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 aa8d0e145d5..0cd18932d10 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,3 +1,3 @@ -!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("mocks/module",["common/angularMocks","common/mocks/module"],function(e){"use strict";return angular.module("leave-absences.mocks",["common.mocks"])}),define("mocks/data/absence-type-data",["common/lodash"],function(e){var t={is_error:0,version:3,count:3,values:[{id:"1",title:"Holiday / Vacation",weight:"1",color:"#151D2C",is_default:"1",is_reserved:"1",allow_request_cancelation:"3",allow_overuse:"0",must_take_public_holiday_as_leave:"1",default_entitlement:"20",add_public_holiday_to_entitlement:"1",is_active:"1",allow_accruals_request:"0",allow_accrue_in_the_past:"0",allow_carry_forward:"1",max_number_of_days_to_carry_forward:"5",carry_forward_expiration_duration:"12",carry_forward_expiration_unit:"2"},{id:"2",title:"TOIL",weight:"2",color:"#056780",is_default:"0",is_reserved:"1",allow_request_cancelation:"3",allow_overuse:"0",must_take_public_holiday_as_leave:"0",default_entitlement:"0",add_public_holiday_to_entitlement:"0",is_active:"1",allow_accruals_request:"1",max_leave_accrual:"5",allow_accrue_in_the_past:"0",accrual_expiration_duration:"3",accrual_expiration_unit:"2",allow_carry_forward:"0"},{id:"3",title:"Sick",weight:"3",color:"#B32E2E",is_default:"0",is_reserved:"1",allow_request_cancelation:"1",allow_overuse:"1",must_take_public_holiday_as_leave:"0",default_entitlement:"0",add_public_holiday_to_entitlement:"0",is_active:"1",allow_accruals_request:"0",allow_accrue_in_the_past:"0",allow_carry_forward:"0"},{id:"4",title:"Weekend",weight:"4",color:"#B32E2E",is_default:"0",is_reserved:"1",allow_request_cancelation:"1",allow_overuse:"1",must_take_public_holiday_as_leave:"0",default_entitlement:"0",add_public_holiday_to_entitlement:"0",is_active:"1",allow_accruals_request:"0",allow_accrue_in_the_past:"0",allow_carry_forward:"0"},{id:"5",title:"Custom",weight:"5",color:"null",is_default:"0",is_reserved:"0",allow_request_cancelation:"3",must_take_public_holiday_as_leave:"0",default_entitlement:"10",add_public_holiday_to_entitlement:"0",is_active:"0",allow_accruals_request:"0",allow_carry_forward:"0",is_sick:"0"}]},n={values:{expiry_date:"2016-07-08"}};return{all:function(){return t},getRandomAbsenceType:function(n){return e.sample(t.values)[n]},getAllAbsenceTypesByKey:function(e){return t.values.map(function(t){return t[e]})},getAllAbsenceTypesTitles:function(){return this.getAllAbsenceTypesByKey("title")},getAllAbsenceTypesIds:function(){return this.getAllAbsenceTypesByKey("id")},calculateToilExpiryDate:function(){return n},getDisabledAbsenceTypes:function(){return t.values.filter(function(e){return"0"===e.is_active})},findByKeyValue:function(n,a){return e.find(t.values,function(e){return e[n]===a})}}}),define("mocks/data/leave-balance-report.data",["common/mocks/data/contact.data","mocks/data/absence-type-data"],function(e,t){function n(){return e.all.values.map(function(e){return{id:e.id,contact_id:e.contact_id,contact_display_name:e.display_name,absence_types:t.all().values.map(function(e){return{id:e.id,entitlement:4,used:3,balance:1,requested:1}})}})}var a=n();return{all:function(){return{is_error:0,version:123,count:a.length,values:a}}}}),define("mocks/apis/leave-balance-report-api-mock",["mocks/module","mocks/data/leave-balance-report.data"],function(e,t){"use strict";e.factory("LeaveBalanceReportAPIMock",["$q",function(e){return{getAll:function(n,a,s){var o=t.all().values;return e.resolve({list:o,total:o.length,allIds:o.map(function(e){return e.id}).join(",")})}}}])}),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","mocks/apis/leave-balance-report-api-mock"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings","leave-absences.mocks"])}),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,s){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaults(t||{},{is_active:!0})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(o).format(s.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",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/absence-type-api","leave-absences/shared/instances/absence-type.instance"],function(e){"use strict";e.factory("AbsenceType",["$log","Model","AbsenceTypeAPI","AbsenceTypeInstance",function(e,t,n,a){return e.debug("AbsenceType"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return a.init(e,!0)})})},calculateToilExpiryDate:function(e,t,a){return n.calculateToilExpiryDate(e,t,a)},canExpire:function(e){return n.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})}})}])}),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,s,o,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:s,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,s,o){return t.debug("WorkPatternAPI.getCalendar",n,a,s,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:s}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,s){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),s).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,s,o,i){function r(t,n){return l().then(function(a){var s=this.days[c(t).valueOf()];return!!s&&e.find(a,function(e){return e.name===n}).value===s.type}.bind(this))}function c(e){return t(e,o.serverDateFormat).clone()}function l(){return u=u||i.valuesOf("hrleaveandabsences_work_day_type")}var u;return s.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,s){return t.debug("Calendar"),n.extend({get:function(n,o,i,r){return t.debug("Calendar.get"),a.getCalendar(n,o,i,r).then(function(t){var a=t.values.map(function(e){return s.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 s(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(s),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})}})}])}),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/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance",function(t,n,a,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 s.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 s.init(e,!0)})})}})}])}),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,s,o,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,s,o,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,s,o){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:s?{IN:s}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(t){e.debug("LeaveRequestAPI.calculateBalanceChange",t);var n=a.defer();return!t||t.contact_id&&t.from_date&&t.from_date_type||n.reject("contact_id, from_date and from_date_type in params are mandatory"),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){n.resolve(e.values)}),n.promise},create:function(t){e.debug("LeaveRequestAPI.create",t);var n=a.defer();return t&&(t.to_date&&!t.to_date_type?n.reject("to_date_type is mandatory"):t.contact_id&&t.from_date&&t.from_date_type&&t.status_id||n.reject("contact_id, from_date, status_id and from_date_type params are mandatory")),this.sendPOST("LeaveRequest","create",t).then(function(e){n.resolve(e.values[0])}),n.promise},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","get",{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 s=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?s.reject(t(e.values).map().flatten().value()):s.resolve(e.values)}),s.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","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI",function(t,n,a,s,o,i){function r(e){return u(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 c(e){return u(e).then(function(e){return this.status_id===e.value}.bind(this))}function l(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function u(e){return a.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return t.find(function(t){return t.name===e})})}function d(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),t.all(n)}return o.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},cancel:function(){return r.call(this,s.statusNames.cancelled)},approve:function(){return r.call(this,s.statusNames.approved)},reject:function(){return r.call(this,s.statusNames.rejected)},sendBack:function(){return r.call(this,s.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return t.all([d.call(this),l.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([d.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){return t.comment_id?void(t.toBeDeleted=!0):void(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)},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return c.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return c.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return c.call(this,s.statusNames.cancelled)},isRejected:function(){return c.call(this,s.statusNames.rejected)},isSentBack:function(){return c.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):n(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)):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,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,s,o,i){return n.all(this.processFilters(e),t,s,o,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,s){return n.balanceChangeByAbsenceType(e,t,a,s)},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange"),n.calculateBalanceChange(t)},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(e,t,n,a){return e.debug("WorkPattern"),t.extend({assignWorkPattern:function(e,t,a,s,o,i){return n.assignWorkPattern(e,t,a,s,o,i)},default:function(){return n.get({default:!0}).then(function(e){return a.init(e[0],!0)})},unassignWorkPattern:function(e){return n.unassignWorkPattern(e)},workPatternsOf:function(e,t,s){return n.workPatternsOf(e,t,s).then(function(e){return e.map(function(e){return a.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular"],function(e){return e.module("leave-absences.components",[])}),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"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all().then(function(e){o.lookupContacts=e.list}).then(a)}}}function a(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:o.filters.userSettings.department?o.filters.userSettings.department.value:null,level_type:o.filters.userSettings.level_type?o.filters.userSettings.level_type.value:null,location:o.filters.userSettings.location?o.filters.userSettings.location.value:null,region:o.filters.userSettings.region?o.filters.userSettings.region.value:null,id:{IN:o.filters.userSettings.contact?[o.filters.userSettings.contact.id]:o.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarAdminController");var o;return{init:function(e){return o=e,o.showContactName=!0,o.showFilters=!0,n()}}}n.controller("LeaveCalendarAdminController",["$log","Contact",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(s)}}}function s(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){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,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 s(a,s,o,i,r,c,l,u,d,m,f,h,p){function v(){for(var e=[],t=n(B.selectedPeriod.start_date).clone().startOf("month"),a=n(B.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(k(t)),t.add(1,"month");B.months=e}function b(){i.$new().$watch(function(){return B.selectedMonths},function(t,n){null===n||e.equals(t,n)||O()})}function g(e){$("injected").then(function(){O(e)}).then(function(){B.loading.calendar=!1}),R().then(function(){B.injectMonths=!0})}function _(){L=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(B)}function y(e){return e.current?"Current Period ("+e.title+")":e.title}function q(){return l.all().then(function(e){B.absencePeriods=t.sortBy(e,"start_date"),B.selectedPeriod=t.find(B.absencePeriods,function(e){return!!e.current})}).then(v).then(S)}function P(){return u.all({is_active:!0})}function A(){return f.valuesOf(["hrleaveandabsences_leave_request_status","hrleaveandabsences_leave_request_day_type"])}function D(){return L.loadContacts().then(function(e){B.contacts=e})}function C(){return f.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){B.filters.optionValues.regions=e.hrjc_region,B.filters.optionValues.locations=e.hrjc_location,B.filters.optionValues.levelTypes=e.hrjc_level_type,B.filters.optionValues.departments=e.hrjc_department})}function T(){return m.all()}function w(){return s.all([P(),T(),A()]).then(function(e){B.supportData.absenceTypes=e[0],B.supportData.publicHolidays=e[1],B.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,B.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type})}function R(){var e=s.resolve();return B.injectMonths&&(e=$("destroyed"),B.injectMonths=!1),e}function k(e){return{index:e.month(),year:e.year(),name:e.format("MMM")}}function I(e){e=t.includes(["contacts","period"],e)?e:"period",s.resolve().then(function(){B.loading.calendar=!0}).then("period"===e?v:t.noop).then("contacts"===e?D:t.noop).then(function(){g("contacts"===e)})}function O(e){var n=B.selectedMonths.length?B.months.filter(function(e){return t.includes(B.selectedMonths,e.index)}):B.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){B.selectedMonths=[n().month()]}function M(){return B.roleOverride?s.resolve().then(function(){x=B.roleOverride}):s.all([p(c.permissions.admin.administer),p(c.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function $(e){return s(function(n){var a=0,s=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===B.months.length&&(s(),n())})})}o.debug("Component: leave-calendar");var L,x,B=this;B.absencePeriods=[],B.contacts=[],B.injectMonths=!1,B.months=[],B.selectedMonths=null,B.selectedPeriod=null,B.showContactName=!1,B.showFilters=!1,B.supportData={},B.loading={calendar:!0,page:!0},B.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!1,department:null,level_type:null,location:null,region:null}},B.labelPeriod=y,B.refresh=I,function(){M().then(b).then(_).then(function(){return s.all([D(),q(),w()])}).then(function(){return B.showFilters?C():t.noop}).then(function(){g()}).then(function(){B.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","$timeout","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","PublicHoliday","OptionGroup","Calendar","checkPermissions",s]})}),define("leave-absences/shared/components/leave-calendar-day.component",["leave-absences/shared/modules/components"],function(e){function t(e,t){"use strict";function n(e,n,a,s,o){e.stopPropagation(),t.openModal(n,a,s,o)}e.debug("Component: leave-calendar-day");var a=this;a.openLeavePopup=n}e.component("leaveCalendarDay",{bindings:{contactData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:t}),t.$inject=["$log","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.collapsed=!1,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"],function(e,t,n){function a(n,a,s,o,i,r){function c(e,t){v([t]),$(t)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:u(e)}}function u(n){var a=t(),s=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:s.format("YYYY-MM-DD"),name:s.format("ddd"),index:s.format("D"),current:a.isSame(s,"day"),enabled:s.isSameOrAfter(F.period.start_date)&&s.isSameOrBefore(F.period.end_date),contactsData:{}};return s.add(1,"day"),e})}function d(e){return B[e]}function m(){return F.showOnlyWithLeaveRequests?F.contacts.filter(function(t){return e.includes(Object.keys(E),t.id)}):F.contacts}function f(e){return t(e,r.serverDateFormat)}function h(e,t){w(t),$(t)}function p(){F.supportData.dayTypes=e.indexBy(F.supportData.dayTypes,"name"),F.supportData.leaveRequestStatuses=e.indexBy(F.supportData.leaveRequestStatuses,"value"),F.supportData.publicHolidays=e.transform(F.supportData.publicHolidays,function(e,t){e[f(t.date).valueOf()]=t},{})}function v(e){var t=a.defer();return e.forEach(function(e){var t=q(e);E[e.contact_id]=E[e.contact_id]||{},t.forEach(function(t){E[e.contact_id][t.date]=e})}),t.resolve(),t.promise}function b(){x.push(s.$on("LeaveCalendar::showMonths",O)),x.push(s.$on("LeaveRequest::new",c)),x.push(s.$on("LeaveRequest::edit",M)),x.push(s.$on("LeaveRequest::updatedByManager",M)),x.push(s.$on("LeaveRequest::deleted",h))}function g(e,n,a){var s=F.supportData.dayTypes[e];return t(a).isSame(n.from_date)?s.value===n.from_date_type:t(a).isSame(n.to_date)?s.value===n.to_date_type:void 0}function _(e){var t=F.supportData.leaveRequestStatuses[e.status_id];return t.name===r.statusNames.awaitingApproval}function y(e){return!!F.supportData.publicHolidays[f(e).valueOf()]}function q(n){for(var a=[],s=t(n.from_date).clone(),o=t(n.to_date);s.isSameOrBefore(o);)a.push(e.find(F.month.days,function(e){return e.date===s.format("YYYY-MM-DD")})),s.add(1,"day");return a}function P(t){return e.find(E[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(F.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function D(){return F.month.loading=!0,a.all([T(),C()]).then(function(){ -return I()}).then(function(){L=!0}).then(function(){F.month.loading=!1})}function C(){return i.all({from_date:{from:F.month.days[0].date},to_date:{to:F.month.days[F.month.days.length-1].date},status_id:{IN:[A(r.statusNames.approved),A(r.statusNames.adminApproved),A(r.statusNames.awaitingApproval)]},contact_id:{IN:F.contacts.map(function(e){return e.id})}},null,null,null,!1).then(function(e){return v(e.list)})}function T(){var t=F.month.days[0].date,n=F.month.days[F.month.days.length-1].date;return o.get(F.contacts.map(function(e){return e.id}),t,n).then(function(t){B=e.indexBy(t,"contact_id")})}function w(t){E[t.contact_id]=e.omit(E[t.contact_id],function(e){return e.id===t.id})}function R(){s.$emit("LeaveCalendar::monthDestroyed"),x.map(function(e){e()})}function k(t,n,s){var o,i;return t.contactsData[n]=t.contactsData[n]||{},i=d(n),o=s===!0?a.resolve():a.all([i.isWeekend(f(t.date)),i.isNonWorkingDay(f(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:y(t.date)})}),o.then(function(){return E[n]?E[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?S(a):null,isAccruedTOIL:a?a.balance_change>0:null,isRequested:a?_(a):null,isAM:a?g("half_day_am",a,t.date):null,isPM:a?g("half_day_pm",a,t.date):null})})}function I(){return a.all(F.month.days.map(function(e){return a.all(F.contacts.map(function(t){return k(e,t.id)}))}))}function O(t,n,a){var s=!!e.find(n,function(e){return e.index===F.month.index});s?(F.currentPage=0,F.visible=!0,(a||!L)&&D()):F.visible=!1}function S(t){var n=e.find(F.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 M(e,t){var n=P(t);h(null,n),c(null,t)}function $(e){return a.all(q(e).map(function(t){return k(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var L=!1,x=[],B={},E={},F=this;F.currentPage=0,F.pageSize=20,F.visible=!1,F.showContactName=!!F.showContactName,F.showOnlyWithLeaveRequests=!!F.showOnlyWithLeaveRequests,F.$onDestroy=R,F.contactsList=m,function(){var e=t().month(F.month.index).year(F.month.year);p(),b(),F.month=l(e),s.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",month:"<",period:"<",showContactName:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","shared-settings",a]})}),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"],function(e,t,n){function a(n,a,s,o,i,r,c){function l(e){var t=_[e].dialog;v=b.leaveRequest.status_id,s.open({title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return b.leaveRequest[e]().then(function(){f(e)}).catch(function(e){c.error("Error:",e)})}})}function u(){var e=b.absenceTypes[b.leaveRequest.type_id].allow_request_cancelation;return"admin"===b.role||"manager"===b.role||("3"===e?t().isBefore(b.leaveRequest.from_date):"2"===e)}function d(){Array.isArray(b.leaveRequestStatuses)&&(b.leaveRequestStatuses=e.indexBy(b.leaveRequestStatuses,"value")),Array.isArray(b.absenceTypes)&&(b.absenceTypes=e.indexBy(b.absenceTypes,"id"))}function m(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function f(t){var n=e.find(b.leaveRequestStatuses,function(e){return e.name===r.statusNames.awaitingApproval}).value;v===n&&i.publish("ManagerBadge:: Update Count"),a.$emit("LeaveRequest::"+("delete"===t?"deleted":"edit"),b.leaveRequest)}function h(){var t=b.leaveRequestStatuses[b.leaveRequest.status_id].name,n=e.compact(e.map(_,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!u()&&e.pull(n,"cancel"),"admin"!==b.role&&e.pull(n,"delete"),"staff"===b.role&&e.pull(n,"approve","reject"),"staff"!==b.role&&p(n),b.allowedActions=e.map(n,function(e){return{key:e,label:_[e].label,isDirectAction:_[e].isDirectAction}})}function p(t){e.each(t,function(e,n){"edit"===e&&(t[n]="respond"),"respond"===e&&(t[n]="edit")})}n.debug("Component: leave-request-action-dropdown");var v,b=this,g=r.statusNames,_={edit:{label:"Edit",allowedStatuses:[g.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[g.moreInformationRequired]},view:{label:"View",allowedStatuses:[g.approved,g.rejected,g.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired,g.approved,g.rejected,g.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};b.allowedActions=[],b.action=l,b.openLeavePopup=m,function(){d(),h()}()}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","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,s,o,i,r){function c(){var t=e.indexBy(m.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){m.comment.contacts=e.indexBy(t.list,"contact_id")})}function l(){return m.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),m.request.comments.length&&c()})}function u(){return m.loading.component=!0,r.get().then(function(e){d=e.contactId}).then(function(){m.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var d=null,m=this;m.loading={component:!0},m.comment={text:"",contacts:{}},function(){l(),u()}(),m.addComment=function(){m.request.comments.push({contact_id:d,leave_request_id:m.request.id,text:m.comment.text}),m.comment.text=""},m.formatDateTime=function(e){return t.utc(e,o.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")},m.getActiveComments=function(){return m.request.comments.filter(function(e){return!e.toBeDeleted})},m.getCommentorName=function(e){return e===d?"Me":m.comment.contacts[e]?m.comment.contacts[e].display_name:void 0},m.isMode=function(e){return m.mode===e},m.orderComment=function(e){return t(e.created_at,o.serverDateTimeFormat)},m.removeCommentVisibility=function(e){return!e.comment_id||m.canManage}}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"directives/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","HR_settings","shared-settings","Contact","Session",a]})}),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,s,o,i,r,c,l){function u(){return e.filter(A.request.files,function(e){return e.toBeDeleted})}function d(){return A.fileUploader&&A.fileUploader.queue?A.fileUploader.queue:[]}function m(){q.push(a.$on("LeaveRequestPopup::submit",_))}function f(){v().then(function(){A.fileUploader=c.uploader({entityTable:"civicrm_hrleaveandabsences_leave_request",crmAttachmentToken:i.attachmentToken,queueLimit:i.fileUploader.queueLimit,allowedMimeTypes:P})})}function h(){return y.length>0?y.map(function(e){return e.label}).join(", "):""}function p(){return A.request.loadAttachments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function v(){return s.all(y.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){P[e.label]=t})})).catch(function(){P=null})}function b(){return r.valuesOf("safe_file_extension").then(function(e){y=e})}function g(){e.forEach(q,function(e){e()})}function _(e,t){A.fileUploader.queue&&A.fileUploader.queue.length>0?A.fileUploader.uploadAll({entityID:A.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var y=[],q=[],P={},A=Object.create(this);return A.filesLoaded=!1,A.today=Date.now(),A.userDateFormatWithTime=o.DATE_FORMAT+" HH:mm",A.userDateFormat=o.DATE_FORMAT,A.listFileTypes=h,A.$onDestroy=g,A.canUploadMore=function(){return A.getFilesCount()=":e}};return a.all(n).then(function(e){return e&&e.length?s.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,s,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 s.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var s=e(n).format(o.serverDateFormat),i={date:s};return a.all(i).then(function(e){return!!e.length})}})}])}),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/calendar-model","leave-absences/shared/models/entitlement-model","leave-absences/shared/models/leave-request-model","leave-absences/shared/models/public-holiday-model"],function(e,t,n,a){"use strict";function s(t,s,o,i,r,c,l,u,d,m,f,h,p,v,b,g,_){function y(){var e=this.requestStatuses[_.statusNames.awaitingApproval].value;Ee.status_id===e&&e!==this.request.status_id&&m.publish("ManagerBadge:: Update Count")}function q(){var e=this;return e._setDateAndTypes(),P.call(e)?(e.loading.showBalanceChange=!0,b.calculateBalanceChange(L.call(e)).then(function(t){t&&(e.balance.change=t,e._calculateOpeningAndClosingBalance(),ue.call(e)),e.loading.showBalanceChange=!1}).catch(F.bind(e))):s.resolve()}function P(){return!!(this.request.from_date&&this.request.to_date&&this.request.from_date_type&&this.request.to_date_type)}function A(){var e=P.call(this);return this.isMode("edit")&&(e=e&&j.call(this)),this.canManage&&this.requestStatuses&&(e=e&&!!this.getStatusFromValue(this.newStatusOnSave)),e=e&&!!this.period.id,e&&!this.isMode("view")}function D(){this._reset(),this._calculateOpeningAndClosingBalance()}function C(){this.isSelfRecord?this.request.status_id=this.requestStatuses[_.statusNames.awaitingApproval].value:this.canManage&&(this.request.status_id=this.newStatusOnSave||this.request.status_id)}function T(){this.errors=[]}function w(){return this.request.create().then(be).then(function(){le.call(this,"LeaveRequest::new")}.bind(this))}function R(){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return this.directiveOptions.leaveRequest.delete().then(function(){this.dismissModal(),o.$emit("LeaveRequest::deleted",this.directiveOptions.leaveRequest)}.bind(this))}.bind(this)})}function k(){this.$modalInstance.dismiss({$value:"cancel"})}function I(e,t){var a;return e?(a=this.requestDayTypes.slice(0),e=this._convertDateToServerFormat(e),g.isPublicHoliday(e).then(function(t){return t?a.filter(function(e){return"public_holiday"===e.name}):$.call(this,e,a).then(function(e){return e.length?e:a.filter(function(e){return n.includes(["all_day","half_day_am","half_day_pm"],e.name)})})}.bind(this)).then(function(e){return fe.call(this,t,e),e}.bind(this))):s.reject([])}function O(e){return a(e,_.serverDateTimeFormat).format(this.uiOptions.userDateFormat.toUpperCase()+" HH:mm")}function S(){var e=this.getStatusFromValue(this.request.status_id);return M.call(this,e.name)}function M(e){return n.map(xe[e],function(e){return this.requestStatuses[e]}.bind(this))}function $(e,t){return e=a(e),s.all([this.calendar.isNonWorkingDay(e),this.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(t){return t.name===e}):[]})}function L(){return n.pick(this.request,["contact_id","from_date","from_date_type","to_date","to_date_type"])}function x(){return n.find(this.absenceTypes,function(e){return e.id===this.request.type_id}.bind(this))}function B(){return!this.request||e.equals({},this.requestStatuses)?[]:this.request.status_id?S.call(this):M.call(this,"none")}function E(e){return n.find(this.requestStatuses,function(t){return t.value===e})}function F(e){this.errors=n.isArray(e)?e:[e],this.loading.showBalanceChange=!1,this.loading.absenceTypes=!1,this.loading.fromDayTypes=!1,this.loading.toDayTypes=!1,this.submitting=!1}function j(){return!e.equals(Ee,this.request.attributes())||this.fileUploader&&0!==this.fileUploader.queue.length||this.canManage&&this.newStatusOnSave}function N(){this.period=n.find(this.absencePeriods,function(e){return e.current})}function W(){var e=this;return e.postContactSelection=!0,e.request.contact_id?s.all([e._loadAbsenceTypes(),e._loadCalendar()]).then(function(){return ne.call(e)}).then(function(){return G.call(e)}).then(function(){return he.call(e),K.call(e),H.call(e),e.isMode("edit")&&pe.call(e),e.postContactSelection=!1,e.calculateBalanceChange()}).catch(function(e){if(e!==Ue)return s.reject(e)}):s.reject("The contact id was not set")}function U(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];xe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],xe.awaiting_approval=e,xe.more_information_required=e,xe.rejected=e,xe.approved=e,xe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function H(){return this.canManage?i.find(this.request.contact_id).then(function(e){this.contactName=e.display_name}.bind(this)):s.resolve()}function G(){if(this.isMode("create"))return s.resolve();var e=this.request.attributes();return this.uiOptions.fromDate=this._convertDateFormatFromServer(this.request.from_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.fromDate,"from").then(function(){return this.request.to_date=e.to_date,this.request.to_date_type=e.to_date_type,this.uiOptions.toDate=this._convertDateFormatFromServer(this.request.to_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.toDate,"to")}.bind(this))}function Y(){Fe.push(o.$on("LeaveRequestPopup::requestObjectUpdated",pe.bind(this)),o.$on("LeaveRequestPopup::childComponent::register",function(){Be++}))}function V(){if(this.request.id){this.mode="edit";var e=[this.requestStatuses[_.statusNames.approved].value,this.requestStatuses[_.statusNames.adminApproved].value,this.requestStatuses[_.statusNames.rejected].value,this.requestStatuses[_.statusNames.cancelled].value];this.isRole("staff")&&e.indexOf(this.request.status_id)>-1&&(this.mode="view")}else this.mode="create"}function z(){return Ne="staff",d(_.permissions.admin.administer).then(function(e){Ne=e?"admin":Ne}).then(function(){return"staff"===Ne&&d(_.permissions.ssp.manage).then(function(e){Ne=e?"manager":Ne})}).finally(function(){this.canManage=this.isRole("manager")||this.isRole("admin"),this.isSelfRecord=this.directiveOptions.isSelfRecord}.bind(this))}function K(){(this.isRole("admin")||this.isMode("create")&&this.isRole("manager"))&&(this.newStatusOnSave=this.requestStatuses[_.statusNames.approved].value)}function X(e){var t=this.getStatusFromValue(this.request.status_id);return!!t&&t.name===e}function J(e){return this.request.request_type===e}function Q(e){return this.mode===e}function Z(e){return Ne===e}function ee(e,t){var n=this.period.id;return t=t||"from",this.loading[t+"DayTypes"]=!0,this._checkAndSetAbsencePeriod(e).then(function(){var e=n===this.period.id;if(!e)return this.uiOptions.multipleDays&&"from"===t&&(this.uiOptions.showBalance=!1,this.uiOptions.toDate=null,this.request.to_date=null,this.request.to_date_type=null),s.all([this._loadAbsenceTypes(),this._loadCalendar()])}.bind(this)).then(function(){return this._setMinMaxDate(),I.call(this,e,t)}.bind(this)).finally(function(){this.loading[t+"DayTypes"]=!1}.bind(this))}function te(){var e=this;return c.all().then(function(t){e.absencePeriods=t})}function ne(){var e=this;return u.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(t){e.requestDayTypes=t})}function ae(){return v.get().then(function(e){je=e.contactId})}function se(){return this.directiveOptions.selectedContactId?i.find(this.directiveOptions.selectedContactId).then(function(e){this.managedContacts=[e]}.bind(this)):this.isRole("admin")?i.all().then(function(e){this.managedContacts=n.remove(e.list,function(e){return e.id!==je})}.bind(this)):i.find(je).then(function(e){return e.leaveManagees()}).then(function(e){this.managedContacts=e}.bind(this))}function oe(){var e=this;return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){e.requestStatuses=n.indexBy(t,"name")})}function ie(e,t){return t.map(function(t){var a=n.find(e,function(e){return e.id===t.type_id});return{id:t.type_id,title:a.title+" ( "+t.remainder.current+" ) ",remainder:t.remainder.current,allow_overuse:a.allow_overuse}})}function re(){this.$modalInstance.close({$value:this.request})}function ce(){var e=(this.currentPage-1)*this.numPerPage,t=e+this.numPerPage;this.filteredbreakdown=We.balance.change.breakdown.slice(e,t)}function le(e){y.call(this),o.$emit(e,this.request),this.errors=[],this.ok()}function ue(){this.pagination.totalItems=this.balance.change.breakdown.length,this.pagination.filteredbreakdown=this.balance.change.breakdown,this.pagination.pageChanged()}function de(e){var t=this;return h.all({contact_id:t.request.contact_id,period_id:t.period.id,type_id:{IN:e.ids}},!0).then(function(n){if(t.absenceTypes=ie(e.types,n),!t.absenceTypes.length)return s.reject(Ue)})}function me(){(this.isMode("edit")&&this.request.from_date===this.request.to_date||this.isMode("create")&&this.isLeaveType("sickness"))&&(this.uiOptions.multipleDays=!1)}function fe(e,t){var a="request"+n.startCase(e)+"DayTypes";this[a]=t,this.isMode("create")&&(this.request[e+"_date_type"]=this[a][0].value)}function he(){this.isMode("create")?(this.selectedAbsenceType=this.absenceTypes[0],this.request.type_id=this.selectedAbsenceType.id):this.selectedAbsenceType=x.call(this)}function pe(){Ee=e.copy(this.request.attributes())}function ve(){var e=this.request.status_id;if(!this.isMode("view")&&!this.submitting)return this.submitting=!0,C.call(this),Pe.call(this).then(function(){return this.isMode("edit")?qe.call(this):w.call(this)}.bind(this)).catch(function(t){this.request.status_id=e,t&&F.call(this,t)}.bind(this)).finally(function(){this.submitting=!1}.bind(this))}function be(){function e(e){e&&n.push(e),++a===Be&&(ge(),n.length>0?t.reject(n):t.resolve())}var t=s.defer(),n=[],a=0;return Be>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function ge(){n.forEach(Fe,function(e){e()})}function _e(e,t){return this.loadAbsencePeriodDatesTypes(e,t).then(function(){return this.updateBalance()}.bind(this)).catch(function(e){F.call(this,e),this._setDateAndTypes()}.bind(this))}function ye(){this.selectedAbsenceType=x.call(this),this.balance.opening=this.selectedAbsenceType.remainder,this.calculateBalanceChange()}function qe(){return this.request.update().then(be).then(function(){this.isRole("manager")?le.call(this,"LeaveRequest::updatedByManager"):(this.isRole("staff")||this.isRole("admin"))&&le.call(this,"LeaveRequest::edit")}.bind(this))}function Pe(){return this.balance.closing<0&&"0"===this.selectedAbsenceType.allow_overuse?s.reject(["You cannot make a request for this leave type at this time as this would leave you with a negative balance"]):this.request.isValid()}function Ae(){this.balance.opening=this.selectedAbsenceType.remainder,this.balance.closing=this.balance.opening+this.balance.change.amount}function De(e){var t=a(e).format(this.uiOptions.userDateFormat.toUpperCase());return this.period=n.find(this.absencePeriods,function(e){return e.isInPeriod(t)}),this.period?s.resolve(!0):(this.period={},this.loading.fromDayTypes=!1,s.reject("Please change date as it is not in any absence period"))}function Ce(e){return a(e,_.serverDateFormat).toDate()}function Te(e){return a(e).format(_.serverDateFormat)}function we(){return U.call(this),Y.call(this),ae.call(this).then(z.bind(this)).then(this._initRequest.bind(this)).then(oe.bind(this)).then(function(){return V.call(this), -this.canManage&&!this.isMode("edit")&&se.call(this)}.bind(this)).then(te.bind(this)).then(function(){N.call(this),this._setMinMaxDate()}.bind(this)).then(function(){if(this.directiveOptions.selectedContactId&&(this.request.contact_id=this.directiveOptions.selectedContactId),me.call(this),this.request.contact_id)return this.initAfterContactSelection()}.bind(this)).catch(F.bind(this))}function Re(){var e={};return this.directiveOptions.leaveRequest?e=this.directiveOptions.leaveRequest.attributes():this.canManage||(e={contact_id:je}),e}function ke(){var e=this;return l.all(e.initParams.absenceType).then(function(t){var n=t.map(function(e){return e.id});return Le={types:t,ids:n},de.call(e,Le)})}function Ie(){var e=this;return f.get(e.request.contact_id,e.period.start_date,e.period.end_date).then(function(t){e.calendar=t})}function Oe(){this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date_type=this.request.from_date_type,this.request.to_date=this.request.from_date,this.calculateBalanceChange()}function Se(){this._setDates(),this.uiOptions.multipleDays?this.uiOptions.showBalance=!!(this.request.from_date&&this.request.from_date_type&&this.request.to_date&&this.request.to_date_type&&this.period.id):(this.uiOptions.fromDate&&(this.request.to_date_type=this.request.from_date_type),this.uiOptions.showBalance=!!this.request.from_date&&!!this.request.from_date_type&&!!this.period.id)}function Me(){this.request.from_date=this.uiOptions.fromDate?this._convertDateToServerFormat(this.uiOptions.fromDate):null,this.request.to_date=this.uiOptions.toDate?this._convertDateToServerFormat(this.uiOptions.toDate):null,!this.uiOptions.multipleDays&&this.uiOptions.fromDate&&(this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date=this.request.from_date)}function $e(){if(this.uiOptions.fromDate){var e=a(this.uiOptions.fromDate).add(1,"d").toDate();this.uiOptions.date.to.options.minDate=e,this.uiOptions.date.to.options.initDate=e,this.uiOptions.toDate&&a(this.uiOptions.toDate).isBefore(this.uiOptions.fromDate)&&(this.uiOptions.toDate=this.uiOptions.fromDate)}else this.uiOptions.date.to.options.minDate=this._convertDateFormatFromServer(this.period.start_date),this.uiOptions.date.to.options.initDate=this.uiOptions.date.to.options.minDate;this.uiOptions.date.to.options.maxDate=this._convertDateFormatFromServer(this.period.end_date)}t.debug("RequestCtrl");var Le,xe={},Be=0,Ee={},Fe=[],je="",Ne="",We=this,Ue="No entitlement";this.absencePeriods=[],this.absenceTypes=[],this.calendar={},this.canManage=!1,this.contactName=null,this.errors=[],this.fileUploader=null,this.isSelfRecord=!1,this.managedContacts=[],this.mode="",this.newStatusOnSave=null,this.period={},this.postContactSelection=!1,this.requestDayTypes=[],this.requestStatuses={},this.selectedAbsenceType={},this.statusNames=_.statusNames,this.submitting=!1,this.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},this.loading={absenceTypes:!0,showBalanceChange:!1,fromDayTypes:!1,toDayTypes:!1},this.pagination={currentPage:1,filteredbreakdown:this.balance.change.breakdown,numPerPage:7,totalItems:this.balance.change.breakdown.length,pageChanged:ce},this.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:p.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}}}},this.changeInNoOfDays=D,this.calculateBalanceChange=q,this.canSubmit=A,this.closeAlert=T,this.deleteLeaveRequest=R,this.dismissModal=k,this.formatDateTime=O,this.getStatuses=B,this.getStatusFromValue=E,this.initAfterContactSelection=W,this.isLeaveStatus=X,this.isLeaveType=J,this.isMode=Q,this.isRole=Z,this.ok=re,this.submit=ve,this.loadAbsencePeriodDatesTypes=ee,this.updateAbsencePeriodDatesTypes=_e,this.updateBalance=ye,this._calculateOpeningAndClosingBalance=Ae,this._checkAndSetAbsencePeriod=De,this._convertDateToServerFormat=Te,this._convertDateFormatFromServer=Ce,this._init=we,this._initRequestAttributes=Re,this._loadCalendar=Ie,this._loadAbsenceTypes=ke,this._reset=Oe,this._setDates=Me,this._setDateAndTypes=Se,this._setMinMaxDate=$e}t.controller("RequestCtrl",s),s.$inject=["$log","$q","$rootScope","Contact","dialog","AbsencePeriod","AbsenceType","api.optionGroup","checkPermissions","pubSub","Calendar","Entitlement","HR_settings","Session","LeaveRequest","PublicHoliday","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/leave-request.controller",["leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/leave-request.instance"],function(e){function t(e,t,n,a,s){function o(){var e=r._initRequestAttributes();r.request=s.init(e)}t.debug("LeaveRequestCtrl");var i=e("RequestCtrl"),r=Object.create(i);return r.directiveOptions=a,r.$modalInstance=n,r.initParams={absenceType:{is_sick:!1}},r._initRequest=o,function(){r.loading.absenceTypes=!0,r._init().finally(function(){r.loading.absenceTypes=!1})}(),r}e.controller("LeaveRequestCtrl",t),t.$inject=["$controller","$log","$uibModalInstance","directiveOptions","LeaveRequestInstance"]}),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(){var e=this.sickness_required_documents?this.sickness_required_documents.split(","):[];return e},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/controllers/sub-controllers/sick-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/sickness-request.instance"],function(e,t){function n(t,n,a,s,o,i,r){function c(){return h.canSubmit.call(this)&&!!p.request.sickness_reason}function l(t){var n=p.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(p.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){p.sicknessDocumentTypes=e})}function m(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){p.sicknessReasons=e.indexBy(t,"name")})}function f(){var e=p._initRequestAttributes();p.request=r.init(e)}n.debug("SicknessRequestCtrl");var h=t("RequestCtrl"),p=Object.create(h);return p.directiveOptions=i,p.$modalInstance=s,p.initParams={absenceType:{is_sick:!0}},p.canSubmit=c,p.isChecked=l,p.isDocumentInRequest=u,p._initRequest=f,function(){p.loading.absenceTypes=!0,p._init().then(function(){return a.all([d(),m()])}).finally(function(){p.loading.absenceTypes=!1})}(),p}t.controller("SicknessRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","directiveOptions","SicknessRequestInstance"]}),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/sub-controllers/toil-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/toil-request.instance"],function(e,t){function n(t,n,a,s,o,i,r,c){function l(){C.request.toil_to_accrue&&(C.loading.showBalanceChange=!0,C._setDateAndTypes(),C.balance.change.amount=+C.request.toil_to_accrue,C._calculateOpeningAndClosingBalance(),C.uiOptions.showBalance=!0,C.request.to_date_type=C.request.from_date_type="1",C.loading.showBalanceChange=!1)}function u(){return!C.canManage&&C.request.id?a.resolve(C.request.toil_expiry_date):C.requestCanExpire?p().catch(function(e){return e.length&&(C.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(C.request.type_id,e)}).then(function(e){return C.request.toil_expiry_date=e,C.uiOptions.expiryDate=new Date(e),e}):(C.request.toil_expiry_date=!1,a.resolve(!1))}function d(){return C.uiOptions.multipleDays&&C.request.to_date||!C.uiOptions.multipleDays&&C.request.from_date}function m(){return D.canSubmit.call(this)&&!!C.request.toil_duration&&!!C.request.toil_to_accrue&&!!C.request.from_date&&!!C.request.to_date}function f(){D.changeInNoOfDays.call(this),d()&&C.calculateToilExpiryDate()}function h(){C.request.toil_expiry_date=!1,C.uiOptions.expiryDate=null}function p(){return v(C.uiOptions.multipleDays?{hasErrors:!C.request.to_date&&!C.request.from_date,label:"To Date",value:C.request.to_date}:{hasErrors:!C.request.from_date,label:"From Date",value:C.request.from_date})}function v(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(e.value):a.reject([])}function b(){C.canManage&&(C.uiOptions.expiryDate=C._convertDateFormatFromServer(C.request.toil_expiry_date))}function g(){return i.canExpire(C.request.type_id).then(function(e){C.requestCanExpire=e})}function _(e){var t=C.period.id;return C._checkAndSetAbsencePeriod(e).then(function(){var e=t===C.period.id;if(!e)return C.uiOptions.multipleDays&&(C.uiOptions.showBalance=!1,C.uiOptions.toDate=null,C.request.to_date=null),a.all([C._loadAbsenceTypes(),C._loadCalendar()])})}function y(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){C.toilAmounts=e.indexBy(t,"value")})}function q(e){return C.loadAbsencePeriodDatesTypes().then(function(){C._setMinMaxDate(),C._setDates(),C.updateBalance(),C.calculateToilExpiryDate()}).catch(function(e){C.errors=[e]})}function P(){C.uiOptions.expiryDate&&(C.request.toil_expiry_date=C._convertDateToServerFormat(C.uiOptions.expiryDate))}function A(){var e=C._initRequestAttributes();C.request=c.init(e),C.request.to_date_type=C.request.from_date_type="1"}n.debug("ToilRequestCtrl");var D=t("RequestCtrl"),C=Object.create(D);return C.requestCanExpire=!0,C.directiveOptions=r,C.$modalInstance=s,C.initParams={absenceType:{allow_accruals_request:!0}},C.calculateBalanceChange=l,C.calculateToilExpiryDate=u,C.canSubmit=m,C.changeInNoOfDays=f,C.clearExpiryDate=h,C.loadAbsencePeriodDatesTypes=_,C.updateAbsencePeriodDatesTypes=q,C.updateExpiryDate=P,C._initRequest=A,function(){C.loading.absenceTypes=!0,C._init().then(function(){return g()}).then(function(){return b(),y()}).finally(function(){C.loading.absenceTypes=!1})}(),C}t.controller("ToilRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","AbsenceType","directiveOptions","TOILRequestInstance"]}),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-popup.service",["common/lodash","leave-absences/shared/modules/services","common/services/notification.service"],function(e,t){"use strict";function n(t,n,a,s,o,i,r,c,l,u){function d(e){return l.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function m(e,t){return t?t.request_type:e||null}function f(t,a,s,i){var c=e.capitalize(m(a,t))+"RequestCtrl";o.open({appendTo:n.children().eq(0),templateUrl:r.sharedPathTpl+"directives/leave-request-popup/leave-request-popup.html",controller:c,controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveRequest:t,selectedContactId:s,isSelfRecord:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function h(e){return u.find(e).then(function(e){return d(e).then(function(t){t?f(e,e.request_type,e.contact_id,"my-leave"===a.section):i.error("Error","You dont have permission to see this leave request")})}).catch(function(e){i.error("Error",e)})}return t.debug("LeavePopup"),{openModal:f,openModalByID:h}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$q","$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){t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:["$log","$rootScope",function(t,n){t.debug("Component: absence-tab-container"),n.section="absence-tab";var a=this;a.contactId=e.adminId}]})})}(CRM),define("leave-absences/absence-tab/components/absence-tab-report.component",["leave-absences/absence-tab/modules/components"],function(e){function t(e){e.debug("Component: absence-tab-report")}e.component("absenceTabReport",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-report.html"}],controllerAs:"report",controller:["$log",t]})}),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["leave-absences/absence-tab/modules/components"],function(e){function t(e){e.debug("Component: absence-tab-entitlements");var t={};return t.contactId=this.contactId,t}e.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:["$log",t]})}),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,s,o,i){function r(e){u.errorMessage=e}function c(){return i.get().then(function(e){u.workPatterns=e})}function l(){return s.valuesOf("hrjc_revision_change_reason").then(function(e){u.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var u=Object.create(this);return u.changeReasons=[],u.errorMessage="",u.saveInProgress=!1,u.workPatterns=[],u.loading={content:!0},u.selected={workPattern:null,effectiveDate:null,changeReason:null},u.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){return n.all([c(),l()]).finally(function(){u.loading.content=!1})}(),u.closeModal=function(){u.dismiss({$value:"cancel"})},u.closeAlert=function(){u.errorMessage=""},u.save=function(){var t=e(u.selected.effectiveDate).format(o.serverDateFormat);return u.saveInProgress=!0,i.assignWorkPattern(u.contactId,u.selected.workPattern.id,t,null,u.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),u.closeModal()}).catch(r).finally(function(){u.saveInProgress=!1})},u}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,s,o,i,r,c,l,u,d){function m(){return d.workPatternsOf(_.contactId,{},!1).then(function(e){_.customWorkPatterns=e})}function f(){return d.default().then(function(e){_.defaultWorkPattern=e})}function h(){return u.valuesOf("hrjc_revision_change_reason").then(function(t){g=e.indexBy(t,"value")})}function p(e){var t=[m()];return e&&(t=t.concat(e)),_.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){_.loading.workPattern=!1})}function v(){var n,a=l.DATE_FORMAT.toUpperCase();_.customWorkPatterns=e(_.customWorkPatterns).map(function(e){return n=g[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()}function b(){var e="civicrm/admin/leaveandabsences/work_patterns",t="civicrm/contact/view",n=CRM.url(t,{cid:_.contactId,selectedChild:"absence"});return CRM.url(e,{cid:_.contactId,returnUrl:n})}n.debug("Component: absence-tab-work-patterns");var g=[],_=Object.create(this);return _.customWorkPatterns=[],_.defaultWorkPattern=null,_.linkToWorkPatternListingPage=b(),_.loading={workPattern:!0},function(){p([h(),f(),c.getDateFormat()]),o.$on("CustomWorkPattern::Added",function(){p()})}(),_.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(){p()})}})},_.openModal=function(){i.open({appendTo:s.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},_}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]})}),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 s(a,s,o,i,r,c,l){function u(){return i.all().then(h)}function d(){return o.all().then(function(e){v.absenceTypes=e})}function m(){var e=t.uniq(t.map(g,function(e){return e.comment_author_id}));return c.all({id:{IN:e}}).then(function(e){b=t.indexBy(e.list,"contact_id")})}function f(){return r.all({contact_id:v.contactId}).then(function(e){g=e})}function h(e){var a=t.uniq(t.map(g,function(e){return e.period_id}));e=t.filter(e,function(e){return a.indexOf(e.id)!==-1}),e=t.sortBy(e,function(e){return-n(e.start_date).valueOf()}),v.absencePeriods=t.map(e,function(e){var n=t.map(v.absenceTypes,function(n){var a=t.filter(g,function(t){return t.type_id===n.id&&t.period_id===e.id})[0];return a?{amount:a.value,comment:a.comment?{message:a.comment,author_name:b[a.comment_author_id].display_name,date:a.comment_date}:null}:null});return{period:e.title,entitlements:n}})}function p(t){var n="civicrm/admin/leaveandabsences/periods/manage_entitlements",a="civicrm/contact/view",s=e.url(a,{cid:t,selectedChild:"absence"});return e.url(n,{cid:t,returnUrl:s})}a.debug("Component: annual-entitlements");var v=this,b=[],g=[];return v.absencePeriods=[],v.absenceTypes=[],v.loading={absencePeriods:!0},v.editEntitlementsPageUrl=p(v.contactId),function(){return s.all([d(),f()]).then(function(){return m()}).then(function(){return u()}).finally(function(){v.loading.absencePeriods=!1})}(),v.showComment=function(e){var t=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";l.info("Calculation comment:",t)},v}a.component("annualEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:["$log","$q","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService",s]})})}(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,s,o,i,r){function c(e){var n=s.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return o.all().then(function(e){m.absenceTypes=e})}function u(){return i.all({contact_id:m.contactId}).then(function(e){d(e)})}function d(n){m.contracts=e.sortBy(n,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,s=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:""}});return{position:a.position,start_date:c(a.period_start_date),end_date:c(a.period_end_date),absences:s}})}n.debug("Component: contract-entitlements");var m=this;return m.absenceTypes=[],m.contracts=[],m.loading={contracts:!0},function(){return a.all([l(),r.getDateFormat()]).then(function(){return u()}).finally(function(){m.loading.contracts=!1})}(),m}n.component("contractEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:["$log","$q","HR_settings","AbsenceType","Contract","DateFormat",a]})}),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),function(e){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"}])})}(CRM),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","common/modules/directives","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-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/leave-request.controller","leave-absences/shared/controllers/sub-controllers/sick-request.controller","leave-absences/shared/controllers/sub-controllers/toil-request.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-report.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-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.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(){}); \ No newline at end of file +!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("mocks/module",["common/angularMocks","common/mocks/module"],function(e){"use strict";return angular.module("leave-absences.mocks",["common.mocks"])}),define("mocks/data/absence-type-data",["common/lodash"],function(e){var t={is_error:0,version:3,count:3,values:[{id:"1",title:"Holiday / Vacation",weight:"1",color:"#151D2C",is_default:"1",is_reserved:"1",allow_request_cancelation:"3",allow_overuse:"0",must_take_public_holiday_as_leave:"1",default_entitlement:"20",add_public_holiday_to_entitlement:"1",is_active:"1",allow_accruals_request:"0",allow_accrue_in_the_past:"0",allow_carry_forward:"1",max_number_of_days_to_carry_forward:"5",carry_forward_expiration_duration:"12",carry_forward_expiration_unit:"2"},{id:"2",title:"TOIL",weight:"2",color:"#056780",is_default:"0",is_reserved:"1",allow_request_cancelation:"3",allow_overuse:"0",must_take_public_holiday_as_leave:"0",default_entitlement:"0",add_public_holiday_to_entitlement:"0",is_active:"1",allow_accruals_request:"1",max_leave_accrual:"5",allow_accrue_in_the_past:"0",accrual_expiration_duration:"3",accrual_expiration_unit:"2",allow_carry_forward:"0"},{id:"3",title:"Sick",weight:"3",color:"#B32E2E",is_default:"0",is_reserved:"1",allow_request_cancelation:"1",allow_overuse:"1",must_take_public_holiday_as_leave:"0",default_entitlement:"0",add_public_holiday_to_entitlement:"0",is_active:"1",allow_accruals_request:"0",allow_accrue_in_the_past:"0",allow_carry_forward:"0"},{id:"4",title:"Weekend",weight:"4",color:"#B32E2E",is_default:"0",is_reserved:"1",allow_request_cancelation:"1",allow_overuse:"1",must_take_public_holiday_as_leave:"0",default_entitlement:"0",add_public_holiday_to_entitlement:"0",is_active:"1",allow_accruals_request:"0",allow_accrue_in_the_past:"0",allow_carry_forward:"0"},{id:"5",title:"Custom",weight:"5",color:"null",is_default:"0",is_reserved:"0",allow_request_cancelation:"3",must_take_public_holiday_as_leave:"0",default_entitlement:"10",add_public_holiday_to_entitlement:"0",is_active:"0",allow_accruals_request:"0",allow_carry_forward:"0",is_sick:"0"}]},n={values:{expiry_date:"2016-07-08"}};return{all:function(){return t},getRandomAbsenceType:function(n){return e.sample(t.values)[n]},getAllAbsenceTypesByKey:function(e){return t.values.map(function(t){return t[e]})},getAllAbsenceTypesTitles:function(){return this.getAllAbsenceTypesByKey("title")},getAllAbsenceTypesIds:function(){return this.getAllAbsenceTypesByKey("id")},calculateToilExpiryDate:function(){return n},getDisabledAbsenceTypes:function(){return t.values.filter(function(e){return"0"===e.is_active})},findByKeyValue:function(n,a){return e.find(t.values,function(e){return e[n]===a})}}}),define("mocks/data/leave-balance-report.data",["common/mocks/data/contact.data","mocks/data/absence-type-data"],function(e,t){function n(){return e.all.values.map(function(e){return{id:e.id,contact_id:e.contact_id,contact_display_name:e.display_name,absence_types:t.all().values.map(function(e){return{id:e.id,entitlement:4,used:3,balance:1,requested:1}})}})}var a=n();return{all:function(){return{is_error:0,version:123,count:a.length,values:a}}}}),define("mocks/apis/leave-balance-report-api-mock",["mocks/module","mocks/data/leave-balance-report.data"],function(e,t){"use strict";e.factory("LeaveBalanceReportAPIMock",["$q",function(e){return{getAll:function(n,a,s){var o=t.all().values;return e.resolve({list:o,total:o.length,allIds:o.map(function(e){return e.id}).join(",")})}}}])}),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","mocks/apis/leave-balance-report-api-mock"],function(e){"use strict";return e.module("leave-absences.models",["common.models","common.services","leave-absences.apis","leave-absences.models.instances","leave-absences.settings","leave-absences.mocks"])}),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,s){return n.debug("AbsenceTypeAPI"),a.extend({all:function(t){return n.debug("AbsenceTypeAPI.all"),this.sendGET("AbsenceType","get",e.defaults(t||{},{is_active:!0})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,o,i){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),i=e.assign({},i,{absence_type_id:a,date:t(o).format(s.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",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/absence-type-api","leave-absences/shared/instances/absence-type.instance"],function(e){"use strict";e.factory("AbsenceType",["$log","Model","AbsenceTypeAPI","AbsenceTypeInstance",function(e,t,n,a){return e.debug("AbsenceType"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return a.init(e,!0)})})},calculateToilExpiryDate:function(e,t,a){return n.calculateToilExpiryDate(e,t,a)},canExpire:function(e){return n.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})}})}])}),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,s,o,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:s,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,s,o){return t.debug("WorkPatternAPI.getCalendar",n,a,s,o),this.sendGET("WorkPattern","getcalendar",e.assign({},o,{contact_id:e.isArray(n)?{IN:n}:n,start_date:a,end_date:s}))},unassignWorkPattern:function(e){return this.sendPOST("ContactWorkPattern","delete",{id:e})},workPatternsOf:function(t,n,s){return this.sendGET("ContactWorkPattern","get",e.assign({},n,{contact_id:t,"api.WorkPattern.get":{id:"$value.pattern_id"}}),s).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,s,o,i){function r(t,n){return l().then(function(a){var s=this.days[c(t).valueOf()];return!!s&&e.find(a,function(e){return e.name===n}).value===s.type}.bind(this))}function c(e){return t(e,o.serverDateFormat).clone()}function l(){return u=u||i.valuesOf("hrleaveandabsences_work_day_type")}var u;return s.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,s){return t.debug("Calendar"),n.extend({get:function(n,o,i,r){return t.debug("Calendar.get"),a.getCalendar(n,o,i,r).then(function(t){var a=t.values.map(function(e){return s.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 s(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(s),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})}})}])}),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/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance",function(t,n,a,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 s.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 s.init(e,!0)})})}})}])}),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,s,o,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,s,o,"getFull",i)),r.promise},balanceChangeByAbsenceType:function(t,n,s,o){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:s?{IN:s}:null,public_holiday:o||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",r,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(t){e.debug("LeaveRequestAPI.calculateBalanceChange",t);var n=a.defer();return!t||t.contact_id&&t.from_date&&t.from_date_type||n.reject("contact_id, from_date and from_date_type in params are mandatory"),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){n.resolve(e.values)}),n.promise},create:function(t){e.debug("LeaveRequestAPI.create",t);var n=a.defer();return t&&(t.to_date&&!t.to_date_type?n.reject("to_date_type is mandatory"):t.contact_id&&t.from_date&&t.from_date_type&&t.status_id||n.reject("contact_id, from_date, status_id and from_date_type params are mandatory")),this.sendPOST("LeaveRequest","create",t).then(function(e){n.resolve(e.values[0])}),n.promise},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","get",{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 s=a.defer();return this.sendPOST("LeaveRequest","isValid",n).then(function(e){e.count>0?s.reject(t(e.values).map().flatten().value()):s.resolve(e.values)}),s.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","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI",function(t,n,a,s,o,i){function r(e){return u(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 c(e){return u(e).then(function(e){return this.status_id===e.value}.bind(this))}function l(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function u(e){return a.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return t.find(function(t){return t.name===e})})}function d(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),t.all(n)}return o.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},cancel:function(){return r.call(this,s.statusNames.cancelled)},approve:function(){return r.call(this,s.statusNames.approved)},reject:function(){return r.call(this,s.statusNames.rejected)},sendBack:function(){return r.call(this,s.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return t.all([d.call(this),l.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([d.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){return t.comment_id?void(t.toBeDeleted=!0):void(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)},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return c.call(this,s.statusNames.approved)},isAwaitingApproval:function(){return c.call(this,s.statusNames.awaitingApproval)},isCancelled:function(){return c.call(this,s.statusNames.cancelled)},isRejected:function(){return c.call(this,s.statusNames.rejected)},isSentBack:function(){return c.call(this,s.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):n(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)):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,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,s,o,i){return n.all(this.processFilters(e),t,s,o,i).then(function(e){return e.list=e.list.map(function(e){return a.init(e,!0)}),e})},balanceChangeByAbsenceType:function(e,t,a,s){return n.balanceChangeByAbsenceType(e,t,a,s)},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange"),n.calculateBalanceChange(t)},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(e,t,n,a){return e.debug("WorkPattern"),t.extend({assignWorkPattern:function(e,t,a,s,o,i){return n.assignWorkPattern(e,t,a,s,o,i)},default:function(){return n.get({default:!0}).then(function(e){return a.init(e[0],!0)})},unassignWorkPattern:function(e){return n.unassignWorkPattern(e)},workPatternsOf:function(e,t,s){return n.workPatternsOf(e,t,s).then(function(e){return e.map(function(e){return a.init(e,!0)})})}})}])}),define("leave-absences/shared/modules/components",["common/angular"],function(e){return e.module("leave-absences.components",[])}),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"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all().then(function(e){o.lookupContacts=e.list}).then(a)}}}function a(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:o.filters.userSettings.department?o.filters.userSettings.department.value:null,level_type:o.filters.userSettings.level_type?o.filters.userSettings.level_type.value:null,location:o.filters.userSettings.location?o.filters.userSettings.location.value:null,region:o.filters.userSettings.region?o.filters.userSettings.region.value:null,id:{IN:o.filters.userSettings.contact?[o.filters.userSettings.contact.id]:o.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarAdminController");var o;return{init:function(e){return o=e,o.showContactName=!0,o.showFilters=!0,n()}}}n.controller("LeaveCalendarAdminController",["$log","Contact",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(s)}}}function s(){return t.all(o(),null,"display_name").then(function(e){return e.list})}function o(){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,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 s(a,s,o,i,r,c,l,u,d,m,f,h,p){function v(){for(var e=[],t=n(B.selectedPeriod.start_date).clone().startOf("month"),a=n(B.selectedPeriod.end_date).clone().endOf("month");t.isBefore(a);)e.push(k(t)),t.add(1,"month");B.months=e}function b(){i.$new().$watch(function(){return B.selectedMonths},function(t,n){null===n||e.equals(t,n)||O()})}function g(e){$("injected").then(function(){O(e)}).then(function(){B.loading.calendar=!1}),R().then(function(){B.injectMonths=!0})}function _(){L=a("LeaveCalendar"+t.capitalize(x)+"Controller").init(B)}function y(e){return e.current?"Current Period ("+e.title+")":e.title}function q(){return l.all().then(function(e){B.absencePeriods=t.sortBy(e,"start_date"),B.selectedPeriod=t.find(B.absencePeriods,function(e){return!!e.current})}).then(v).then(S)}function P(){return u.all({is_active:!0})}function A(){return f.valuesOf(["hrleaveandabsences_leave_request_status","hrleaveandabsences_leave_request_day_type"])}function D(){return L.loadContacts().then(function(e){B.contacts=e})}function C(){return f.valuesOf(["hrjc_region","hrjc_location","hrjc_level_type","hrjc_department"]).then(function(e){B.filters.optionValues.regions=e.hrjc_region,B.filters.optionValues.locations=e.hrjc_location,B.filters.optionValues.levelTypes=e.hrjc_level_type,B.filters.optionValues.departments=e.hrjc_department})}function T(){return m.all()}function w(){return s.all([P(),T(),A()]).then(function(e){B.supportData.absenceTypes=e[0],B.supportData.publicHolidays=e[1],B.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,B.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type})}function R(){var e=s.resolve();return B.injectMonths&&(e=$("destroyed"),B.injectMonths=!1),e}function k(e){return{index:e.month(),year:e.year(),name:e.format("MMM")}}function I(e){e=t.includes(["contacts","period"],e)?e:"period",s.resolve().then(function(){B.loading.calendar=!0}).then("period"===e?v:t.noop).then("contacts"===e?D:t.noop).then(function(){g("contacts"===e)})}function O(e){var n=B.selectedMonths.length?B.months.filter(function(e){return t.includes(B.selectedMonths,e.index)}):B.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function S(){B.selectedMonths=[n().month()]}function M(){return B.roleOverride?s.resolve().then(function(){x=B.roleOverride}):s.all([p(c.permissions.admin.administer),p(c.permissions.ssp.manage)]).then(function(e){x=e[0]?"admin":e[1]?"manager":"staff"})}function $(e){return s(function(n){var a=0,s=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===B.months.length&&(s(),n())})})}o.debug("Component: leave-calendar");var L,x,B=this;B.absencePeriods=[],B.contacts=[],B.injectMonths=!1,B.months=[],B.selectedMonths=null,B.selectedPeriod=null,B.showContactName=!1,B.showFilters=!1,B.supportData={},B.loading={calendar:!0,page:!0},B.filters={optionValues:{},userSettings:{contact:null,contacts_with_leaves:!1,department:null,level_type:null,location:null,region:null}},B.labelPeriod=y,B.refresh=I,function(){M().then(b).then(_).then(function(){return s.all([D(),q(),w()])}).then(function(){return B.showFilters?C():t.noop}).then(function(){g()}).then(function(){B.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","$timeout","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","PublicHoliday","OptionGroup","Calendar","checkPermissions",s]})}),define("leave-absences/shared/components/leave-calendar-day.component",["leave-absences/shared/modules/components"],function(e){function t(e,t){"use strict";function n(e,n,a,s,o){e.stopPropagation(),t.openModal(n,a,s,o)}e.debug("Component: leave-calendar-day");var a=this;a.openLeavePopup=n}e.component("leaveCalendarDay",{bindings:{contactData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:t}),t.$inject=["$log","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.collapsed=!1,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"],function(e,t,n){function a(n,a,s,o,i,r){function c(e,t){v([t]),$(t)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:u(e)}}function u(n){var a=t(),s=n.clone().startOf("month");return e.map(e.times(n.daysInMonth()),function(){var e={date:s.format("YYYY-MM-DD"),name:s.format("ddd"),index:s.format("D"),current:a.isSame(s,"day"),enabled:s.isSameOrAfter(F.period.start_date)&&s.isSameOrBefore(F.period.end_date),contactsData:{}};return s.add(1,"day"),e})}function d(e){return B[e]}function m(){return F.showOnlyWithLeaveRequests?F.contacts.filter(function(t){return e.includes(Object.keys(E),t.id)}):F.contacts}function f(e){return t(e,r.serverDateFormat)}function h(e,t){w(t),$(t)}function p(){F.supportData.dayTypes=e.indexBy(F.supportData.dayTypes,"name"),F.supportData.leaveRequestStatuses=e.indexBy(F.supportData.leaveRequestStatuses,"value"),F.supportData.publicHolidays=e.transform(F.supportData.publicHolidays,function(e,t){e[f(t.date).valueOf()]=t},{})}function v(e){return e.forEach(function(e){var t=q(e);E[e.contact_id]=E[e.contact_id]||{},t.forEach(function(t){E[e.contact_id][t.date]=e})}),a.resolve()}function b(){x.push(s.$on("LeaveCalendar::showMonths",O)),x.push(s.$on("LeaveRequest::new",c)),x.push(s.$on("LeaveRequest::edit",M)),x.push(s.$on("LeaveRequest::updatedByManager",M)),x.push(s.$on("LeaveRequest::deleted",h))}function g(e,n,a){var s=F.supportData.dayTypes[e];return t(a).isSame(n.from_date)?s.value===n.from_date_type:t(a).isSame(n.to_date)?s.value===n.to_date_type:void 0}function _(e){var t=F.supportData.leaveRequestStatuses[e.status_id];return t.name===r.statusNames.awaitingApproval}function y(e){return!!F.supportData.publicHolidays[f(e).valueOf()]}function q(n){for(var a=[],s=t(n.from_date).clone(),o=t(n.to_date);s.isSameOrBefore(o);)s.month()===F.month.index&&s.year()===F.month.year&&a.push(e.find(F.month.days,function(e){return e.date===s.format("YYYY-MM-DD")})),s.add(1,"day");return a}function P(t){return e.find(E[t.contact_id],function(e){return t.id===e.id})}function A(t){var n=e.find(F.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function D(){return F.month.loading=!0, +a.all([T(),C()]).then(function(){return I()}).then(function(){L=!0}).then(function(){F.month.loading=!1})}function C(){var e={from:F.month.days[0].date,to:F.month.days[F.month.days.length-1].date};return i.all({from_date:e,to_date:e,options:{or:[["from_date","to_date"]]},status_id:{IN:[A(r.statusNames.approved),A(r.statusNames.adminApproved),A(r.statusNames.awaitingApproval)]},contact_id:{IN:F.contacts.map(function(e){return e.id})}},null,null,null,!1).then(function(e){return v(e.list)})}function T(){var t=F.month.days[0].date,n=F.month.days[F.month.days.length-1].date;return o.get(F.contacts.map(function(e){return e.id}),t,n).then(function(t){B=e.indexBy(t,"contact_id")})}function w(t){E[t.contact_id]=e.omit(E[t.contact_id],function(e){return e.id===t.id})}function R(){s.$emit("LeaveCalendar::monthDestroyed"),x.map(function(e){e()})}function k(t,n,s){var o,i;return t.contactsData[n]=t.contactsData[n]||{},i=d(n),o=s===!0?a.resolve():a.all([i.isWeekend(f(t.date)),i.isNonWorkingDay(f(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:y(t.date)})}),o.then(function(){return E[n]?E[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?S(a):null,isAccruedTOIL:a?a.balance_change>0:null,isRequested:a?_(a):null,isAM:a?g("half_day_am",a,t.date):null,isPM:a?g("half_day_pm",a,t.date):null})})}function I(){return a.all(F.month.days.map(function(e){return a.all(F.contacts.map(function(t){return k(e,t.id)}))}))}function O(t,n,a){var s=!!e.find(n,function(e){return e.index===F.month.index});s?(F.currentPage=0,F.visible=!0,(a||!L)&&D()):F.visible=!1}function S(t){var n=e.find(F.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 M(e,t){var n=P(t);h(null,n),c(null,t)}function $(e){return a.all(q(e).map(function(t){return k(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var L=!1,x=[],B={},E={},F=this;F.currentPage=0,F.pageSize=20,F.visible=!1,F.showContactName=!!F.showContactName,F.showOnlyWithLeaveRequests=!!F.showOnlyWithLeaveRequests,F.$onDestroy=R,F.contactsList=m,function(){var e=t().month(F.month.index).year(F.month.year);p(),b(),F.month=l(e),s.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",month:"<",period:"<",showContactName:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","shared-settings",a]})}),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"],function(e,t,n){function a(n,a,s,o,i,r,c){function l(e){var t=_[e].dialog;v=b.leaveRequest.status_id,s.open({title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return b.leaveRequest[e]().then(function(){f(e)}).catch(function(e){c.error("Error:",e)})}})}function u(){var e=b.absenceTypes[b.leaveRequest.type_id].allow_request_cancelation;return"admin"===b.role||"manager"===b.role||("3"===e?t().isBefore(b.leaveRequest.from_date):"2"===e)}function d(){Array.isArray(b.leaveRequestStatuses)&&(b.leaveRequestStatuses=e.indexBy(b.leaveRequestStatuses,"value")),Array.isArray(b.absenceTypes)&&(b.absenceTypes=e.indexBy(b.absenceTypes,"id"))}function m(e,t,n,a,s){e.stopPropagation(),o.openModal(t,n,a,s)}function f(t){var n=e.find(b.leaveRequestStatuses,function(e){return e.name===r.statusNames.awaitingApproval}).value;v===n&&i.publish("ManagerBadge:: Update Count"),a.$emit("LeaveRequest::"+("delete"===t?"deleted":"edit"),b.leaveRequest)}function h(){var t=b.leaveRequestStatuses[b.leaveRequest.status_id].name,n=e.compact(e.map(_,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!u()&&e.pull(n,"cancel"),"admin"!==b.role&&e.pull(n,"delete"),"staff"===b.role&&e.pull(n,"approve","reject"),"staff"!==b.role&&p(n),b.allowedActions=e.map(n,function(e){return{key:e,label:_[e].label,isDirectAction:_[e].isDirectAction}})}function p(t){e.each(t,function(e,n){"edit"===e&&(t[n]="respond"),"respond"===e&&(t[n]="edit")})}n.debug("Component: leave-request-action-dropdown");var v,b=this,g=r.statusNames,_={edit:{label:"Edit",allowedStatuses:[g.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[g.moreInformationRequired]},view:{label:"View",allowedStatuses:[g.approved,g.rejected,g.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired,g.approved,g.rejected,g.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};b.allowedActions=[],b.action=l,b.openLeavePopup=m,function(){d(),h()}()}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","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,s,o,i,r){function c(){var t=e.indexBy(m.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){m.comment.contacts=e.indexBy(t.list,"contact_id")})}function l(){return m.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),m.request.comments.length&&c()})}function u(){return m.loading.component=!0,r.get().then(function(e){d=e.contactId}).then(function(){m.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var d=null,m=this;m.loading={component:!0},m.comment={text:"",contacts:{}},function(){l(),u()}(),m.addComment=function(){m.request.comments.push({contact_id:d,leave_request_id:m.request.id,text:m.comment.text}),m.comment.text=""},m.formatDateTime=function(e){return t.utc(e,o.serverDateTimeFormat).local().format(s.DATE_FORMAT.toUpperCase()+" HH:mm")},m.getActiveComments=function(){return m.request.comments.filter(function(e){return!e.toBeDeleted})},m.getCommentorName=function(e){return e===d?"Me":m.comment.contacts[e]?m.comment.contacts[e].display_name:void 0},m.isMode=function(e){return m.mode===e},m.orderComment=function(e){return t(e.created_at,o.serverDateTimeFormat)},m.removeCommentVisibility=function(e){return!e.comment_id||m.canManage}}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"directives/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","HR_settings","shared-settings","Contact","Session",a]})}),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,s,o,i,r,c,l){function u(){return e.filter(A.request.files,function(e){return e.toBeDeleted})}function d(){return A.fileUploader&&A.fileUploader.queue?A.fileUploader.queue:[]}function m(){q.push(a.$on("LeaveRequestPopup::submit",_))}function f(){v().then(function(){A.fileUploader=c.uploader({entityTable:"civicrm_hrleaveandabsences_leave_request",crmAttachmentToken:i.attachmentToken,queueLimit:i.fileUploader.queueLimit,allowedMimeTypes:P})})}function h(){return y.length>0?y.map(function(e){return e.label}).join(", "):""}function p(){return A.request.loadAttachments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function v(){return s.all(y.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){P[e.label]=t})})).catch(function(){P=null})}function b(){return r.valuesOf("safe_file_extension").then(function(e){y=e})}function g(){e.forEach(q,function(e){e()})}function _(e,t){A.fileUploader.queue&&A.fileUploader.queue.length>0?A.fileUploader.uploadAll({entityID:A.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var y=[],q=[],P={},A=Object.create(this);return A.filesLoaded=!1,A.today=Date.now(),A.userDateFormatWithTime=o.DATE_FORMAT+" HH:mm",A.userDateFormat=o.DATE_FORMAT,A.listFileTypes=h,A.$onDestroy=g,A.canUploadMore=function(){return A.getFilesCount()=":e}};return a.all(n).then(function(e){return e&&e.length?s.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,s,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 s.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var s=e(n).format(o.serverDateFormat),i={date:s};return a.all(i).then(function(e){return!!e.length})}})}])}),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/calendar-model","leave-absences/shared/models/entitlement-model","leave-absences/shared/models/leave-request-model","leave-absences/shared/models/public-holiday-model"],function(e,t,n,a){"use strict";function s(t,s,o,i,r,c,l,u,d,m,f,h,p,v,b,g,_){function y(){var e=this.requestStatuses[_.statusNames.awaitingApproval].value;Ee.status_id===e&&e!==this.request.status_id&&m.publish("ManagerBadge:: Update Count")}function q(){var e=this;return e._setDateAndTypes(),P.call(e)?(e.loading.showBalanceChange=!0,b.calculateBalanceChange(L.call(e)).then(function(t){t&&(e.balance.change=t,e._calculateOpeningAndClosingBalance(),ue.call(e)),e.loading.showBalanceChange=!1}).catch(F.bind(e))):s.resolve()}function P(){return!!(this.request.from_date&&this.request.to_date&&this.request.from_date_type&&this.request.to_date_type)}function A(){var e=P.call(this);return this.isMode("edit")&&(e=e&&j.call(this)),this.canManage&&this.requestStatuses&&(e=e&&!!this.getStatusFromValue(this.newStatusOnSave)),e=e&&!!this.period.id,e&&!this.isMode("view")}function D(){this._reset(),this._calculateOpeningAndClosingBalance()}function C(){this.isSelfRecord?this.request.status_id=this.requestStatuses[_.statusNames.awaitingApproval].value:this.canManage&&(this.request.status_id=this.newStatusOnSave||this.request.status_id)}function T(){this.errors=[]}function w(){return this.request.create().then(be).then(function(){le.call(this,"LeaveRequest::new")}.bind(this))}function R(){r.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return this.directiveOptions.leaveRequest.delete().then(function(){this.dismissModal(),o.$emit("LeaveRequest::deleted",this.directiveOptions.leaveRequest)}.bind(this))}.bind(this)})}function k(){this.$modalInstance.dismiss({$value:"cancel"})}function I(e,t){var a;return e?(a=this.requestDayTypes.slice(0),e=this._convertDateToServerFormat(e),g.isPublicHoliday(e).then(function(t){return t?a.filter(function(e){return"public_holiday"===e.name}):$.call(this,e,a).then(function(e){return e.length?e:a.filter(function(e){return n.includes(["all_day","half_day_am","half_day_pm"],e.name)})})}.bind(this)).then(function(e){return fe.call(this,t,e),e}.bind(this))):s.reject([])}function O(e){return a(e,_.serverDateTimeFormat).format(this.uiOptions.userDateFormat.toUpperCase()+" HH:mm")}function S(){var e=this.getStatusFromValue(this.request.status_id);return M.call(this,e.name)}function M(e){return n.map(xe[e],function(e){return this.requestStatuses[e]}.bind(this))}function $(e,t){return e=a(e),s.all([this.calendar.isNonWorkingDay(e),this.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(t){return t.name===e}):[]})}function L(){return n.pick(this.request,["contact_id","from_date","from_date_type","to_date","to_date_type"])}function x(){return n.find(this.absenceTypes,function(e){return e.id===this.request.type_id}.bind(this))}function B(){return!this.request||e.equals({},this.requestStatuses)?[]:this.request.status_id?S.call(this):M.call(this,"none")}function E(e){return n.find(this.requestStatuses,function(t){return t.value===e})}function F(e){this.errors=n.isArray(e)?e:[e],this.loading.showBalanceChange=!1,this.loading.absenceTypes=!1,this.loading.fromDayTypes=!1,this.loading.toDayTypes=!1,this.submitting=!1}function j(){return!e.equals(Ee,this.request.attributes())||this.fileUploader&&0!==this.fileUploader.queue.length||this.canManage&&this.newStatusOnSave}function N(){this.period=n.find(this.absencePeriods,function(e){return e.current})}function W(){var e=this;return e.postContactSelection=!0,e.request.contact_id?s.all([e._loadAbsenceTypes(),e._loadCalendar()]).then(function(){return ne.call(e)}).then(function(){return G.call(e)}).then(function(){return he.call(e),K.call(e),H.call(e),e.isMode("edit")&&pe.call(e),e.postContactSelection=!1,e.calculateBalanceChange()}).catch(function(e){if(e!==Ue)return s.reject(e)}):s.reject("The contact id was not set")}function U(){var e=[_.statusNames.moreInformationRequired,_.statusNames.approved,_.statusNames.rejected,_.statusNames.cancelled];xe.none=[_.statusNames.moreInformationRequired,_.statusNames.approved],xe.awaiting_approval=e,xe.more_information_required=e,xe.rejected=e,xe.approved=e,xe.cancelled=[_.statusNames.awaitingApproval].concat(e)}function H(){return this.canManage?i.find(this.request.contact_id).then(function(e){this.contactName=e.display_name}.bind(this)):s.resolve()}function G(){if(this.isMode("create"))return s.resolve();var e=this.request.attributes();return this.uiOptions.fromDate=this._convertDateFormatFromServer(this.request.from_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.fromDate,"from").then(function(){return this.request.to_date=e.to_date,this.request.to_date_type=e.to_date_type,this.uiOptions.toDate=this._convertDateFormatFromServer(this.request.to_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.toDate,"to")}.bind(this))}function Y(){Fe.push(o.$on("LeaveRequestPopup::requestObjectUpdated",pe.bind(this)),o.$on("LeaveRequestPopup::childComponent::register",function(){Be++}))}function V(){if(this.request.id){this.mode="edit";var e=[this.requestStatuses[_.statusNames.approved].value,this.requestStatuses[_.statusNames.adminApproved].value,this.requestStatuses[_.statusNames.rejected].value,this.requestStatuses[_.statusNames.cancelled].value];this.isRole("staff")&&e.indexOf(this.request.status_id)>-1&&(this.mode="view")}else this.mode="create"}function z(){return Ne="staff",d(_.permissions.admin.administer).then(function(e){Ne=e?"admin":Ne}).then(function(){return"staff"===Ne&&d(_.permissions.ssp.manage).then(function(e){Ne=e?"manager":Ne})}).finally(function(){this.canManage=this.isRole("manager")||this.isRole("admin"),this.isSelfRecord=this.directiveOptions.isSelfRecord}.bind(this))}function K(){(this.isRole("admin")||this.isMode("create")&&this.isRole("manager"))&&(this.newStatusOnSave=this.requestStatuses[_.statusNames.approved].value)}function X(e){var t=this.getStatusFromValue(this.request.status_id);return!!t&&t.name===e}function J(e){return this.request.request_type===e}function Q(e){return this.mode===e}function Z(e){return Ne===e}function ee(e,t){var n=this.period.id;return t=t||"from",this.loading[t+"DayTypes"]=!0,this._checkAndSetAbsencePeriod(e).then(function(){var e=n===this.period.id;if(!e)return this.uiOptions.multipleDays&&"from"===t&&(this.uiOptions.showBalance=!1,this.uiOptions.toDate=null,this.request.to_date=null,this.request.to_date_type=null),s.all([this._loadAbsenceTypes(),this._loadCalendar()])}.bind(this)).then(function(){return this._setMinMaxDate(),I.call(this,e,t)}.bind(this)).finally(function(){this.loading[t+"DayTypes"]=!1}.bind(this))}function te(){var e=this;return c.all().then(function(t){e.absencePeriods=t})}function ne(){var e=this;return u.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(t){e.requestDayTypes=t})}function ae(){return v.get().then(function(e){je=e.contactId})}function se(){return this.directiveOptions.selectedContactId?i.find(this.directiveOptions.selectedContactId).then(function(e){this.managedContacts=[e]}.bind(this)):this.isRole("admin")?i.all().then(function(e){this.managedContacts=n.remove(e.list,function(e){return e.id!==je})}.bind(this)):i.find(je).then(function(e){return e.leaveManagees()}).then(function(e){this.managedContacts=e}.bind(this))}function oe(){var e=this;return u.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){e.requestStatuses=n.indexBy(t,"name")})}function ie(e,t){return t.map(function(t){var a=n.find(e,function(e){return e.id===t.type_id});return{id:t.type_id,title:a.title+" ( "+t.remainder.current+" ) ",remainder:t.remainder.current,allow_overuse:a.allow_overuse}})}function re(){this.$modalInstance.close({$value:this.request})}function ce(){var e=(this.currentPage-1)*this.numPerPage,t=e+this.numPerPage;this.filteredbreakdown=We.balance.change.breakdown.slice(e,t)}function le(e){y.call(this),o.$emit(e,this.request),this.errors=[],this.ok()}function ue(){this.pagination.totalItems=this.balance.change.breakdown.length,this.pagination.filteredbreakdown=this.balance.change.breakdown,this.pagination.pageChanged()}function de(e){var t=this;return h.all({contact_id:t.request.contact_id,period_id:t.period.id,type_id:{IN:e.ids}},!0).then(function(n){if(t.absenceTypes=ie(e.types,n),!t.absenceTypes.length)return s.reject(Ue)})}function me(){(this.isMode("edit")&&this.request.from_date===this.request.to_date||this.isMode("create")&&this.isLeaveType("sickness"))&&(this.uiOptions.multipleDays=!1)}function fe(e,t){var a="request"+n.startCase(e)+"DayTypes";this[a]=t,this.isMode("create")&&(this.request[e+"_date_type"]=this[a][0].value)}function he(){this.isMode("create")?(this.selectedAbsenceType=this.absenceTypes[0],this.request.type_id=this.selectedAbsenceType.id):this.selectedAbsenceType=x.call(this)}function pe(){Ee=e.copy(this.request.attributes())}function ve(){var e=this.request.status_id;if(!this.isMode("view")&&!this.submitting)return this.submitting=!0,C.call(this),Pe.call(this).then(function(){return this.isMode("edit")?qe.call(this):w.call(this)}.bind(this)).catch(function(t){this.request.status_id=e,t&&F.call(this,t)}.bind(this)).finally(function(){this.submitting=!1}.bind(this))}function be(){function e(e){e&&n.push(e),++a===Be&&(ge(),n.length>0?t.reject(n):t.resolve())}var t=s.defer(),n=[],a=0;return Be>0?o.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function ge(){n.forEach(Fe,function(e){e()})}function _e(e,t){return this.loadAbsencePeriodDatesTypes(e,t).then(function(){return this.updateBalance()}.bind(this)).catch(function(e){F.call(this,e),this._setDateAndTypes()}.bind(this))}function ye(){this.selectedAbsenceType=x.call(this),this.balance.opening=this.selectedAbsenceType.remainder,this.calculateBalanceChange()}function qe(){return this.request.update().then(be).then(function(){this.isRole("manager")?le.call(this,"LeaveRequest::updatedByManager"):(this.isRole("staff")||this.isRole("admin"))&&le.call(this,"LeaveRequest::edit")}.bind(this))}function Pe(){return this.balance.closing<0&&"0"===this.selectedAbsenceType.allow_overuse?s.reject(["You cannot make a request for this leave type at this time as this would leave you with a negative balance"]):this.request.isValid()}function Ae(){this.balance.opening=this.selectedAbsenceType.remainder,this.balance.closing=this.balance.opening+this.balance.change.amount}function De(e){var t=a(e).format(this.uiOptions.userDateFormat.toUpperCase());return this.period=n.find(this.absencePeriods,function(e){return e.isInPeriod(t)}),this.period?s.resolve(!0):(this.period={},this.loading.fromDayTypes=!1,s.reject("Please change date as it is not in any absence period"))}function Ce(e){return a(e,_.serverDateFormat).toDate()}function Te(e){return a(e).format(_.serverDateFormat)}function we(){return U.call(this),Y.call(this),ae.call(this).then(z.bind(this)).then(this._initRequest.bind(this)).then(oe.bind(this)).then(function(){ +return V.call(this),this.canManage&&!this.isMode("edit")&&se.call(this)}.bind(this)).then(te.bind(this)).then(function(){N.call(this),this._setMinMaxDate()}.bind(this)).then(function(){if(this.directiveOptions.selectedContactId&&(this.request.contact_id=this.directiveOptions.selectedContactId),me.call(this),this.request.contact_id)return this.initAfterContactSelection()}.bind(this)).catch(F.bind(this))}function Re(){var e={};return this.directiveOptions.leaveRequest?e=this.directiveOptions.leaveRequest.attributes():this.canManage||(e={contact_id:je}),e}function ke(){var e=this;return l.all(e.initParams.absenceType).then(function(t){var n=t.map(function(e){return e.id});return Le={types:t,ids:n},de.call(e,Le)})}function Ie(){var e=this;return f.get(e.request.contact_id,e.period.start_date,e.period.end_date).then(function(t){e.calendar=t})}function Oe(){this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date_type=this.request.from_date_type,this.request.to_date=this.request.from_date,this.calculateBalanceChange()}function Se(){this._setDates(),this.uiOptions.multipleDays?this.uiOptions.showBalance=!!(this.request.from_date&&this.request.from_date_type&&this.request.to_date&&this.request.to_date_type&&this.period.id):(this.uiOptions.fromDate&&(this.request.to_date_type=this.request.from_date_type),this.uiOptions.showBalance=!!this.request.from_date&&!!this.request.from_date_type&&!!this.period.id)}function Me(){this.request.from_date=this.uiOptions.fromDate?this._convertDateToServerFormat(this.uiOptions.fromDate):null,this.request.to_date=this.uiOptions.toDate?this._convertDateToServerFormat(this.uiOptions.toDate):null,!this.uiOptions.multipleDays&&this.uiOptions.fromDate&&(this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date=this.request.from_date)}function $e(){if(this.uiOptions.fromDate){var e=a(this.uiOptions.fromDate).add(1,"d").toDate();this.uiOptions.date.to.options.minDate=e,this.uiOptions.date.to.options.initDate=e,this.uiOptions.toDate&&a(this.uiOptions.toDate).isBefore(this.uiOptions.fromDate)&&(this.uiOptions.toDate=this.uiOptions.fromDate)}else this.uiOptions.date.to.options.minDate=this._convertDateFormatFromServer(this.period.start_date),this.uiOptions.date.to.options.initDate=this.uiOptions.date.to.options.minDate;this.uiOptions.date.to.options.maxDate=this._convertDateFormatFromServer(this.period.end_date)}t.debug("RequestCtrl");var Le,xe={},Be=0,Ee={},Fe=[],je="",Ne="",We=this,Ue="No entitlement";this.absencePeriods=[],this.absenceTypes=[],this.calendar={},this.canManage=!1,this.contactName=null,this.errors=[],this.fileUploader=null,this.isSelfRecord=!1,this.managedContacts=[],this.mode="",this.newStatusOnSave=null,this.period={},this.postContactSelection=!1,this.requestDayTypes=[],this.requestStatuses={},this.selectedAbsenceType={},this.statusNames=_.statusNames,this.submitting=!1,this.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},this.loading={absenceTypes:!0,showBalanceChange:!1,fromDayTypes:!1,toDayTypes:!1},this.pagination={currentPage:1,filteredbreakdown:this.balance.change.breakdown,numPerPage:7,totalItems:this.balance.change.breakdown.length,pageChanged:ce},this.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:p.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}}}},this.changeInNoOfDays=D,this.calculateBalanceChange=q,this.canSubmit=A,this.closeAlert=T,this.deleteLeaveRequest=R,this.dismissModal=k,this.formatDateTime=O,this.getStatuses=B,this.getStatusFromValue=E,this.initAfterContactSelection=W,this.isLeaveStatus=X,this.isLeaveType=J,this.isMode=Q,this.isRole=Z,this.ok=re,this.submit=ve,this.loadAbsencePeriodDatesTypes=ee,this.updateAbsencePeriodDatesTypes=_e,this.updateBalance=ye,this._calculateOpeningAndClosingBalance=Ae,this._checkAndSetAbsencePeriod=De,this._convertDateToServerFormat=Te,this._convertDateFormatFromServer=Ce,this._init=we,this._initRequestAttributes=Re,this._loadCalendar=Ie,this._loadAbsenceTypes=ke,this._reset=Oe,this._setDates=Me,this._setDateAndTypes=Se,this._setMinMaxDate=$e}t.controller("RequestCtrl",s),s.$inject=["$log","$q","$rootScope","Contact","dialog","AbsencePeriod","AbsenceType","api.optionGroup","checkPermissions","pubSub","Calendar","Entitlement","HR_settings","Session","LeaveRequest","PublicHoliday","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/leave-request.controller",["leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/leave-request.instance"],function(e){function t(e,t,n,a,s){function o(){var e=r._initRequestAttributes();r.request=s.init(e)}t.debug("LeaveRequestCtrl");var i=e("RequestCtrl"),r=Object.create(i);return r.directiveOptions=a,r.$modalInstance=n,r.initParams={absenceType:{is_sick:!1}},r._initRequest=o,function(){r.loading.absenceTypes=!0,r._init().finally(function(){r.loading.absenceTypes=!1})}(),r}e.controller("LeaveRequestCtrl",t),t.$inject=["$controller","$log","$uibModalInstance","directiveOptions","LeaveRequestInstance"]}),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(){var e=this.sickness_required_documents?this.sickness_required_documents.split(","):[];return e},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/controllers/sub-controllers/sick-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/sickness-request.instance"],function(e,t){function n(t,n,a,s,o,i,r){function c(){return h.canSubmit.call(this)&&!!p.request.sickness_reason}function l(t){var n=p.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function u(t){return!!e.find(p.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return o.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){p.sicknessDocumentTypes=e})}function m(){return o.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){p.sicknessReasons=e.indexBy(t,"name")})}function f(){var e=p._initRequestAttributes();p.request=r.init(e)}n.debug("SicknessRequestCtrl");var h=t("RequestCtrl"),p=Object.create(h);return p.directiveOptions=i,p.$modalInstance=s,p.initParams={absenceType:{is_sick:!0}},p.canSubmit=c,p.isChecked=l,p.isDocumentInRequest=u,p._initRequest=f,function(){p.loading.absenceTypes=!0,p._init().then(function(){return a.all([d(),m()])}).finally(function(){p.loading.absenceTypes=!1})}(),p}t.controller("SicknessRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","directiveOptions","SicknessRequestInstance"]}),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/sub-controllers/toil-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/toil-request.instance"],function(e,t){function n(t,n,a,s,o,i,r,c){function l(){C.request.toil_to_accrue&&(C.loading.showBalanceChange=!0,C._setDateAndTypes(),C.balance.change.amount=+C.request.toil_to_accrue,C._calculateOpeningAndClosingBalance(),C.uiOptions.showBalance=!0,C.request.to_date_type=C.request.from_date_type="1",C.loading.showBalanceChange=!1)}function u(){return!C.canManage&&C.request.id?a.resolve(C.request.toil_expiry_date):C.requestCanExpire?p().catch(function(e){return e.length&&(C.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(C.request.type_id,e)}).then(function(e){return C.request.toil_expiry_date=e,C.uiOptions.expiryDate=new Date(e),e}):(C.request.toil_expiry_date=!1,a.resolve(!1))}function d(){return C.uiOptions.multipleDays&&C.request.to_date||!C.uiOptions.multipleDays&&C.request.from_date}function m(){return D.canSubmit.call(this)&&!!C.request.toil_duration&&!!C.request.toil_to_accrue&&!!C.request.from_date&&!!C.request.to_date}function f(){D.changeInNoOfDays.call(this),d()&&C.calculateToilExpiryDate()}function h(){C.request.toil_expiry_date=!1,C.uiOptions.expiryDate=null}function p(){return v(C.uiOptions.multipleDays?{hasErrors:!C.request.to_date&&!C.request.from_date,label:"To Date",value:C.request.to_date}:{hasErrors:!C.request.from_date,label:"From Date",value:C.request.from_date})}function v(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(e.value):a.reject([])}function b(){C.canManage&&(C.uiOptions.expiryDate=C._convertDateFormatFromServer(C.request.toil_expiry_date))}function g(){return i.canExpire(C.request.type_id).then(function(e){C.requestCanExpire=e})}function _(e){var t=C.period.id;return C._checkAndSetAbsencePeriod(e).then(function(){var e=t===C.period.id;if(!e)return C.uiOptions.multipleDays&&(C.uiOptions.showBalance=!1,C.uiOptions.toDate=null,C.request.to_date=null),a.all([C._loadAbsenceTypes(),C._loadCalendar()])})}function y(){return o.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){C.toilAmounts=e.indexBy(t,"value")})}function q(e){return C.loadAbsencePeriodDatesTypes().then(function(){C._setMinMaxDate(),C._setDates(),C.updateBalance(),C.calculateToilExpiryDate()}).catch(function(e){C.errors=[e]})}function P(){C.uiOptions.expiryDate&&(C.request.toil_expiry_date=C._convertDateToServerFormat(C.uiOptions.expiryDate))}function A(){var e=C._initRequestAttributes();C.request=c.init(e),C.request.to_date_type=C.request.from_date_type="1"}n.debug("ToilRequestCtrl");var D=t("RequestCtrl"),C=Object.create(D);return C.requestCanExpire=!0,C.directiveOptions=r,C.$modalInstance=s,C.initParams={absenceType:{allow_accruals_request:!0}},C.calculateBalanceChange=l,C.calculateToilExpiryDate=u,C.canSubmit=m,C.changeInNoOfDays=f,C.clearExpiryDate=h,C.loadAbsencePeriodDatesTypes=_,C.updateAbsencePeriodDatesTypes=q,C.updateExpiryDate=P,C._initRequest=A,function(){C.loading.absenceTypes=!0,C._init().then(function(){return g()}).then(function(){return b(),y()}).finally(function(){C.loading.absenceTypes=!1})}(),C}t.controller("ToilRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","AbsenceType","directiveOptions","TOILRequestInstance"]}),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-popup.service",["common/lodash","leave-absences/shared/modules/services","common/services/notification.service"],function(e,t){"use strict";function n(t,n,a,s,o,i,r,c,l,u){function d(e){return l.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function m(e,t){return t?t.request_type:e||null}function f(t,a,s,i){var c=e.capitalize(m(a,t))+"RequestCtrl";o.open({appendTo:n.children().eq(0),templateUrl:r.sharedPathTpl+"directives/leave-request-popup/leave-request-popup.html",controller:c,controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveRequest:t,selectedContactId:s,isSelfRecord:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function h(e){return u.find(e).then(function(e){return d(e).then(function(t){t?f(e,e.request_type,e.contact_id,"my-leave"===a.section):i.error("Error","You dont have permission to see this leave request")})}).catch(function(e){i.error("Error",e)})}return t.debug("LeavePopup"),{openModal:f,openModalByID:h}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$q","$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){t.component("absenceTabContainer",{templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-container.html"}],controllerAs:"absence",controller:["$log","$rootScope",function(t,n){t.debug("Component: absence-tab-container"),n.section="absence-tab";var a=this;a.contactId=e.adminId}]})})}(CRM),define("leave-absences/absence-tab/components/absence-tab-report.component",["leave-absences/absence-tab/modules/components"],function(e){function t(e){e.debug("Component: absence-tab-report")}e.component("absenceTabReport",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-report.html"}],controllerAs:"report",controller:["$log",t]})}),define("leave-absences/absence-tab/components/absence-tab-entitlements.component",["leave-absences/absence-tab/modules/components"],function(e){function t(e){e.debug("Component: absence-tab-entitlements");var t={};return t.contactId=this.contactId,t}e.component("absenceTabEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/absence-tab-entitlements.html"}],controllerAs:"entitlements",controller:["$log",t]})}),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,s,o,i){function r(e){u.errorMessage=e}function c(){return i.get().then(function(e){u.workPatterns=e})}function l(){return s.valuesOf("hrjc_revision_change_reason").then(function(e){u.changeReasons=e})}t.debug("Component: absence-tab-custom-work-pattern-modal");var u=Object.create(this);return u.changeReasons=[],u.errorMessage="",u.saveInProgress=!1,u.workPatterns=[],u.loading={content:!0},u.selected={workPattern:null,effectiveDate:null,changeReason:null},u.uiOptions={effectiveDate:{show:!1,options:{startingDay:1,showWeeks:!1}}},function(){return n.all([c(),l()]).finally(function(){u.loading.content=!1})}(),u.closeModal=function(){u.dismiss({$value:"cancel"})},u.closeAlert=function(){u.errorMessage=""},u.save=function(){var t=e(u.selected.effectiveDate).format(o.serverDateFormat);return u.saveInProgress=!0,i.assignWorkPattern(u.contactId,u.selected.workPattern.id,t,null,u.selected.changeReason).then(function(){a.$broadcast("CustomWorkPattern::Added"),u.closeModal()}).catch(r).finally(function(){u.saveInProgress=!1})},u}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,s,o,i,r,c,l,u,d){function m(){return d.workPatternsOf(_.contactId,{},!1).then(function(e){_.customWorkPatterns=e})}function f(){return d.default().then(function(e){_.defaultWorkPattern=e})}function h(){return u.valuesOf("hrjc_revision_change_reason").then(function(t){g=e.indexBy(t,"value")})}function p(e){var t=[m()];return e&&(t=t.concat(e)),_.loading.workPattern=!0,a.all(t).then(function(){v()}).finally(function(){_.loading.workPattern=!1})}function v(){var n,a=l.DATE_FORMAT.toUpperCase();_.customWorkPatterns=e(_.customWorkPatterns).map(function(e){return n=g[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()}function b(){var e="civicrm/admin/leaveandabsences/work_patterns",t="civicrm/contact/view",n=CRM.url(t,{cid:_.contactId,selectedChild:"absence"});return CRM.url(e,{cid:_.contactId,returnUrl:n})}n.debug("Component: absence-tab-work-patterns");var g=[],_=Object.create(this);return _.customWorkPatterns=[],_.defaultWorkPattern=null,_.linkToWorkPatternListingPage=b(),_.loading={workPattern:!0},function(){p([h(),f(),c.getDateFormat()]),o.$on("CustomWorkPattern::Added",function(){p()})}(),_.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(){p()})}})},_.openModal=function(){i.open({appendTo:s.children().eq(0),template:'',controller:["$uibModalInstance",function(e){this.dismiss=e.dismiss}],controllerAs:"$ctrl"})},_}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]})}),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 s(a,s,o,i,r,c,l){function u(){return i.all().then(h)}function d(){return o.all().then(function(e){v.absenceTypes=e})}function m(){var e=t.uniq(t.map(g,function(e){return e.comment_author_id}));return c.all({id:{IN:e}}).then(function(e){b=t.indexBy(e.list,"contact_id")})}function f(){return r.all({contact_id:v.contactId}).then(function(e){g=e})}function h(e){var a=t.uniq(t.map(g,function(e){return e.period_id}));e=t.filter(e,function(e){return a.indexOf(e.id)!==-1}),e=t.sortBy(e,function(e){return-n(e.start_date).valueOf()}),v.absencePeriods=t.map(e,function(e){var n=t.map(v.absenceTypes,function(n){var a=t.filter(g,function(t){return t.type_id===n.id&&t.period_id===e.id})[0];return a?{amount:a.value,comment:a.comment?{message:a.comment,author_name:b[a.comment_author_id].display_name,date:a.comment_date}:null}:null});return{period:e.title,entitlements:n}})}function p(t){var n="civicrm/admin/leaveandabsences/periods/manage_entitlements",a="civicrm/contact/view",s=e.url(a,{cid:t,selectedChild:"absence"});return e.url(n,{cid:t,returnUrl:s})}a.debug("Component: annual-entitlements");var v=this,b=[],g=[];return v.absencePeriods=[],v.absenceTypes=[],v.loading={absencePeriods:!0},v.editEntitlementsPageUrl=p(v.contactId),function(){return s.all([d(),f()]).then(function(){return m()}).then(function(){return u()}).finally(function(){v.loading.absencePeriods=!1})}(),v.showComment=function(e){var t=e.message+"

Last updated:
By: "+e.author_name+"
Date: "+n.utc(e.date).local().format("DD/M/YYYY HH:mm")+"
";l.info("Calculation comment:",t)},v}a.component("annualEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/annual-entitlements.html"}],controllerAs:"entitlements",controller:["$log","$q","AbsenceType","AbsencePeriod","Entitlement","Contact","notificationService",s]})})}(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,s,o,i,r){function c(e){var n=s.DATE_FORMAT.toUpperCase();return e?t(e).format(n):""}function l(){return o.all().then(function(e){m.absenceTypes=e})}function u(){return i.all({contact_id:m.contactId}).then(function(e){d(e)})}function d(n){m.contracts=e.sortBy(n,function(e){return t(e.info.details.period_start_date)}).map(function(t){var n=t.info,a=n.details,s=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:""}});return{position:a.position,start_date:c(a.period_start_date),end_date:c(a.period_end_date),absences:s}})}n.debug("Component: contract-entitlements");var m=this;return m.absenceTypes=[],m.contracts=[],m.loading={contracts:!0},function(){return a.all([l(),r.getDateFormat()]).then(function(){return u()}).finally(function(){m.loading.contracts=!1})}(),m}n.component("contractEntitlements",{bindings:{contactId:"<"},templateUrl:["settings",function(e){return e.pathTpl+"components/contract-entitlements.html"}],controllerAs:"entitlements",controller:["$log","$q","HR_settings","AbsenceType","Contract","DateFormat",a]})}),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),function(e){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"}])})}(CRM),define("leave-absences/absence-tab/app",["common/angular","common/angularBootstrap","common/text-angular","common/modules/dialog","common/services/check-permissions","common/services/angular-date/date-format","common/modules/directives","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-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/leave-request.controller","leave-absences/shared/controllers/sub-controllers/sick-request.controller","leave-absences/shared/controllers/sub-controllers/toil-request.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-report.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-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.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(){}); \ 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 638032d6128..5c50fc32304 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,6 +6,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 H(new(H(function(){},{prototype:e})),t)}function r(e){return V(arguments,function(t){t!==e&&V(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function s(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 i(e){if(Object.keys)return Object.keys(e);var t=[];return V(e,function(e,n){t.push(n)}),t}function o(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),a<0&&(a+=n);a=0||(c.push(r[f]),l[r[f]]=e[r[f]]);return H({},l,t)}function l(e,t,n){if(!n){n=[];for(var a in e)n.push(a)}for(var r=0;r "));if(g[n]=a,N(e))v.push(n,[function(){return t.get(e)}],l);else{var r=t.annotate(e);V(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}b.pop(),g[n]=s}}function h(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var p=i(u||{}),v=[],b=[],g={};return V(u,m),u=b=g=null,function(a,s,i){function o(){--_||($||r(y,s.$$values),b.$$values=y,b.$$promises=b.$$promises||!0,delete b.$$inheritedValues,m.resolve(y))}function u(e){b.$$failure=e,m.reject(e)}function l(n,r,s){function l(e){d.reject(e),u(e)}function c(){if(!j(b.$$failure))try{d.resolve(t.invoke(r,i,y)),d.promise.then(function(e){y[n]=e,o()},l)}catch(e){l(e)}}var d=e.defer(),f=0;V(s,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){y[e]=t,--f||c()},l))}),f||c(),g[n]=d.promise}if(h(a)&&i===n&&(i=s,s=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=c;if(s){if(!h(s))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else s=d;var m=e.defer(),b=m.promise,g=b.$$promises={},y=H({},a),_=1+v.length/3,$=!1;if(j(s.$$failure))return u(s.$$failure),b;s.$$inheritedValues&&r(y,f(s.$$inheritedValues,p)),H(g,s.$$promises),s.$$values?($=r(y,f(s.$$values,p)),b.$$inheritedValues=f(s.$$values,p),o()):(s.$$inheritedValues&&(b.$$inheritedValues=f(s.$$inheritedValues,p)),s.then(o,u));for(var q=0,w=v.length;q=0));)g=s(b.id,b.type,b.cfg,"path"),d+=i(b.segment,g.type.pattern.source,g.squash,g.isOptional),m.push(b.segment),f=l.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var $=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),$.length>0)for(f=0;u=c.exec($);)b=o(u,!0),g=s(b.id,b.type,b.cfg,"search"),f=l.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=i(y)+(t.strict===!1?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){H(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 s(){return{strict:p,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function l(){for(;q.length;){var e=q.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(b[e.name],d.invoke(e.def))}}function c(e){H(this,e||{})}z=this;var d,f=!1,p=!0,v=!1,b={},$=!0,q=[],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 e===!0||e===!1},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)&&(p=e),p},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(e!==!0&&e!==!1&&!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 g(e,H(s(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return V(g.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 b[e];if(b.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return b[e]=new y(H({name:e},t)),n&&(q.push({name:e,def:n}),$||l()),this},V(w,function(e,t){b[t]=new y(H({name:t},e))}),b=a(b,{}),this.$get=["$injector",function(e){return d=e,$=!1,l(),V(w,function(e,t){b[t]||(b[t]=new y(e))}),this}],this.Param=function(e,a,r,s){function l(e){var t=F(e)?i(e):[],n=o(t,"value")===-1&&o(t,"type")===-1&&o(t,"squash")===-1&&o(t,"array")===-1;return n&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}function c(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a?a:n.type?t.isString(n.type)?b[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?b.any:b.string}function f(){var t={array:"search"===s&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return H(t,n,r).array}function p(e,t){var n=e.squash;if(!t||n===!1)return!1;if(!j(n)||null==n)return v;if(n===!0||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}function g(e,t,a,r){var s,i,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return s=U(e.replace)?e.replace:[],N(r)&&s.push({from:r,to:n}),i=h(s,function(e){return e.from}),m(u,function(e){return o(i,e.from)===-1}).concat(s)}function _(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!w.type.is(e))throw new Error("Default value ("+e+") for parameter '"+w.id+"' is not an instance of Type ("+w.type.name+")");return e}function $(e){function t(e){return function(t){return t.from===e}}function n(e){var n=h(m(w.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}return e=n(e),j(e)?w.type.$normalize(e):_()}function q(){return"{Param:"+e+" "+a+" squash: '"+C+"' optional: "+P+"}"}var w=this;r=l(r),a=c(r,a,s);var A=f();a=A?a.$asArray(A,"search"===s):a,"string"!==a.name||A||"path"!==s||r.value!==n||(r.value="");var P=r.value!==n,C=p(r,P),D=g(r,A,P,C);H(this,{id:e,type:a,location:s,array:A,squash:C,replace:D,isOptional:P,value:$,dynamic:n,config:r,toString:q})},c.prototype={$$new:function(){return a(this,H(new c,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=i(c.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),V(t,function(t){V(i(t),function(t){o(e,t)===-1&&o(a,t)===-1&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return V(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return V(a.$$keys(),function(r){var s=e&&e[r],i=t&&t[r];a[r].type.equals(s,i)||(n=!1)}),n},$$validates:function(e){var a,r,s,i,o,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(C.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=n.indexOf(".")!==-1?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!C[r])return m(r,t.self);for(var s in R)B(R[s])&&(t[s]=R[s](t,R.$delegates[s]));return C[n]=t,!t[S]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){P.$current.navigable==t&&l(e,n)||P.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function g(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=P.$current.name.split("."),a=0,r=t.length;a=C;a--)i=h[a],i.self.onExit&&o.invoke(i.self.onExit,i.self,i.locals.globals),i.locals=null;for(a=C;a<_.length;a++)r=_[a],r.locals=x[a],r.self.onEnter&&o.invoke(r.self.onEnter,r.self,r.locals.globals);return P.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,l.self,d),R):(P.$current=t,P.current=t.self,P.params=n,W(P.params,m),P.transition=null,s.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===s.location}),s.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,l.self,d),v.update(!0),P.current)}).then(null,function(a){return a===D?R:P.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,l.self,d),R):(P.transition=null,i=e.$broadcast("$stateChangeError",t.self,n,l.self,d,a),i.defaultPrevented||v.update(),r.reject(a))});return B},P.is=function(e,t,a){a=H({relative:P.$current},a||{});var r=f(e,a.relative);return j(r)?P.$current===r&&(!t||l(r.params.$$values(t),m)):n},P.includes=function(e,t,a){if(a=H({relative:P.$current},a||{}),N(e)&&g(e)){if(!y(e))return!1;e=P.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(P.$current.includes[r.name]))return!1;if(!t)return!0;for(var s=i(t),o=0;o2?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(l){var r=l&&l(n,e);return{enter:function(e,t,n){r.enter(e,null,t),n()},leave:function(e,t){r.leave(e),t()}}}return a()}var u=i(),l=u("$animator"),c=u("$animate"),d={restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,l){function c(){if(f&&(f.remove(),f=null),h&&(h.$destroy(),h=null),m){var e=m.data("$uiViewAnim");g.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(o){var d,f=D(n,l,i,r),y=f&&e.$current&&e.$current.locals[f];if(o||y!==p){d=n.$new(),p=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=s.defer(),o=s.defer(),u={$animEnter:r.promise,$animLeave:o.promise,$$animLeave:o};e.data("$uiViewAnim",u),g.enter(e,i,function(){r.resolve(),h&&h.$emit("$viewContentAnimationEnded"),(t.isDefined(b)&&!b||n.$eval(b))&&a(e)}),c()});m=_,h=d,h.$emit("$viewContentLoaded",f),h.$eval(v)}}var f,m,h,p,v=l.onload||"",b=l.autoscroll,g=o(l,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}};return d}function C(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(s){var i=s.html();return function(s,o,u){var l=a.$current,c=D(s,u,o,r),d=l&&l.locals[c];if(d){o.data("$uiView",{name:c,state:d.$$state}),o.html(d.$template?d.$template:i);var f=t.extend({},d);s[d.$$resolveAs]=f;var m=e(o.contents());if(d.$$controller){d.$scope=s,d.$element=o;var h=n(d.$$controller,d);d.$$controllerAs&&(s[d.$$controllerAs]=h,s[d.$$controllerAs][d.$$resolveAs]=f),B(h.$onInit)&&h.$onInit(),o.data("$ngControllerController",h),o.children().data("$ngControllerController",h)}m(s)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),s=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(s?s.state.name:"")}function S(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/),!n||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 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(s){var i=s.which||s.button,o=r();if(!(i>1||s.ctrlKey||s.metaKey||s.shiftKey||e.attr("target"))){var u=n(function(){t.go(o.state,o.params,o.options)});s.preventDefault();var l=a.isAnchor&&!o.href?1:0;s.preventDefault=function(){l--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:R(e)||t.$current,inherit:!0}}function k(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,s,i){var o,u=S(s.uiSref,e.current.name),l={state:u.state,href:null,params:null},c=T(r),d=i[1]||i[0],f=null;l.options=H(I(r,e),s.uiSrefOpts?a.$eval(s.uiSrefOpts):{});var m=function(n){n&&(l.params=t.copy(n)),l.href=e.href(u.state,l.params,l.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,l.params)),null!==l.href&&s.$set(c.attr,l.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==l.params&&m(e)},!0),l.params=t.copy(a.$eval(u.paramExpr))),m(),c.clickable&&(o=O(r,e,n,c,function(){return l}),r[r.on?"on":"bind"]("click",o),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",o)}))}}}function x(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,s){function i(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(),l&&(m=l.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var o,u=T(a),l=s[1]||s[0],c=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+c.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,i,!0),i(n.$eval(d)),u.clickable&&(o=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",o),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",o)}))}}}function M(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,s){function i(t,n,r){var s=e.get(t,R(a)),i=o(t,n),u={state:s||{name:t},params:n,hash:i};return p.push(u),v[i]=r,function(){var e=p.indexOf(u);e!==-1&&p.splice(e,1)}}function o(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=i(e,t,h);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 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,V=t.forEach,H=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),b.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",b);var z;g.prototype.concat=function(e,t){var n={caseInsensitive:z.caseInsensitive(),strict:z.strictMode(),squash:z.defaultSquashPolicy()};return new g(this.sourcePath+e+this.sourceSearch,H(n,t),this)},g.prototype.toString=function(){return this.source},g.prototype.exec=function(e,t){function n(e){function t(e){return e.split("").reverse().join("")}function n(e){return e.replace(/\\-/g,"-")}var a=t(e).split(/-(?!\\)/),r=h(a,t);return h(r,n).reverse()}var a=this.regexp.exec(e);if(!a)return null;t=t||{};var r,s,i,o=this.parameters(),u=o.length,l=this.segments.length-1,c={};if(l!==a.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var d,f;for(r=0;r0:null,isRequested:a?y(a):null,isAM:a?g("half_day_am",a,t.date):null,isPM:a?g("half_day_pm",a,t.date):null})})}function T(){return a.all(B.month.days.map(function(e){return a.all(B.contacts.map(function(t){return R(e,t.id)}))}))}function O(t,n,a){var r=!!e.find(n,function(e){return e.index===B.month.index});r?(B.currentPage=0,B.visible=!0,(a||!M)&&A()):B.visible=!1}function I(t){var n=e.find(B.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 k(e,t){var n=q(t);h(null,n),u(null,t)}function x(e){return a.all($(e).map(function(t){return R(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var M=!1,L=[],E={},j={},B=this;B.currentPage=0,B.pageSize=20,B.visible=!1,B.showContactName=!!B.showContactName,B.showOnlyWithLeaveRequests=!!B.showOnlyWithLeaveRequests,B.$onDestroy=S,B.contactsList=f,function(){var e=t().month(B.month.index).year(B.month.year);p(),b(),B.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",month:"<",period:"<",showContactName:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","shared-settings",a]})}),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"],function(e,t,n){function a(n,a,r,s,i,o,u){function l(e){var t=y[e].dialog;v=b.leaveRequest.status_id,r.open({title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return b.leaveRequest[e]().then(function(){m(e)}).catch(function(e){u.error("Error:",e)})}})}function c(){var e=b.absenceTypes[b.leaveRequest.type_id].allow_request_cancelation;return"admin"===b.role||"manager"===b.role||("3"===e?t().isBefore(b.leaveRequest.from_date):"2"===e)}function d(){Array.isArray(b.leaveRequestStatuses)&&(b.leaveRequestStatuses=e.indexBy(b.leaveRequestStatuses,"value")),Array.isArray(b.absenceTypes)&&(b.absenceTypes=e.indexBy(b.absenceTypes,"id"))}function f(e,t,n,a,r){e.stopPropagation(),s.openModal(t,n,a,r)}function m(t){var n=e.find(b.leaveRequestStatuses,function(e){return e.name===o.statusNames.awaitingApproval}).value;v===n&&i.publish("ManagerBadge:: Update Count"),a.$emit("LeaveRequest::"+("delete"===t?"deleted":"edit"),b.leaveRequest)}function h(){var t=b.leaveRequestStatuses[b.leaveRequest.status_id].name,n=e.compact(e.map(y,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!c()&&e.pull(n,"cancel"),"admin"!==b.role&&e.pull(n,"delete"),"staff"===b.role&&e.pull(n,"approve","reject"),"staff"!==b.role&&p(n),b.allowedActions=e.map(n,function(e){return{key:e,label:y[e].label,isDirectAction:y[e].isDirectAction}})}function p(t){e.each(t,function(e,n){"edit"===e&&(t[n]="respond"),"respond"===e&&(t[n]="edit")})}n.debug("Component: leave-request-action-dropdown");var v,b=this,g=o.statusNames,y={edit:{label:"Edit",allowedStatuses:[g.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[g.moreInformationRequired]},view:{label:"View",allowedStatuses:[g.approved,g.rejected,g.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired,g.approved,g.rejected,g.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};b.allowedActions=[],b.action=l,b.openLeavePopup=f,function(){d(),h()}()}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","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,s,i,o){function u(){var t=e.indexBy(f.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){f.comment.contacts=e.indexBy(t.list,"contact_id")})}function l(){return f.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),f.request.comments.length&&u()})}function c(){return f.loading.component=!0,o.get().then(function(e){d=e.contactId}).then(function(){f.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var d=null,f=this;f.loading={component:!0},f.comment={text:"",contacts:{}},function(){l(),c()}(),f.addComment=function(){f.request.comments.push({contact_id:d,leave_request_id:f.request.id,text:f.comment.text}),f.comment.text=""},f.formatDateTime=function(e){return t.utc(e,s.serverDateTimeFormat).local().format(r.DATE_FORMAT.toUpperCase()+" HH:mm")},f.getActiveComments=function(){return f.request.comments.filter(function(e){return!e.toBeDeleted})},f.getCommentorName=function(e){return e===d?"Me":f.comment.contacts[e]?f.comment.contacts[e].display_name:void 0},f.isMode=function(e){return f.mode===e},f.orderComment=function(e){return t(e.created_at,s.serverDateTimeFormat)},f.removeCommentVisibility=function(e){return!e.comment_id||f.canManage}}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"directives/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","HR_settings","shared-settings","Contact","Session",a]})}),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,s,i,o,u,l){function c(){return e.filter(w.request.files,function(e){return e.toBeDeleted})}function d(){return w.fileUploader&&w.fileUploader.queue?w.fileUploader.queue:[]}function f(){$.push(a.$on("LeaveRequestPopup::submit",y))}function m(){v().then(function(){w.fileUploader=u.uploader({entityTable:"civicrm_hrleaveandabsences_leave_request",crmAttachmentToken:i.attachmentToken,queueLimit:i.fileUploader.queueLimit,allowedMimeTypes:q})})}function h(){return _.length>0?_.map(function(e){return e.label}).join(", "):""}function p(){return w.request.loadAttachments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function v(){return r.all(_.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){q[e.label]=t})})).catch(function(){q=null})}function b(){return o.valuesOf("safe_file_extension").then(function(e){_=e})}function g(){e.forEach($,function(e){e()})}function y(e,t){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var _=[],$=[],q={},w=Object.create(this);return w.filesLoaded=!1,w.today=Date.now(),w.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",w.userDateFormat=s.DATE_FORMAT,w.listFileTypes=h,w.$onDestroy=g,w.canUploadMore=function(){return w.getFilesCount()0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function x(e){var t=[y(o.statusNames.moreInformationRequired),y(o.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=x(n)),n.length)return{IN:n}}function L(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=U),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,A(n))}function E(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function j(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function B(){a.$on("LeaveRequest::updatedByManager",function(){F.refresh()}),a.$on("LeaveRequest::new",function(){F.refresh()}),a.$on("LeaveRequest::edit",function(){F.refresh()}),a.$on("LeaveRequest::deleted",function(){F.refresh()})}function N(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,U={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[U],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},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:"me"}},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.clearStaffSelection=f,F.filterLeaveRequestByStatus=h,F.getAbsenceTypesByID=p,F.getArrayOfSize=v,F.getLeaveStatusByValue=b,F.getNavBadge=g,F.getUserNameByID=_,F.labelPeriod=$,F.openLeavePopup=I,F.refresh=L,F.refreshWithFilter=E,F.refreshWithFilterByAssignee=j,F.totalNoOfPages=N,function(){s(o.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([q(),w(),T(),P(),S(),D(),O()]).then(function(){F.loading.page=!1,A()}),B()})}()}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"]}),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,s){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(s.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.defaults(t||{},{is_active:!0})).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(r.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",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/absence-type-api","leave-absences/shared/instances/absence-type.instance"],function(e){"use strict";e.factory("AbsenceType",["$log","Model","AbsenceTypeAPI","AbsenceTypeInstance",function(e,t,n,a){return e.debug("AbsenceType"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return a.init(e,!0)})})},calculateToilExpiryDate:function(e,t,a){return n.calculateToilExpiryDate(e,t,a)},canExpire:function(e){return n.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})}})}])}),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,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,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,r,s){return t.debug("WorkPatternAPI.getCalendar",n,a,r,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{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,s,i){function o(t,n){return l().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,s.serverDateFormat).clone()}function l(){return c=c||i.valuesOf("hrleaveandabsences_work_day_type")}var c;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return o.call(this,e,"non_working_day")},isWeekend:function(e){return o.call(this,e,"weekend")},isWorkingDay:function(e){return o.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,s,i,o){return t.debug("Calendar.get"),a.getCalendar(n,s,i,o).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})}})}])}),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/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance",function(t,n,a,r){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)})})}})}])}),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,s,i){e.debug("LeaveRequestAPI.all");var o=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?o.resolve({list:[],total:0,allIds:[]}):o.resolve(this.getAll("LeaveRequest",t,n,r,s,"getFull",i)),o.promise},balanceChangeByAbsenceType:function(t,n,r,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var o={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",o,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(t){e.debug("LeaveRequestAPI.calculateBalanceChange",t);var n=a.defer();return!t||t.contact_id&&t.from_date&&t.from_date_type||n.reject("contact_id, from_date and from_date_type in params are mandatory"),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){n.resolve(e.values)}),n.promise},create:function(t){e.debug("LeaveRequestAPI.create",t);var n=a.defer();return t&&(t.to_date&&!t.to_date_type?n.reject("to_date_type is mandatory"):t.contact_id&&t.from_date&&t.from_date_type&&t.status_id||n.reject("contact_id, from_date, status_id and from_date_type params are mandatory")),this.sendPOST("LeaveRequest","create",t).then(function(e){n.resolve(e.values[0])}),n.promise},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","get",{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","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI",function(t,n,a,r,s,i){function o(e){return c(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 u(e){return c(e).then(function(e){return this.status_id===e.value}.bind(this))}function l(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function c(e){return a.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return t.find(function(t){return t.name===e})})}function d(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),t.all(n)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},cancel:function(){return o.call(this,r.statusNames.cancelled)},approve:function(){return o.call(this,r.statusNames.approved)},reject:function(){return o.call(this,r.statusNames.rejected)},sendBack:function(){return o.call(this,r.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return t.all([d.call(this),l.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([d.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){return t.comment_id?void(t.toBeDeleted=!0):void(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)},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return u.call(this,r.statusNames.approved)},isAwaitingApproval:function(){return u.call(this,r.statusNames.awaitingApproval)},isCancelled:function(){return u.call(this,r.statusNames.cancelled)},isRejected:function(){return u.call(this,r.statusNames.rejected)},isSentBack:function(){return u.call(this,r.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):n(r.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)):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,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,s,i){return n.all(this.processFilters(e),t,r,s,i).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)},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange"),n.calculateBalanceChange(t)},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,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 r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(s.serverDateFormat),i={date:r};return a.all(i).then(function(e){return!!e.length})}})}])}),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/calendar-model","leave-absences/shared/models/entitlement-model","leave-absences/shared/models/leave-request-model","leave-absences/shared/models/public-holiday-model"],function(e,t,n,a){"use strict";function r(t,r,s,i,o,u,l,c,d,f,m,h,p,v,b,g,y){function _(){var e=this.requestStatuses[y.statusNames.awaitingApproval].value;je.status_id===e&&e!==this.request.status_id&&f.publish("ManagerBadge:: Update Count")}function $(){var e=this;return e._setDateAndTypes(),q.call(e)?(e.loading.showBalanceChange=!0,b.calculateBalanceChange(M.call(e)).then(function(t){t&&(e.balance.change=t,e._calculateOpeningAndClosingBalance(),ce.call(e)),e.loading.showBalanceChange=!1}).catch(B.bind(e))):r.resolve()}function q(){return!!(this.request.from_date&&this.request.to_date&&this.request.from_date_type&&this.request.to_date_type)}function w(){var e=q.call(this);return this.isMode("edit")&&(e=e&&N.call(this)),this.canManage&&this.requestStatuses&&(e=e&&!!this.getStatusFromValue(this.newStatusOnSave)),e=e&&!!this.period.id,e&&!this.isMode("view")}function A(){this._reset(),this._calculateOpeningAndClosingBalance()}function P(){this.isSelfRecord?this.request.status_id=this.requestStatuses[y.statusNames.awaitingApproval].value:this.canManage&&(this.request.status_id=this.newStatusOnSave||this.request.status_id)}function C(){this.errors=[]}function D(){return this.request.create().then(be).then(function(){le.call(this,"LeaveRequest::new")}.bind(this))}function S(){o.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return this.directiveOptions.leaveRequest.delete().then(function(){this.dismissModal(),s.$emit("LeaveRequest::deleted",this.directiveOptions.leaveRequest)}.bind(this))}.bind(this)})}function R(){this.$modalInstance.dismiss({$value:"cancel"})}function T(e,t){var a;return e?(a=this.requestDayTypes.slice(0),e=this._convertDateToServerFormat(e),g.isPublicHoliday(e).then(function(t){return t?a.filter(function(e){return"public_holiday"===e.name}):x.call(this,e,a).then(function(e){return e.length?e:a.filter(function(e){return n.includes(["all_day","half_day_am","half_day_pm"],e.name)})})}.bind(this)).then(function(e){return me.call(this,t,e),e}.bind(this))):r.reject([])}function O(e){return a(e,y.serverDateTimeFormat).format(this.uiOptions.userDateFormat.toUpperCase()+" HH:mm")}function I(){var e=this.getStatusFromValue(this.request.status_id);return k.call(this,e.name)}function k(e){return n.map(Le[e],function(e){return this.requestStatuses[e]}.bind(this))}function x(e,t){return e=a(e),r.all([this.calendar.isNonWorkingDay(e),this.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(t){return t.name===e}):[]})}function M(){return n.pick(this.request,["contact_id","from_date","from_date_type","to_date","to_date_type"])}function L(){return n.find(this.absenceTypes,function(e){return e.id===this.request.type_id}.bind(this))}function E(){return!this.request||e.equals({},this.requestStatuses)?[]:this.request.status_id?I.call(this):k.call(this,"none")}function j(e){return n.find(this.requestStatuses,function(t){return t.value===e})}function B(e){this.errors=n.isArray(e)?e:[e],this.loading.showBalanceChange=!1,this.loading.absenceTypes=!1,this.loading.fromDayTypes=!1,this.loading.toDayTypes=!1,this.submitting=!1}function N(){return!e.equals(je,this.request.attributes())||this.fileUploader&&0!==this.fileUploader.queue.length||this.canManage&&this.newStatusOnSave}function F(){this.period=n.find(this.absencePeriods,function(e){return e.current})}function U(){var e=this;return e.postContactSelection=!0,e.request.contact_id?r.all([e._loadAbsenceTypes(),e._loadCalendar()]).then(function(){return ne.call(e)}).then(function(){return W.call(e)}).then(function(){return he.call(e),K.call(e),H.call(e),e.isMode("edit")&&pe.call(e),e.postContactSelection=!1,e.calculateBalanceChange()}).catch(function(e){if(e!==Ve)return r.reject(e)}):r.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Le.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Le.awaiting_approval=e,Le.more_information_required=e,Le.rejected=e,Le.approved=e,Le.cancelled=[y.statusNames.awaitingApproval].concat(e)}function H(){return this.canManage?i.find(this.request.contact_id).then(function(e){this.contactName=e.display_name}.bind(this)):r.resolve()}function W(){if(this.isMode("create"))return r.resolve();var e=this.request.attributes();return this.uiOptions.fromDate=this._convertDateFormatFromServer(this.request.from_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.fromDate,"from").then(function(){return this.request.to_date=e.to_date,this.request.to_date_type=e.to_date_type,this.uiOptions.toDate=this._convertDateFormatFromServer(this.request.to_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.toDate,"to")}.bind(this))}function G(){Be.push(s.$on("LeaveRequestPopup::requestObjectUpdated",pe.bind(this)),s.$on("LeaveRequestPopup::childComponent::register",function(){Ee++}))}function z(){if(this.request.id){this.mode="edit";var e=[this.requestStatuses[y.statusNames.approved].value,this.requestStatuses[y.statusNames.adminApproved].value,this.requestStatuses[y.statusNames.rejected].value,this.requestStatuses[y.statusNames.cancelled].value];this.isRole("staff")&&e.indexOf(this.request.status_id)>-1&&(this.mode="view")}else this.mode="create"}function Y(){return Fe="staff",d(y.permissions.admin.administer).then(function(e){Fe=e?"admin":Fe}).then(function(){return"staff"===Fe&&d(y.permissions.ssp.manage).then(function(e){Fe=e?"manager":Fe})}).finally(function(){this.canManage=this.isRole("manager")||this.isRole("admin"),this.isSelfRecord=this.directiveOptions.isSelfRecord}.bind(this))}function K(){(this.isRole("admin")||this.isMode("create")&&this.isRole("manager"))&&(this.newStatusOnSave=this.requestStatuses[y.statusNames.approved].value)}function J(e){var t=this.getStatusFromValue(this.request.status_id);return!!t&&t.name===e}function X(e){return this.request.request_type===e}function Z(e){return this.mode===e}function Q(e){return Fe===e}function ee(e,t){var n=this.period.id;return t=t||"from",this.loading[t+"DayTypes"]=!0,this._checkAndSetAbsencePeriod(e).then(function(){var e=n===this.period.id;if(!e)return this.uiOptions.multipleDays&&"from"===t&&(this.uiOptions.showBalance=!1,this.uiOptions.toDate=null,this.request.to_date=null,this.request.to_date_type=null),r.all([this._loadAbsenceTypes(),this._loadCalendar()])}.bind(this)).then(function(){return this._setMinMaxDate(),T.call(this,e,t)}.bind(this)).finally(function(){this.loading[t+"DayTypes"]=!1}.bind(this))}function te(){var e=this;return u.all().then(function(t){e.absencePeriods=t})}function ne(){var e=this;return c.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(t){e.requestDayTypes=t})}function ae(){return v.get().then(function(e){Ne=e.contactId})}function re(){return this.directiveOptions.selectedContactId?i.find(this.directiveOptions.selectedContactId).then(function(e){this.managedContacts=[e]}.bind(this)):this.isRole("admin")?i.all().then(function(e){this.managedContacts=n.remove(e.list,function(e){return e.id!==Ne})}.bind(this)):i.find(Ne).then(function(e){return e.leaveManagees()}).then(function(e){this.managedContacts=e}.bind(this))}function se(){var e=this;return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){e.requestStatuses=n.indexBy(t,"name")})}function ie(e,t){return t.map(function(t){var a=n.find(e,function(e){return e.id===t.type_id});return{id:t.type_id,title:a.title+" ( "+t.remainder.current+" ) ",remainder:t.remainder.current,allow_overuse:a.allow_overuse}})}function oe(){this.$modalInstance.close({$value:this.request})}function ue(){var e=(this.currentPage-1)*this.numPerPage,t=e+this.numPerPage;this.filteredbreakdown=Ue.balance.change.breakdown.slice(e,t)}function le(e){_.call(this),s.$emit(e,this.request),this.errors=[],this.ok()}function ce(){this.pagination.totalItems=this.balance.change.breakdown.length,this.pagination.filteredbreakdown=this.balance.change.breakdown,this.pagination.pageChanged()}function de(e){var t=this;return h.all({contact_id:t.request.contact_id,period_id:t.period.id,type_id:{IN:e.ids}},!0).then(function(n){if(t.absenceTypes=ie(e.types,n),!t.absenceTypes.length)return r.reject(Ve)})}function fe(){(this.isMode("edit")&&this.request.from_date===this.request.to_date||this.isMode("create")&&this.isLeaveType("sickness"))&&(this.uiOptions.multipleDays=!1)}function me(e,t){var a="request"+n.startCase(e)+"DayTypes";this[a]=t,this.isMode("create")&&(this.request[e+"_date_type"]=this[a][0].value)}function he(){this.isMode("create")?(this.selectedAbsenceType=this.absenceTypes[0],this.request.type_id=this.selectedAbsenceType.id):this.selectedAbsenceType=L.call(this)}function pe(){je=e.copy(this.request.attributes())}function ve(){var e=this.request.status_id;if(!this.isMode("view")&&!this.submitting)return this.submitting=!0, -P.call(this),qe.call(this).then(function(){return this.isMode("edit")?$e.call(this):D.call(this)}.bind(this)).catch(function(t){this.request.status_id=e,t&&B.call(this,t)}.bind(this)).finally(function(){this.submitting=!1}.bind(this))}function be(){function e(e){e&&n.push(e),++a===Ee&&(ge(),n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Ee>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function ge(){n.forEach(Be,function(e){e()})}function ye(e,t){return this.loadAbsencePeriodDatesTypes(e,t).then(function(){return this.updateBalance()}.bind(this)).catch(function(e){B.call(this,e),this._setDateAndTypes()}.bind(this))}function _e(){this.selectedAbsenceType=L.call(this),this.balance.opening=this.selectedAbsenceType.remainder,this.calculateBalanceChange()}function $e(){return this.request.update().then(be).then(function(){this.isRole("manager")?le.call(this,"LeaveRequest::updatedByManager"):(this.isRole("staff")||this.isRole("admin"))&&le.call(this,"LeaveRequest::edit")}.bind(this))}function qe(){return this.balance.closing<0&&"0"===this.selectedAbsenceType.allow_overuse?r.reject(["You cannot make a request for this leave type at this time as this would leave you with a negative balance"]):this.request.isValid()}function we(){this.balance.opening=this.selectedAbsenceType.remainder,this.balance.closing=this.balance.opening+this.balance.change.amount}function Ae(e){var t=a(e).format(this.uiOptions.userDateFormat.toUpperCase());return this.period=n.find(this.absencePeriods,function(e){return e.isInPeriod(t)}),this.period?r.resolve(!0):(this.period={},this.loading.fromDayTypes=!1,r.reject("Please change date as it is not in any absence period"))}function Pe(e){return a(e,y.serverDateFormat).toDate()}function Ce(e){return a(e).format(y.serverDateFormat)}function De(){return V.call(this),G.call(this),ae.call(this).then(Y.bind(this)).then(this._initRequest.bind(this)).then(se.bind(this)).then(function(){return z.call(this),this.canManage&&!this.isMode("edit")&&re.call(this)}.bind(this)).then(te.bind(this)).then(function(){F.call(this),this._setMinMaxDate()}.bind(this)).then(function(){if(this.directiveOptions.selectedContactId&&(this.request.contact_id=this.directiveOptions.selectedContactId),fe.call(this),this.request.contact_id)return this.initAfterContactSelection()}.bind(this)).catch(B.bind(this))}function Se(){var e={};return this.directiveOptions.leaveRequest?e=this.directiveOptions.leaveRequest.attributes():this.canManage||(e={contact_id:Ne}),e}function Re(){var e=this;return l.all(e.initParams.absenceType).then(function(t){var n=t.map(function(e){return e.id});return Me={types:t,ids:n},de.call(e,Me)})}function Te(){var e=this;return m.get(e.request.contact_id,e.period.start_date,e.period.end_date).then(function(t){e.calendar=t})}function Oe(){this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date_type=this.request.from_date_type,this.request.to_date=this.request.from_date,this.calculateBalanceChange()}function Ie(){this._setDates(),this.uiOptions.multipleDays?this.uiOptions.showBalance=!!(this.request.from_date&&this.request.from_date_type&&this.request.to_date&&this.request.to_date_type&&this.period.id):(this.uiOptions.fromDate&&(this.request.to_date_type=this.request.from_date_type),this.uiOptions.showBalance=!!this.request.from_date&&!!this.request.from_date_type&&!!this.period.id)}function ke(){this.request.from_date=this.uiOptions.fromDate?this._convertDateToServerFormat(this.uiOptions.fromDate):null,this.request.to_date=this.uiOptions.toDate?this._convertDateToServerFormat(this.uiOptions.toDate):null,!this.uiOptions.multipleDays&&this.uiOptions.fromDate&&(this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date=this.request.from_date)}function xe(){if(this.uiOptions.fromDate){var e=a(this.uiOptions.fromDate).add(1,"d").toDate();this.uiOptions.date.to.options.minDate=e,this.uiOptions.date.to.options.initDate=e,this.uiOptions.toDate&&a(this.uiOptions.toDate).isBefore(this.uiOptions.fromDate)&&(this.uiOptions.toDate=this.uiOptions.fromDate)}else this.uiOptions.date.to.options.minDate=this._convertDateFormatFromServer(this.period.start_date),this.uiOptions.date.to.options.initDate=this.uiOptions.date.to.options.minDate;this.uiOptions.date.to.options.maxDate=this._convertDateFormatFromServer(this.period.end_date)}t.debug("RequestCtrl");var Me,Le={},Ee=0,je={},Be=[],Ne="",Fe="",Ue=this,Ve="No entitlement";this.absencePeriods=[],this.absenceTypes=[],this.calendar={},this.canManage=!1,this.contactName=null,this.errors=[],this.fileUploader=null,this.isSelfRecord=!1,this.managedContacts=[],this.mode="",this.newStatusOnSave=null,this.period={},this.postContactSelection=!1,this.requestDayTypes=[],this.requestStatuses={},this.selectedAbsenceType={},this.statusNames=y.statusNames,this.submitting=!1,this.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},this.loading={absenceTypes:!0,showBalanceChange:!1,fromDayTypes:!1,toDayTypes:!1},this.pagination={currentPage:1,filteredbreakdown:this.balance.change.breakdown,numPerPage:7,totalItems:this.balance.change.breakdown.length,pageChanged:ue},this.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:p.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}}}},this.changeInNoOfDays=A,this.calculateBalanceChange=$,this.canSubmit=w,this.closeAlert=C,this.deleteLeaveRequest=S,this.dismissModal=R,this.formatDateTime=O,this.getStatuses=E,this.getStatusFromValue=j,this.initAfterContactSelection=U,this.isLeaveStatus=J,this.isLeaveType=X,this.isMode=Z,this.isRole=Q,this.ok=oe,this.submit=ve,this.loadAbsencePeriodDatesTypes=ee,this.updateAbsencePeriodDatesTypes=ye,this.updateBalance=_e,this._calculateOpeningAndClosingBalance=we,this._checkAndSetAbsencePeriod=Ae,this._convertDateToServerFormat=Ce,this._convertDateFormatFromServer=Pe,this._init=De,this._initRequestAttributes=Se,this._loadCalendar=Te,this._loadAbsenceTypes=Re,this._reset=Oe,this._setDates=ke,this._setDateAndTypes=Ie,this._setMinMaxDate=xe}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","Contact","dialog","AbsencePeriod","AbsenceType","api.optionGroup","checkPermissions","pubSub","Calendar","Entitlement","HR_settings","Session","LeaveRequest","PublicHoliday","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/leave-request.controller",["leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/leave-request.instance"],function(e){function t(e,t,n,a,r){function s(){var e=o._initRequestAttributes();o.request=r.init(e)}t.debug("LeaveRequestCtrl");var i=e("RequestCtrl"),o=Object.create(i);return o.directiveOptions=a,o.$modalInstance=n,o.initParams={absenceType:{is_sick:!1}},o._initRequest=s,function(){o.loading.absenceTypes=!0,o._init().finally(function(){o.loading.absenceTypes=!1})}(),o}e.controller("LeaveRequestCtrl",t),t.$inject=["$controller","$log","$uibModalInstance","directiveOptions","LeaveRequestInstance"]}),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(){var e=this.sickness_required_documents?this.sickness_required_documents.split(","):[];return e},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/controllers/sub-controllers/sick-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/sickness-request.instance"],function(e,t){function n(t,n,a,r,s,i,o){function u(){return h.canSubmit.call(this)&&!!p.request.sickness_reason}function l(t){var n=p.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(p.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){p.sicknessDocumentTypes=e})}function f(){return s.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){p.sicknessReasons=e.indexBy(t,"name")})}function m(){var e=p._initRequestAttributes();p.request=o.init(e)}n.debug("SicknessRequestCtrl");var h=t("RequestCtrl"),p=Object.create(h);return p.directiveOptions=i,p.$modalInstance=r,p.initParams={absenceType:{is_sick:!0}},p.canSubmit=u,p.isChecked=l,p.isDocumentInRequest=c,p._initRequest=m,function(){p.loading.absenceTypes=!0,p._init().then(function(){return a.all([d(),f()])}).finally(function(){p.loading.absenceTypes=!1})}(),p}t.controller("SicknessRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","directiveOptions","SicknessRequestInstance"]}),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/sub-controllers/toil-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/toil-request.instance"],function(e,t){function n(t,n,a,r,s,i,o,u){function l(){P.request.toil_to_accrue&&(P.loading.showBalanceChange=!0,P._setDateAndTypes(),P.balance.change.amount=+P.request.toil_to_accrue,P._calculateOpeningAndClosingBalance(),P.uiOptions.showBalance=!0,P.request.to_date_type=P.request.from_date_type="1",P.loading.showBalanceChange=!1)}function c(){return!P.canManage&&P.request.id?a.resolve(P.request.toil_expiry_date):P.requestCanExpire?p().catch(function(e){return e.length&&(P.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(P.request.type_id,e)}).then(function(e){return P.request.toil_expiry_date=e,P.uiOptions.expiryDate=new Date(e),e}):(P.request.toil_expiry_date=!1,a.resolve(!1))}function d(){return P.uiOptions.multipleDays&&P.request.to_date||!P.uiOptions.multipleDays&&P.request.from_date}function f(){return A.canSubmit.call(this)&&!!P.request.toil_duration&&!!P.request.toil_to_accrue&&!!P.request.from_date&&!!P.request.to_date}function m(){A.changeInNoOfDays.call(this),d()&&P.calculateToilExpiryDate()}function h(){P.request.toil_expiry_date=!1,P.uiOptions.expiryDate=null}function p(){return v(P.uiOptions.multipleDays?{hasErrors:!P.request.to_date&&!P.request.from_date,label:"To Date",value:P.request.to_date}:{hasErrors:!P.request.from_date,label:"From Date",value:P.request.from_date})}function v(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(e.value):a.reject([])}function b(){P.canManage&&(P.uiOptions.expiryDate=P._convertDateFormatFromServer(P.request.toil_expiry_date))}function g(){return i.canExpire(P.request.type_id).then(function(e){P.requestCanExpire=e})}function y(e){var t=P.period.id;return P._checkAndSetAbsencePeriod(e).then(function(){var e=t===P.period.id;if(!e)return P.uiOptions.multipleDays&&(P.uiOptions.showBalance=!1,P.uiOptions.toDate=null,P.request.to_date=null),a.all([P._loadAbsenceTypes(),P._loadCalendar()])})}function _(){return s.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){P.toilAmounts=e.indexBy(t,"value")})}function $(e){return P.loadAbsencePeriodDatesTypes().then(function(){P._setMinMaxDate(),P._setDates(),P.updateBalance(),P.calculateToilExpiryDate()}).catch(function(e){P.errors=[e]})}function q(){P.uiOptions.expiryDate&&(P.request.toil_expiry_date=P._convertDateToServerFormat(P.uiOptions.expiryDate))}function w(){var e=P._initRequestAttributes();P.request=u.init(e),P.request.to_date_type=P.request.from_date_type="1"}n.debug("ToilRequestCtrl");var A=t("RequestCtrl"),P=Object.create(A);return P.requestCanExpire=!0,P.directiveOptions=o,P.$modalInstance=r,P.initParams={absenceType:{allow_accruals_request:!0}},P.calculateBalanceChange=l,P.calculateToilExpiryDate=c,P.canSubmit=f,P.changeInNoOfDays=m,P.clearExpiryDate=h,P.loadAbsencePeriodDatesTypes=y,P.updateAbsencePeriodDatesTypes=$,P.updateExpiryDate=q,P._initRequest=w,function(){P.loading.absenceTypes=!0,P._init().then(function(){return g()}).then(function(){return b(),_()}).finally(function(){P.loading.absenceTypes=!1})}(),P}t.controller("ToilRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","AbsenceType","directiveOptions","TOILRequestInstance"]}),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-popup.service",["common/lodash","leave-absences/shared/modules/services","common/services/notification.service"],function(e,t){"use strict";function n(t,n,a,r,s,i,o,u,l,c){function d(e){return l.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function f(e,t){return t?t.request_type:e||null}function m(t,a,r,i){var u=e.capitalize(f(a,t))+"RequestCtrl";s.open({appendTo:n.children().eq(0),templateUrl:o.sharedPathTpl+"directives/leave-request-popup/leave-request-popup.html",controller:u,controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveRequest:t,selectedContactId:r,isSelfRecord:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function h(e){return c.find(e).then(function(e){return d(e).then(function(t){t?m(e,e.request_type,e.contact_id,"my-leave"===a.section):i.error("Error","You dont have permission to see this leave request")})}).catch(function(e){i.error("Error",e)})}return t.debug("LeavePopup"),{openModal:m,openModalByID:h}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$q","$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,s){r.debugEnabled(s.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:''}).state("calendar",{url:"/calendar",template:''}).state("balance-report",{url:"/balance-report",template:""})}])}),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/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-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/leave-request.controller","leave-absences/shared/controllers/sub-controllers/sick-request.controller","leave-absences/shared/controllers/sub-controllers/toil-request.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.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(){}); \ No newline at end of file +if(U(n)&&0===n.length)return n;n=r(n);var a=h(n,e);return t===!0?0===m(a,i).length:s(a)}}function u(e){return function(t,n){var a=r(t),s=r(n);if(a.length!==s.length)return!1;for(var i=0;i0:null,isRequested:a?y(a):null,isAM:a?g("half_day_am",a,t.date):null,isPM:a?g("half_day_pm",a,t.date):null})})}function T(){return a.all(B.month.days.map(function(e){return a.all(B.contacts.map(function(t){return R(e,t.id)}))}))}function O(t,n,a){var r=!!e.find(n,function(e){return e.index===B.month.index});r?(B.currentPage=0,B.visible=!0,(a||!M)&&A()):B.visible=!1}function I(t){var n=e.find(B.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 k(e,t){var n=q(t);h(null,n),u(null,t)}function x(e){return a.all($(e).map(function(t){return R(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var M=!1,L=[],E={},j={},B=this;B.currentPage=0,B.pageSize=20,B.visible=!1,B.showContactName=!!B.showContactName,B.showOnlyWithLeaveRequests=!!B.showOnlyWithLeaveRequests,B.$onDestroy=S,B.contactsList=f,function(){var e=t().month(B.month.index).year(B.month.year);p(),b(),B.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",month:"<",period:"<",showContactName:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","shared-settings",a]})}),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"],function(e,t,n){function a(n,a,r,s,i,o,u){function l(e){var t=y[e].dialog;v=b.leaveRequest.status_id,r.open({title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return b.leaveRequest[e]().then(function(){m(e)}).catch(function(e){u.error("Error:",e)})}})}function c(){var e=b.absenceTypes[b.leaveRequest.type_id].allow_request_cancelation;return"admin"===b.role||"manager"===b.role||("3"===e?t().isBefore(b.leaveRequest.from_date):"2"===e)}function d(){Array.isArray(b.leaveRequestStatuses)&&(b.leaveRequestStatuses=e.indexBy(b.leaveRequestStatuses,"value")),Array.isArray(b.absenceTypes)&&(b.absenceTypes=e.indexBy(b.absenceTypes,"id"))}function f(e,t,n,a,r){e.stopPropagation(),s.openModal(t,n,a,r)}function m(t){var n=e.find(b.leaveRequestStatuses,function(e){return e.name===o.statusNames.awaitingApproval}).value;v===n&&i.publish("ManagerBadge:: Update Count"),a.$emit("LeaveRequest::"+("delete"===t?"deleted":"edit"),b.leaveRequest)}function h(){var t=b.leaveRequestStatuses[b.leaveRequest.status_id].name,n=e.compact(e.map(y,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!c()&&e.pull(n,"cancel"),"admin"!==b.role&&e.pull(n,"delete"),"staff"===b.role&&e.pull(n,"approve","reject"),"staff"!==b.role&&p(n),b.allowedActions=e.map(n,function(e){return{key:e,label:y[e].label,isDirectAction:y[e].isDirectAction}})}function p(t){e.each(t,function(e,n){"edit"===e&&(t[n]="respond"),"respond"===e&&(t[n]="edit")})}n.debug("Component: leave-request-action-dropdown");var v,b=this,g=o.statusNames,y={edit:{label:"Edit",allowedStatuses:[g.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[g.moreInformationRequired]},view:{label:"View",allowedStatuses:[g.approved,g.rejected,g.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired,g.approved,g.rejected,g.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};b.allowedActions=[],b.action=l,b.openLeavePopup=f,function(){d(),h()}()}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","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,s,i,o){function u(){var t=e.indexBy(f.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){f.comment.contacts=e.indexBy(t.list,"contact_id")})}function l(){return f.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),f.request.comments.length&&u()})}function c(){return f.loading.component=!0,o.get().then(function(e){d=e.contactId}).then(function(){f.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var d=null,f=this;f.loading={component:!0},f.comment={text:"",contacts:{}},function(){l(),c()}(),f.addComment=function(){f.request.comments.push({contact_id:d,leave_request_id:f.request.id,text:f.comment.text}),f.comment.text=""},f.formatDateTime=function(e){return t.utc(e,s.serverDateTimeFormat).local().format(r.DATE_FORMAT.toUpperCase()+" HH:mm")},f.getActiveComments=function(){return f.request.comments.filter(function(e){return!e.toBeDeleted})},f.getCommentorName=function(e){return e===d?"Me":f.comment.contacts[e]?f.comment.contacts[e].display_name:void 0},f.isMode=function(e){return f.mode===e},f.orderComment=function(e){return t(e.created_at,s.serverDateTimeFormat)},f.removeCommentVisibility=function(e){return!e.comment_id||f.canManage}}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"directives/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","HR_settings","shared-settings","Contact","Session",a]})}),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,s,i,o,u,l){function c(){return e.filter(w.request.files,function(e){return e.toBeDeleted})}function d(){return w.fileUploader&&w.fileUploader.queue?w.fileUploader.queue:[]}function f(){$.push(a.$on("LeaveRequestPopup::submit",y))}function m(){v().then(function(){w.fileUploader=u.uploader({entityTable:"civicrm_hrleaveandabsences_leave_request",crmAttachmentToken:i.attachmentToken,queueLimit:i.fileUploader.queueLimit,allowedMimeTypes:q})})}function h(){return _.length>0?_.map(function(e){return e.label}).join(", "):""}function p(){return w.request.loadAttachments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function v(){return r.all(_.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){q[e.label]=t})})).catch(function(){q=null})}function b(){return o.valuesOf("safe_file_extension").then(function(e){_=e})}function g(){e.forEach($,function(e){e()})}function y(e,t){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var _=[],$=[],q={},w=Object.create(this);return w.filesLoaded=!1,w.today=Date.now(),w.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",w.userDateFormat=s.DATE_FORMAT,w.listFileTypes=h,w.$onDestroy=g,w.canUploadMore=function(){return w.getFilesCount()0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function x(e){var t=[y(o.statusNames.moreInformationRequired),y(o.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=x(n)),n.length)return{IN:n}}function L(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=U),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,A(n))}function E(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function j(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function B(){a.$on("LeaveRequest::updatedByManager",function(){F.refresh()}),a.$on("LeaveRequest::new",function(){F.refresh()}),a.$on("LeaveRequest::edit",function(){F.refresh()}),a.$on("LeaveRequest::deleted",function(){F.refresh()})}function N(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,U={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[U],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},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:"me"}},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.clearStaffSelection=f,F.filterLeaveRequestByStatus=h,F.getAbsenceTypesByID=p,F.getArrayOfSize=v,F.getLeaveStatusByValue=b,F.getNavBadge=g,F.getUserNameByID=_,F.labelPeriod=$,F.openLeavePopup=I,F.refresh=L,F.refreshWithFilter=E,F.refreshWithFilterByAssignee=j,F.totalNoOfPages=N,function(){s(o.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([q(),w(),T(),P(),S(),D(),O()]).then(function(){F.loading.page=!1,A()}),B()})}()}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"]}),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,s){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(s.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.defaults(t||{},{is_active:!0})).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(r.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",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/absence-type-api","leave-absences/shared/instances/absence-type.instance"],function(e){"use strict";e.factory("AbsenceType",["$log","Model","AbsenceTypeAPI","AbsenceTypeInstance",function(e,t,n,a){return e.debug("AbsenceType"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return a.init(e,!0)})})},calculateToilExpiryDate:function(e,t,a){return n.calculateToilExpiryDate(e,t,a)},canExpire:function(e){return n.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})}})}])}),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,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,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,r,s){return t.debug("WorkPatternAPI.getCalendar",n,a,r,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{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,s,i){function o(t,n){return l().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,s.serverDateFormat).clone()}function l(){return c=c||i.valuesOf("hrleaveandabsences_work_day_type")}var c;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return o.call(this,e,"non_working_day")},isWeekend:function(e){return o.call(this,e,"weekend")},isWorkingDay:function(e){return o.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,s,i,o){return t.debug("Calendar.get"),a.getCalendar(n,s,i,o).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})}})}])}),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/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance",function(t,n,a,r){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)})})}})}])}),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,s,i){e.debug("LeaveRequestAPI.all");var o=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?o.resolve({list:[],total:0,allIds:[]}):o.resolve(this.getAll("LeaveRequest",t,n,r,s,"getFull",i)),o.promise},balanceChangeByAbsenceType:function(t,n,r,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var o={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",o,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(t){e.debug("LeaveRequestAPI.calculateBalanceChange",t);var n=a.defer();return!t||t.contact_id&&t.from_date&&t.from_date_type||n.reject("contact_id, from_date and from_date_type in params are mandatory"),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){n.resolve(e.values)}),n.promise},create:function(t){e.debug("LeaveRequestAPI.create",t);var n=a.defer();return t&&(t.to_date&&!t.to_date_type?n.reject("to_date_type is mandatory"):t.contact_id&&t.from_date&&t.from_date_type&&t.status_id||n.reject("contact_id, from_date, status_id and from_date_type params are mandatory")),this.sendPOST("LeaveRequest","create",t).then(function(e){n.resolve(e.values[0])}),n.promise},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","get",{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","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI",function(t,n,a,r,s,i){function o(e){return c(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 u(e){return c(e).then(function(e){return this.status_id===e.value}.bind(this))}function l(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function c(e){return a.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return t.find(function(t){return t.name===e})})}function d(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),t.all(n)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},cancel:function(){return o.call(this,r.statusNames.cancelled)},approve:function(){return o.call(this,r.statusNames.approved)},reject:function(){return o.call(this,r.statusNames.rejected)},sendBack:function(){return o.call(this,r.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return t.all([d.call(this),l.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([d.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){return t.comment_id?void(t.toBeDeleted=!0):void(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)},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return u.call(this,r.statusNames.approved)},isAwaitingApproval:function(){return u.call(this,r.statusNames.awaitingApproval)},isCancelled:function(){return u.call(this,r.statusNames.cancelled)},isRejected:function(){return u.call(this,r.statusNames.rejected)},isSentBack:function(){return u.call(this,r.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):n(r.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)):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,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,s,i){return n.all(this.processFilters(e),t,r,s,i).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)},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange"),n.calculateBalanceChange(t)},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,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 r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(s.serverDateFormat),i={date:r};return a.all(i).then(function(e){return!!e.length})}})}])}),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/calendar-model","leave-absences/shared/models/entitlement-model","leave-absences/shared/models/leave-request-model","leave-absences/shared/models/public-holiday-model"],function(e,t,n,a){"use strict";function r(t,r,s,i,o,u,l,c,d,f,m,h,p,v,b,g,y){function _(){var e=this.requestStatuses[y.statusNames.awaitingApproval].value;je.status_id===e&&e!==this.request.status_id&&f.publish("ManagerBadge:: Update Count")}function $(){var e=this;return e._setDateAndTypes(),q.call(e)?(e.loading.showBalanceChange=!0,b.calculateBalanceChange(M.call(e)).then(function(t){t&&(e.balance.change=t,e._calculateOpeningAndClosingBalance(),ce.call(e)),e.loading.showBalanceChange=!1}).catch(B.bind(e))):r.resolve()}function q(){return!!(this.request.from_date&&this.request.to_date&&this.request.from_date_type&&this.request.to_date_type)}function w(){var e=q.call(this);return this.isMode("edit")&&(e=e&&N.call(this)),this.canManage&&this.requestStatuses&&(e=e&&!!this.getStatusFromValue(this.newStatusOnSave)),e=e&&!!this.period.id,e&&!this.isMode("view")}function A(){this._reset(),this._calculateOpeningAndClosingBalance()}function P(){this.isSelfRecord?this.request.status_id=this.requestStatuses[y.statusNames.awaitingApproval].value:this.canManage&&(this.request.status_id=this.newStatusOnSave||this.request.status_id)}function C(){this.errors=[]}function D(){return this.request.create().then(be).then(function(){le.call(this,"LeaveRequest::new")}.bind(this))}function S(){o.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return this.directiveOptions.leaveRequest.delete().then(function(){this.dismissModal(),s.$emit("LeaveRequest::deleted",this.directiveOptions.leaveRequest)}.bind(this))}.bind(this)})}function R(){this.$modalInstance.dismiss({$value:"cancel"})}function T(e,t){var a;return e?(a=this.requestDayTypes.slice(0),e=this._convertDateToServerFormat(e),g.isPublicHoliday(e).then(function(t){return t?a.filter(function(e){return"public_holiday"===e.name}):x.call(this,e,a).then(function(e){return e.length?e:a.filter(function(e){return n.includes(["all_day","half_day_am","half_day_pm"],e.name)})})}.bind(this)).then(function(e){return me.call(this,t,e),e}.bind(this))):r.reject([])}function O(e){return a(e,y.serverDateTimeFormat).format(this.uiOptions.userDateFormat.toUpperCase()+" HH:mm")}function I(){var e=this.getStatusFromValue(this.request.status_id);return k.call(this,e.name)}function k(e){return n.map(Le[e],function(e){return this.requestStatuses[e]}.bind(this))}function x(e,t){return e=a(e),r.all([this.calendar.isNonWorkingDay(e),this.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(t){return t.name===e}):[]})}function M(){return n.pick(this.request,["contact_id","from_date","from_date_type","to_date","to_date_type"])}function L(){return n.find(this.absenceTypes,function(e){return e.id===this.request.type_id}.bind(this))}function E(){return!this.request||e.equals({},this.requestStatuses)?[]:this.request.status_id?I.call(this):k.call(this,"none")}function j(e){return n.find(this.requestStatuses,function(t){return t.value===e})}function B(e){this.errors=n.isArray(e)?e:[e],this.loading.showBalanceChange=!1,this.loading.absenceTypes=!1,this.loading.fromDayTypes=!1,this.loading.toDayTypes=!1,this.submitting=!1}function N(){return!e.equals(je,this.request.attributes())||this.fileUploader&&0!==this.fileUploader.queue.length||this.canManage&&this.newStatusOnSave}function F(){this.period=n.find(this.absencePeriods,function(e){return e.current})}function U(){var e=this;return e.postContactSelection=!0,e.request.contact_id?r.all([e._loadAbsenceTypes(),e._loadCalendar()]).then(function(){return ne.call(e)}).then(function(){return W.call(e)}).then(function(){return he.call(e),K.call(e),H.call(e),e.isMode("edit")&&pe.call(e),e.postContactSelection=!1,e.calculateBalanceChange()}).catch(function(e){if(e!==Ve)return r.reject(e)}):r.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Le.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Le.awaiting_approval=e,Le.more_information_required=e,Le.rejected=e,Le.approved=e,Le.cancelled=[y.statusNames.awaitingApproval].concat(e)}function H(){return this.canManage?i.find(this.request.contact_id).then(function(e){this.contactName=e.display_name}.bind(this)):r.resolve()}function W(){if(this.isMode("create"))return r.resolve();var e=this.request.attributes();return this.uiOptions.fromDate=this._convertDateFormatFromServer(this.request.from_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.fromDate,"from").then(function(){return this.request.to_date=e.to_date,this.request.to_date_type=e.to_date_type,this.uiOptions.toDate=this._convertDateFormatFromServer(this.request.to_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.toDate,"to")}.bind(this))}function G(){Be.push(s.$on("LeaveRequestPopup::requestObjectUpdated",pe.bind(this)),s.$on("LeaveRequestPopup::childComponent::register",function(){Ee++}))}function z(){if(this.request.id){this.mode="edit";var e=[this.requestStatuses[y.statusNames.approved].value,this.requestStatuses[y.statusNames.adminApproved].value,this.requestStatuses[y.statusNames.rejected].value,this.requestStatuses[y.statusNames.cancelled].value];this.isRole("staff")&&e.indexOf(this.request.status_id)>-1&&(this.mode="view")}else this.mode="create"}function Y(){return Fe="staff",d(y.permissions.admin.administer).then(function(e){Fe=e?"admin":Fe}).then(function(){return"staff"===Fe&&d(y.permissions.ssp.manage).then(function(e){Fe=e?"manager":Fe})}).finally(function(){this.canManage=this.isRole("manager")||this.isRole("admin"),this.isSelfRecord=this.directiveOptions.isSelfRecord}.bind(this))}function K(){(this.isRole("admin")||this.isMode("create")&&this.isRole("manager"))&&(this.newStatusOnSave=this.requestStatuses[y.statusNames.approved].value)}function J(e){var t=this.getStatusFromValue(this.request.status_id);return!!t&&t.name===e}function X(e){return this.request.request_type===e}function Z(e){return this.mode===e}function Q(e){return Fe===e}function ee(e,t){var n=this.period.id;return t=t||"from",this.loading[t+"DayTypes"]=!0,this._checkAndSetAbsencePeriod(e).then(function(){var e=n===this.period.id;if(!e)return this.uiOptions.multipleDays&&"from"===t&&(this.uiOptions.showBalance=!1,this.uiOptions.toDate=null,this.request.to_date=null,this.request.to_date_type=null),r.all([this._loadAbsenceTypes(),this._loadCalendar()])}.bind(this)).then(function(){return this._setMinMaxDate(),T.call(this,e,t)}.bind(this)).finally(function(){this.loading[t+"DayTypes"]=!1}.bind(this))}function te(){var e=this;return u.all().then(function(t){e.absencePeriods=t})}function ne(){var e=this;return c.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(t){e.requestDayTypes=t})}function ae(){return v.get().then(function(e){Ne=e.contactId})}function re(){return this.directiveOptions.selectedContactId?i.find(this.directiveOptions.selectedContactId).then(function(e){this.managedContacts=[e]}.bind(this)):this.isRole("admin")?i.all().then(function(e){this.managedContacts=n.remove(e.list,function(e){return e.id!==Ne})}.bind(this)):i.find(Ne).then(function(e){return e.leaveManagees()}).then(function(e){this.managedContacts=e}.bind(this))}function se(){var e=this;return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){e.requestStatuses=n.indexBy(t,"name")})}function ie(e,t){return t.map(function(t){var a=n.find(e,function(e){return e.id===t.type_id});return{id:t.type_id,title:a.title+" ( "+t.remainder.current+" ) ",remainder:t.remainder.current,allow_overuse:a.allow_overuse}})}function oe(){this.$modalInstance.close({$value:this.request})}function ue(){var e=(this.currentPage-1)*this.numPerPage,t=e+this.numPerPage;this.filteredbreakdown=Ue.balance.change.breakdown.slice(e,t)}function le(e){_.call(this),s.$emit(e,this.request),this.errors=[],this.ok()}function ce(){this.pagination.totalItems=this.balance.change.breakdown.length,this.pagination.filteredbreakdown=this.balance.change.breakdown,this.pagination.pageChanged()}function de(e){var t=this;return h.all({contact_id:t.request.contact_id,period_id:t.period.id,type_id:{IN:e.ids}},!0).then(function(n){if(t.absenceTypes=ie(e.types,n),!t.absenceTypes.length)return r.reject(Ve)})}function fe(){(this.isMode("edit")&&this.request.from_date===this.request.to_date||this.isMode("create")&&this.isLeaveType("sickness"))&&(this.uiOptions.multipleDays=!1)}function me(e,t){var a="request"+n.startCase(e)+"DayTypes";this[a]=t,this.isMode("create")&&(this.request[e+"_date_type"]=this[a][0].value)}function he(){this.isMode("create")?(this.selectedAbsenceType=this.absenceTypes[0],this.request.type_id=this.selectedAbsenceType.id):this.selectedAbsenceType=L.call(this)}function pe(){je=e.copy(this.request.attributes()); +}function ve(){var e=this.request.status_id;if(!this.isMode("view")&&!this.submitting)return this.submitting=!0,P.call(this),qe.call(this).then(function(){return this.isMode("edit")?$e.call(this):D.call(this)}.bind(this)).catch(function(t){this.request.status_id=e,t&&B.call(this,t)}.bind(this)).finally(function(){this.submitting=!1}.bind(this))}function be(){function e(e){e&&n.push(e),++a===Ee&&(ge(),n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Ee>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function ge(){n.forEach(Be,function(e){e()})}function ye(e,t){return this.loadAbsencePeriodDatesTypes(e,t).then(function(){return this.updateBalance()}.bind(this)).catch(function(e){B.call(this,e),this._setDateAndTypes()}.bind(this))}function _e(){this.selectedAbsenceType=L.call(this),this.balance.opening=this.selectedAbsenceType.remainder,this.calculateBalanceChange()}function $e(){return this.request.update().then(be).then(function(){this.isRole("manager")?le.call(this,"LeaveRequest::updatedByManager"):(this.isRole("staff")||this.isRole("admin"))&&le.call(this,"LeaveRequest::edit")}.bind(this))}function qe(){return this.balance.closing<0&&"0"===this.selectedAbsenceType.allow_overuse?r.reject(["You cannot make a request for this leave type at this time as this would leave you with a negative balance"]):this.request.isValid()}function we(){this.balance.opening=this.selectedAbsenceType.remainder,this.balance.closing=this.balance.opening+this.balance.change.amount}function Ae(e){var t=a(e).format(this.uiOptions.userDateFormat.toUpperCase());return this.period=n.find(this.absencePeriods,function(e){return e.isInPeriod(t)}),this.period?r.resolve(!0):(this.period={},this.loading.fromDayTypes=!1,r.reject("Please change date as it is not in any absence period"))}function Pe(e){return a(e,y.serverDateFormat).toDate()}function Ce(e){return a(e).format(y.serverDateFormat)}function De(){return V.call(this),G.call(this),ae.call(this).then(Y.bind(this)).then(this._initRequest.bind(this)).then(se.bind(this)).then(function(){return z.call(this),this.canManage&&!this.isMode("edit")&&re.call(this)}.bind(this)).then(te.bind(this)).then(function(){F.call(this),this._setMinMaxDate()}.bind(this)).then(function(){if(this.directiveOptions.selectedContactId&&(this.request.contact_id=this.directiveOptions.selectedContactId),fe.call(this),this.request.contact_id)return this.initAfterContactSelection()}.bind(this)).catch(B.bind(this))}function Se(){var e={};return this.directiveOptions.leaveRequest?e=this.directiveOptions.leaveRequest.attributes():this.canManage||(e={contact_id:Ne}),e}function Re(){var e=this;return l.all(e.initParams.absenceType).then(function(t){var n=t.map(function(e){return e.id});return Me={types:t,ids:n},de.call(e,Me)})}function Te(){var e=this;return m.get(e.request.contact_id,e.period.start_date,e.period.end_date).then(function(t){e.calendar=t})}function Oe(){this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date_type=this.request.from_date_type,this.request.to_date=this.request.from_date,this.calculateBalanceChange()}function Ie(){this._setDates(),this.uiOptions.multipleDays?this.uiOptions.showBalance=!!(this.request.from_date&&this.request.from_date_type&&this.request.to_date&&this.request.to_date_type&&this.period.id):(this.uiOptions.fromDate&&(this.request.to_date_type=this.request.from_date_type),this.uiOptions.showBalance=!!this.request.from_date&&!!this.request.from_date_type&&!!this.period.id)}function ke(){this.request.from_date=this.uiOptions.fromDate?this._convertDateToServerFormat(this.uiOptions.fromDate):null,this.request.to_date=this.uiOptions.toDate?this._convertDateToServerFormat(this.uiOptions.toDate):null,!this.uiOptions.multipleDays&&this.uiOptions.fromDate&&(this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date=this.request.from_date)}function xe(){if(this.uiOptions.fromDate){var e=a(this.uiOptions.fromDate).add(1,"d").toDate();this.uiOptions.date.to.options.minDate=e,this.uiOptions.date.to.options.initDate=e,this.uiOptions.toDate&&a(this.uiOptions.toDate).isBefore(this.uiOptions.fromDate)&&(this.uiOptions.toDate=this.uiOptions.fromDate)}else this.uiOptions.date.to.options.minDate=this._convertDateFormatFromServer(this.period.start_date),this.uiOptions.date.to.options.initDate=this.uiOptions.date.to.options.minDate;this.uiOptions.date.to.options.maxDate=this._convertDateFormatFromServer(this.period.end_date)}t.debug("RequestCtrl");var Me,Le={},Ee=0,je={},Be=[],Ne="",Fe="",Ue=this,Ve="No entitlement";this.absencePeriods=[],this.absenceTypes=[],this.calendar={},this.canManage=!1,this.contactName=null,this.errors=[],this.fileUploader=null,this.isSelfRecord=!1,this.managedContacts=[],this.mode="",this.newStatusOnSave=null,this.period={},this.postContactSelection=!1,this.requestDayTypes=[],this.requestStatuses={},this.selectedAbsenceType={},this.statusNames=y.statusNames,this.submitting=!1,this.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},this.loading={absenceTypes:!0,showBalanceChange:!1,fromDayTypes:!1,toDayTypes:!1},this.pagination={currentPage:1,filteredbreakdown:this.balance.change.breakdown,numPerPage:7,totalItems:this.balance.change.breakdown.length,pageChanged:ue},this.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:p.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}}}},this.changeInNoOfDays=A,this.calculateBalanceChange=$,this.canSubmit=w,this.closeAlert=C,this.deleteLeaveRequest=S,this.dismissModal=R,this.formatDateTime=O,this.getStatuses=E,this.getStatusFromValue=j,this.initAfterContactSelection=U,this.isLeaveStatus=J,this.isLeaveType=X,this.isMode=Z,this.isRole=Q,this.ok=oe,this.submit=ve,this.loadAbsencePeriodDatesTypes=ee,this.updateAbsencePeriodDatesTypes=ye,this.updateBalance=_e,this._calculateOpeningAndClosingBalance=we,this._checkAndSetAbsencePeriod=Ae,this._convertDateToServerFormat=Ce,this._convertDateFormatFromServer=Pe,this._init=De,this._initRequestAttributes=Se,this._loadCalendar=Te,this._loadAbsenceTypes=Re,this._reset=Oe,this._setDates=ke,this._setDateAndTypes=Ie,this._setMinMaxDate=xe}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","Contact","dialog","AbsencePeriod","AbsenceType","api.optionGroup","checkPermissions","pubSub","Calendar","Entitlement","HR_settings","Session","LeaveRequest","PublicHoliday","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/leave-request.controller",["leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/leave-request.instance"],function(e){function t(e,t,n,a,r){function s(){var e=o._initRequestAttributes();o.request=r.init(e)}t.debug("LeaveRequestCtrl");var i=e("RequestCtrl"),o=Object.create(i);return o.directiveOptions=a,o.$modalInstance=n,o.initParams={absenceType:{is_sick:!1}},o._initRequest=s,function(){o.loading.absenceTypes=!0,o._init().finally(function(){o.loading.absenceTypes=!1})}(),o}e.controller("LeaveRequestCtrl",t),t.$inject=["$controller","$log","$uibModalInstance","directiveOptions","LeaveRequestInstance"]}),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(){var e=this.sickness_required_documents?this.sickness_required_documents.split(","):[];return e},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/controllers/sub-controllers/sick-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/sickness-request.instance"],function(e,t){function n(t,n,a,r,s,i,o){function u(){return h.canSubmit.call(this)&&!!p.request.sickness_reason}function l(t){var n=p.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(p.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){p.sicknessDocumentTypes=e})}function f(){return s.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){p.sicknessReasons=e.indexBy(t,"name")})}function m(){var e=p._initRequestAttributes();p.request=o.init(e)}n.debug("SicknessRequestCtrl");var h=t("RequestCtrl"),p=Object.create(h);return p.directiveOptions=i,p.$modalInstance=r,p.initParams={absenceType:{is_sick:!0}},p.canSubmit=u,p.isChecked=l,p.isDocumentInRequest=c,p._initRequest=m,function(){p.loading.absenceTypes=!0,p._init().then(function(){return a.all([d(),f()])}).finally(function(){p.loading.absenceTypes=!1})}(),p}t.controller("SicknessRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","directiveOptions","SicknessRequestInstance"]}),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/sub-controllers/toil-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/toil-request.instance"],function(e,t){function n(t,n,a,r,s,i,o,u){function l(){P.request.toil_to_accrue&&(P.loading.showBalanceChange=!0,P._setDateAndTypes(),P.balance.change.amount=+P.request.toil_to_accrue,P._calculateOpeningAndClosingBalance(),P.uiOptions.showBalance=!0,P.request.to_date_type=P.request.from_date_type="1",P.loading.showBalanceChange=!1)}function c(){return!P.canManage&&P.request.id?a.resolve(P.request.toil_expiry_date):P.requestCanExpire?p().catch(function(e){return e.length&&(P.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(P.request.type_id,e)}).then(function(e){return P.request.toil_expiry_date=e,P.uiOptions.expiryDate=new Date(e),e}):(P.request.toil_expiry_date=!1,a.resolve(!1))}function d(){return P.uiOptions.multipleDays&&P.request.to_date||!P.uiOptions.multipleDays&&P.request.from_date}function f(){return A.canSubmit.call(this)&&!!P.request.toil_duration&&!!P.request.toil_to_accrue&&!!P.request.from_date&&!!P.request.to_date}function m(){A.changeInNoOfDays.call(this),d()&&P.calculateToilExpiryDate()}function h(){P.request.toil_expiry_date=!1,P.uiOptions.expiryDate=null}function p(){return v(P.uiOptions.multipleDays?{hasErrors:!P.request.to_date&&!P.request.from_date,label:"To Date",value:P.request.to_date}:{hasErrors:!P.request.from_date,label:"From Date",value:P.request.from_date})}function v(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(e.value):a.reject([])}function b(){P.canManage&&(P.uiOptions.expiryDate=P._convertDateFormatFromServer(P.request.toil_expiry_date))}function g(){return i.canExpire(P.request.type_id).then(function(e){P.requestCanExpire=e})}function y(e){var t=P.period.id;return P._checkAndSetAbsencePeriod(e).then(function(){var e=t===P.period.id;if(!e)return P.uiOptions.multipleDays&&(P.uiOptions.showBalance=!1,P.uiOptions.toDate=null,P.request.to_date=null),a.all([P._loadAbsenceTypes(),P._loadCalendar()])})}function _(){return s.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){P.toilAmounts=e.indexBy(t,"value")})}function $(e){return P.loadAbsencePeriodDatesTypes().then(function(){P._setMinMaxDate(),P._setDates(),P.updateBalance(),P.calculateToilExpiryDate()}).catch(function(e){P.errors=[e]})}function q(){P.uiOptions.expiryDate&&(P.request.toil_expiry_date=P._convertDateToServerFormat(P.uiOptions.expiryDate))}function w(){var e=P._initRequestAttributes();P.request=u.init(e),P.request.to_date_type=P.request.from_date_type="1"}n.debug("ToilRequestCtrl");var A=t("RequestCtrl"),P=Object.create(A);return P.requestCanExpire=!0,P.directiveOptions=o,P.$modalInstance=r,P.initParams={absenceType:{allow_accruals_request:!0}},P.calculateBalanceChange=l,P.calculateToilExpiryDate=c,P.canSubmit=f,P.changeInNoOfDays=m,P.clearExpiryDate=h,P.loadAbsencePeriodDatesTypes=y,P.updateAbsencePeriodDatesTypes=$,P.updateExpiryDate=q,P._initRequest=w,function(){P.loading.absenceTypes=!0,P._init().then(function(){return g()}).then(function(){return b(),_()}).finally(function(){P.loading.absenceTypes=!1})}(),P}t.controller("ToilRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","AbsenceType","directiveOptions","TOILRequestInstance"]}),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-popup.service",["common/lodash","leave-absences/shared/modules/services","common/services/notification.service"],function(e,t){"use strict";function n(t,n,a,r,s,i,o,u,l,c){function d(e){return l.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function f(e,t){return t?t.request_type:e||null}function m(t,a,r,i){var u=e.capitalize(f(a,t))+"RequestCtrl";s.open({appendTo:n.children().eq(0),templateUrl:o.sharedPathTpl+"directives/leave-request-popup/leave-request-popup.html",controller:u,controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveRequest:t,selectedContactId:r,isSelfRecord:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function h(e){return c.find(e).then(function(e){return d(e).then(function(t){t?m(e,e.request_type,e.contact_id,"my-leave"===a.section):i.error("Error","You dont have permission to see this leave request")})}).catch(function(e){i.error("Error",e)})}return t.debug("LeavePopup"),{openModal:m,openModalByID:h}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$q","$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,s){r.debugEnabled(s.debug),t.defaults.stripTrailingSlashes=!1,a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",n.otherwise("/requests"),e.state("requests",{url:"/requests",template:''}).state("calendar",{url:"/calendar",template:''}).state("balance-report",{url:"/balance-report",template:""})}])}),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/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-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/leave-request.controller","leave-absences/shared/controllers/sub-controllers/sick-request.controller","leave-absences/shared/controllers/sub-controllers/toil-request.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.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(){}); \ 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 85dd4e43351..db5a688f842 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,6 +6,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 H(new(H(function(){},{prototype:e})),t)}function r(e){return V(arguments,function(t){t!==e&&V(t,function(t,n){e.hasOwnProperty(n)||(e[n]=t)})}),e}function s(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 i(e){if(Object.keys)return Object.keys(e);var t=[];return V(e,function(e,n){t.push(n)}),t}function o(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),a<0&&(a+=n);a=0||(c.push(r[f]),l[r[f]]=e[r[f]]);return H({},l,t)}function l(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)}],l);else{var r=t.annotate(e);V(r,function(e){e!==n&&u.hasOwnProperty(e)&&m(u[e],e)}),v.push(n,e,r)}g.pop(),b[n]=s}}function h(e){return F(e)&&e.then&&e.$$promises}if(!F(u))throw new Error("'invocables' must be an object");var p=i(u||{}),v=[],g=[],b={};return V(u,m),u=g=b=null,function(a,s,i){function o(){--_||($||r(y,s.$$values),g.$$values=y,g.$$promises=g.$$promises||!0,delete g.$$inheritedValues,m.resolve(y))}function u(e){g.$$failure=e,m.reject(e)}function l(n,r,s){function l(e){d.reject(e),u(e)}function c(){if(!j(g.$$failure))try{d.resolve(t.invoke(r,i,y)),d.promise.then(function(e){y[n]=e,o()},l)}catch(e){l(e)}}var d=e.defer(),f=0;V(s,function(e){b.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,b[e].then(function(t){y[e]=t,--f||c()},l))}),f||c(),b[n]=d.promise}if(h(a)&&i===n&&(i=s,s=a,a=null),a){if(!F(a))throw new Error("'locals' must be an object")}else a=c;if(s){if(!h(s))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else s=d;var m=e.defer(),g=m.promise,b=g.$$promises={},y=H({},a),_=1+v.length/3,$=!1;if(j(s.$$failure))return u(s.$$failure),g;s.$$inheritedValues&&r(y,f(s.$$inheritedValues,p)),H(b,s.$$promises),s.$$values?($=r(y,f(s.$$values,p)),g.$$inheritedValues=f(s.$$values,p),o()):(s.$$inheritedValues&&(g.$$inheritedValues=f(s.$$inheritedValues,p)),s.then(o,u));for(var q=0,w=v.length;q=0));)b=s(g.id,g.type,g.cfg,"path"),d+=i(g.segment,b.type.pattern.source,b.squash,b.isOptional),m.push(g.segment),f=l.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var $=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),$.length>0)for(f=0;u=c.exec($);)g=o(u,!0),b=s(g.id,g.type,g.cfg,"search"),f=l.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=i(y)+(t.strict===!1?"/?":"")+"$",m.push(y),this.regexp=new RegExp(d,t.caseInsensitive?"i":n),this.prefix=m[0],this.$$paramNames=v}function y(e){H(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 s(){return{strict:p,caseInsensitive:f}}function u(e){return B(e)||U(e)&&B(e[e.length-1])}function l(){for(;q.length;){var e=q.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 c(e){H(this,e||{})}z=this;var d,f=!1,p=!0,v=!1,g={},$=!0,q=[],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 e===!0||e===!1},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)&&(p=e),p},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(e!==!0&&e!==!1&&!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,H(s(),t))},this.isMatcher=function(e){if(!F(e))return!1;var t=!0;return V(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(H({name:e},t)),n&&(q.push({name:e,def:n}),$||l()),this},V(w,function(e,t){g[t]=new y(H({name:t},e))}),g=a(g,{}),this.$get=["$injector",function(e){return d=e,$=!1,l(),V(w,function(e,t){g[t]||(g[t]=new y(e))}),this}],this.Param=function(e,a,r,s){function l(e){var t=F(e)?i(e):[],n=o(t,"value")===-1&&o(t,"type")===-1&&o(t,"squash")===-1&&o(t,"array")===-1;return n&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}function c(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a?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}function f(){var t={array:"search"===s&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return H(t,n,r).array}function p(e,t){var n=e.squash;if(!t||n===!1)return!1;if(!j(n)||null==n)return v;if(n===!0||N(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}function b(e,t,a,r){var s,i,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return s=U(e.replace)?e.replace:[],N(r)&&s.push({from:r,to:n}),i=h(s,function(e){return e.from}),m(u,function(e){return o(i,e.from)===-1}).concat(s)}function _(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!w.type.is(e))throw new Error("Default value ("+e+") for parameter '"+w.id+"' is not an instance of Type ("+w.type.name+")");return e}function $(e){function t(e){return function(t){return t.from===e}}function n(e){var n=h(m(w.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}return e=n(e),j(e)?w.type.$normalize(e):_()}function q(){return"{Param:"+e+" "+a+" squash: '"+C+"' optional: "+P+"}"}var w=this;r=l(r),a=c(r,a,s);var A=f();a=A?a.$asArray(A,"search"===s):a,"string"!==a.name||A||"path"!==s||r.value!==n||(r.value="");var P=r.value!==n,C=p(r,P),D=b(r,A,P,C);H(this,{id:e,type:a,location:s,array:A,squash:C,replace:D,isOptional:P,value:$,dynamic:n,config:r,toString:q})},c.prototype={$$new:function(){return a(this,H(new c,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=i(c.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),V(t,function(t){V(i(t),function(t){o(e,t)===-1&&o(a,t)===-1&&e.push(t)})}),e},$$values:function(e){var t={},n=this;return V(n.$$keys(),function(a){t[a]=n[a].value(e&&e[a])}),t},$$equals:function(e,t){var n=!0,a=this;return V(a.$$keys(),function(r){var s=e&&e[r],i=t&&t[r];a[r].type.equals(s,i)||(n=!1)}),n},$$validates:function(e){var a,r,s,i,o,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(C.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=n.indexOf(".")!==-1?n.substring(0,n.lastIndexOf(".")):N(t.parent)?t.parent:F(t.parent)&&N(t.parent.name)?t.parent.name:"";if(r&&!C[r])return m(r,t.self);for(var s in R)B(R[s])&&(t[s]=R[s](t,R.$delegates[s]));return C[n]=t,!t[S]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){P.$current.navigable==t&&l(e,n)||P.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=P.$current.name.split("."),a=0,r=t.length;a=C;a--)i=h[a],i.self.onExit&&o.invoke(i.self.onExit,i.self,i.locals.globals),i.locals=null;for(a=C;a<_.length;a++)r=_[a],r.locals=x[a],r.self.onEnter&&o.invoke(r.self.onEnter,r.self,r.locals.globals);return P.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,l.self,d),R):(P.$current=t,P.current=t.self,P.params=n,W(P.params,m),P.transition=null,s.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===s.location}),s.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,l.self,d),v.update(!0),P.current)}).then(null,function(a){return a===D?R:P.transition!==B?(e.$broadcast("$stateChangeCancel",t.self,n,l.self,d),R):(P.transition=null,i=e.$broadcast("$stateChangeError",t.self,n,l.self,d,a),i.defaultPrevented||v.update(),r.reject(a))});return B},P.is=function(e,t,a){a=H({relative:P.$current},a||{});var r=f(e,a.relative);return j(r)?P.$current===r&&(!t||l(r.params.$$values(t),m)):n},P.includes=function(e,t,a){if(a=H({relative:P.$current},a||{}),N(e)&&b(e)){if(!y(e))return!1;e=P.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(P.$current.includes[r.name]))return!1;if(!t)return!0;for(var s=i(t),o=0;o2?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(l){var r=l&&l(n,e);return{enter:function(e,t,n){r.enter(e,null,t),n()},leave:function(e,t){r.leave(e),t()}}}return a()}var u=i(),l=u("$animator"),c=u("$animate"),d={restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,i,u){return function(n,i,l){function c(){if(f&&(f.remove(),f=null),h&&(h.$destroy(),h=null),m){var e=m.data("$uiViewAnim");b.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(o){var d,f=D(n,l,i,r),y=f&&e.$current&&e.$current.locals[f];if(o||y!==p){d=n.$new(),p=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=s.defer(),o=s.defer(),u={$animEnter:r.promise,$animLeave:o.promise,$$animLeave:o};e.data("$uiViewAnim",u),b.enter(e,i,function(){r.resolve(),h&&h.$emit("$viewContentAnimationEnded"),(t.isDefined(g)&&!g||n.$eval(g))&&a(e)}),c()});m=_,h=d,h.$emit("$viewContentLoaded",f),h.$eval(v)}}var f,m,h,p,v=l.onload||"",g=l.autoscroll,b=o(l,n);i.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}};return d}function C(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(s){var i=s.html();return function(s,o,u){var l=a.$current,c=D(s,u,o,r),d=l&&l.locals[c];if(d){o.data("$uiView",{name:c,state:d.$$state}),o.html(d.$template?d.$template:i);var f=t.extend({},d);s[d.$$resolveAs]=f;var m=e(o.contents());if(d.$$controller){d.$scope=s,d.$element=o;var h=n(d.$$controller,d);d.$$controllerAs&&(s[d.$$controllerAs]=h,s[d.$$controllerAs][d.$$resolveAs]=f),B(h.$onInit)&&h.$onInit(),o.data("$ngControllerController",h),o.children().data("$ngControllerController",h)}m(s)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),s=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(s?s.state.name:"")}function S(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/),!n||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 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(s){var i=s.which||s.button,o=r();if(!(i>1||s.ctrlKey||s.metaKey||s.shiftKey||e.attr("target"))){var u=n(function(){t.go(o.state,o.params,o.options)});s.preventDefault();var l=a.isAnchor&&!o.href?1:0;s.preventDefault=function(){l--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:R(e)||t.$current,inherit:!0}}function k(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,s,i){var o,u=S(s.uiSref,e.current.name),l={state:u.state,href:null,params:null},c=T(r),d=i[1]||i[0],f=null;l.options=H(I(r,e),s.uiSrefOpts?a.$eval(s.uiSrefOpts):{});var m=function(n){n&&(l.params=t.copy(n)),l.href=e.href(u.state,l.params,l.options),f&&f(),d&&(f=d.$$addStateInfo(u.state,l.params)),null!==l.href&&s.$set(c.attr,l.href)};u.paramExpr&&(a.$watch(u.paramExpr,function(e){e!==l.params&&m(e)},!0),l.params=t.copy(a.$eval(u.paramExpr))),m(),c.clickable&&(o=O(r,e,n,c,function(){return l}),r[r.on?"on":"bind"]("click",o),a.$on("$destroy",function(){r[r.off?"off":"unbind"]("click",o)}))}}}function x(e,t){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(n,a,r,s){function i(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(),l&&(m=l.$$addStateInfo(f.state,f.params)),f.href&&r.$set(u.attr,f.href)}var o,u=T(a),l=s[1]||s[0],c=[r.uiState,r.uiStateParams||null,r.uiStateOpts||null],d="["+c.map(function(e){return e||"null"}).join(", ")+"]",f={state:null,params:null,options:null,href:null},m=null;n.$watch(d,i,!0),i(n.$eval(d)),u.clickable&&(o=O(a,e,t,u,function(){return f}),a[a.on?"on":"bind"]("click",o),n.$on("$destroy",function(){a[a.off?"off":"unbind"]("click",o)}))}}}function L(e,t,n){return{restrict:"A",controller:["$scope","$element","$attrs","$timeout",function(t,a,r,s){function i(t,n,r){var s=e.get(t,R(a)),i=o(t,n),u={state:s||{name:t},params:n,hash:i};return p.push(u),v[i]=r,function(){var e=p.indexOf(u);e!==-1&&p.splice(e,1)}}function o(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=i(e,t,h);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,V=t.forEach,H=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 z;b.prototype.concat=function(e,t){var n={caseInsensitive:z.caseInsensitive(),strict:z.strictMode(),squash:z.defaultSquashPolicy()};return new b(this.sourcePath+e+this.sourceSearch,H(n,t),this)},b.prototype.toString=function(){return this.source},b.prototype.exec=function(e,t){function n(e){function t(e){return e.split("").reverse().join("")}function n(e){return e.replace(/\\-/g,"-")}var a=t(e).split(/-(?!\\)/),r=h(a,t);return h(r,n).reverse()}var a=this.regexp.exec(e);if(!a)return null;t=t||{};var r,s,i,o=this.parameters(),u=o.length,l=this.segments.length-1,c={};if(l!==a.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var d,f;for(r=0;r=":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.defaults(t||{},{is_active:!0})).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(r.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",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/absence-type-api","leave-absences/shared/instances/absence-type.instance"],function(e){"use strict";e.factory("AbsenceType",["$log","Model","AbsenceTypeAPI","AbsenceTypeInstance",function(e,t,n,a){return e.debug("AbsenceType"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return a.init(e,!0)})})},calculateToilExpiryDate:function(e,t,a){return n.calculateToilExpiryDate(e,t,a)},canExpire:function(e){return n.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})}})}])}),define("leave-absences/shared/modules/components",["common/angular"],function(e){return e.module("leave-absences.components",[])}),define("leave-absences/shared/apis/leave-balance-report.api",["leave-absences/shared/modules/apis","mocks/data/leave-balance-report.data"],function(e,t){"use strict";e.factory("LeaveBalanceReportAPI",["$q","$log","api",function(e,n,a){return a.extend({getAll:function(a,r,s){n.debug("LeaveBalanceReportAPI.all");var i=t.all().values;if(r){var o,u;r.page=r.page||1,r.size=r.size||i.length,u=(r.page-1)*r.size,o=u+r.size,i=i.slice(u,o)}return e.resolve({list:i,total:t.all().values.length,allIds:i.map(function(e){return e.id}).join(",")})}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/leave-balance-report.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","LeaveBalanceReportAPI",function(e,t){return e.extend({all:function(e,n,a){return t.getAll(e,n,a)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service"],function(e,t,n){function a(n,a,r,s,i){function o(){return a.all({options:{sort:"title ASC"}}).then(function(e){m.absenceTypes=e})}function u(){return i.get().then(function(e){d=e.contact_id})}function l(e){return e=e||1,m.loading.report=!0,r.all({managed_by:d},{page:e,size:f}).then(function(e){m.report=c(e.list),m.reportCount=e.total}).catch(function(e){s.error("Error",e.error_message)}).finally(function(){m.loading.report=!1})}function c(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})}var d,f=50,m=this;m.absenceTypes=[],m.loading={report:!0},m.report=[],m.reportCount=0,function(){m.loading.report=!0;var e=1;n.all([o(),u()]).then(l.bind(this,e)).catch(function(e){s.error("Error",e)})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","AbsenceType","LeaveBalanceReport","notificationService","Session"]}),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"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all().then(function(e){s.lookupContacts=e.list}).then(a)}}}function a(){return t.all(r(),null,"display_name").then(function(e){return e.list})}function r(){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("LeaveCalendarAdminController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,n()}}}n.controller("LeaveCalendarAdminController",["$log","Contact",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(r)}}}function r(){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,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,s,i,o,u,l,c,d,f,m,h,p){function v(){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(R(t)),t.add(1,"month");E.months=e}function g(){i.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||O()})}function b(e){x("injected").then(function(){O(e)}).then(function(){E.loading.calendar=!1}),S().then(function(){E.injectMonths=!0})}function y(){L=a("LeaveCalendar"+t.capitalize(M)+"Controller").init(E)}function _(e){return e.current?"Current Period ("+e.title+")":e.title}function $(){return l.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(v).then(I)}function q(){return c.all({is_active:!0})}function w(){return m.valuesOf(["hrleaveandabsences_leave_request_status","hrleaveandabsences_leave_request_day_type"])}function A(){return L.loadContacts().then(function(e){E.contacts=e})}function P(){return m.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 f.all()}function D(){return r.all([q(),C(),w()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type})}function S(){var e=r.resolve();return E.injectMonths&&(e=x("destroyed"),E.injectMonths=!1),e}function R(e){return{index:e.month(),year:e.year(),name:e.format("MMM")}}function T(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then("period"===e?v:t.noop).then("contacts"===e?A:t.noop).then(function(){b("contacts"===e)})}function O(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function I(){E.selectedMonths=[n().month()]}function k(){return E.roleOverride?r.resolve().then(function(){M=E.roleOverride}):r.all([p(u.permissions.admin.administer),p(u.permissions.ssp.manage)]).then(function(e){M=e[0]?"admin":e[1]?"manager":"staff"})}function x(e){return r(function(n){var a=0,r=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}s.debug("Component: leave-calendar");var L,M,E=this;E.absencePeriods=[],E.contacts=[],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:!1,department:null,level_type:null,location:null,region:null}},E.labelPeriod=_,E.refresh=T,function(){k().then(g).then(y).then(function(){return r.all([A(),$(),D()])}).then(function(){return E.showFilters?P():t.noop}).then(function(){b()}).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","$timeout","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","PublicHoliday","OptionGroup","Calendar","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["leave-absences/shared/modules/components"],function(e){function t(e,t){"use strict";function n(e,n,a,r,s){e.stopPropagation(),t.openModal(n,a,r,s)}e.debug("Component: leave-calendar-day");var a=this;a.openLeavePopup=n}e.component("leaveCalendarDay",{bindings:{contactData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:t}),t.$inject=["$log","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.collapsed=!1,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"],function(e,t,n){function a(n,a,r,s,i,o){function u(e,t){v([t]),x(t)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:c(e)}}function c(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(B.period.start_date)&&r.isSameOrBefore(B.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function d(e){return E[e]}function f(){return B.showOnlyWithLeaveRequests?B.contacts.filter(function(t){return e.includes(Object.keys(j),t.id)}):B.contacts}function m(e){return t(e,o.serverDateFormat)}function h(e,t){D(t),x(t)}function p(){B.supportData.dayTypes=e.indexBy(B.supportData.dayTypes,"name"),B.supportData.leaveRequestStatuses=e.indexBy(B.supportData.leaveRequestStatuses,"value"),B.supportData.publicHolidays=e.transform(B.supportData.publicHolidays,function(e,t){e[m(t.date).valueOf()]=t},{})}function v(e){var t=a.defer();return e.forEach(function(e){var t=$(e);j[e.contact_id]=j[e.contact_id]||{},t.forEach(function(t){j[e.contact_id][t.date]=e})}),t.resolve(),t.promise}function g(){M.push(r.$on("LeaveCalendar::showMonths",O)),M.push(r.$on("LeaveRequest::new",u)),M.push(r.$on("LeaveRequest::edit",k)),M.push(r.$on("LeaveRequest::updatedByManager",k)),M.push(r.$on("LeaveRequest::deleted",h))}function b(e,n,a){var r=B.supportData.dayTypes[e];return t(a).isSame(n.from_date)?r.value===n.from_date_type:t(a).isSame(n.to_date)?r.value===n.to_date_type:void 0}function y(e){var t=B.supportData.leaveRequestStatuses[e.status_id];return t.name===o.statusNames.awaitingApproval}function _(e){return!!B.supportData.publicHolidays[m(e).valueOf()]}function $(n){for(var a=[],r=t(n.from_date).clone(),s=t(n.to_date);r.isSameOrBefore(s);)a.push(e.find(B.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function q(t){return e.find(j[t.contact_id],function(e){return t.id===e.id})}function w(t){var n=e.find(B.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function A(){return B.month.loading=!0,a.all([C(),P()]).then(function(){return T()}).then(function(){L=!0}).then(function(){B.month.loading=!1})}function P(){return i.all({from_date:{from:B.month.days[0].date},to_date:{to:B.month.days[B.month.days.length-1].date},status_id:{IN:[w(o.statusNames.approved),w(o.statusNames.adminApproved),w(o.statusNames.awaitingApproval)]},contact_id:{IN:B.contacts.map(function(e){return e.id})}},null,null,null,!1).then(function(e){return v(e.list)})}function C(){var t=B.month.days[0].date,n=B.month.days[B.month.days.length-1].date;return s.get(B.contacts.map(function(e){return e.id}),t,n).then(function(t){E=e.indexBy(t,"contact_id")})}function D(t){j[t.contact_id]=e.omit(j[t.contact_id],function(e){return e.id===t.id})}function S(){r.$emit("LeaveCalendar::monthDestroyed"),M.map(function(e){e()})}function R(t,n,r){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=d(n),s=r===!0?a.resolve():a.all([i.isWeekend(m(t.date)),i.isNonWorkingDay(m(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:_(t.date)})}),s.then(function(){return j[n]?j[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?I(a):null,isAccruedTOIL:a?a.balance_change>0:null,isRequested:a?y(a):null,isAM:a?b("half_day_am",a,t.date):null,isPM:a?b("half_day_pm",a,t.date):null})})}function T(){return a.all(B.month.days.map(function(e){return a.all(B.contacts.map(function(t){return R(e,t.id)}))}))}function O(t,n,a){var r=!!e.find(n,function(e){return e.index===B.month.index});r?(B.currentPage=0,B.visible=!0,(a||!L)&&A()):B.visible=!1}function I(t){var n=e.find(B.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 k(e,t){var n=q(t);h(null,n),u(null,t)}function x(e){return a.all($(e).map(function(t){return R(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var L=!1,M=[],E={},j={},B=this;B.currentPage=0,B.pageSize=20,B.visible=!1,B.showContactName=!!B.showContactName,B.showOnlyWithLeaveRequests=!!B.showOnlyWithLeaveRequests,B.$onDestroy=S,B.contactsList=f,function(){var e=t().month(B.month.index).year(B.month.year);p(),g(),B.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",month:"<",period:"<",showContactName:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","shared-settings",a]})}),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"],function(e,t,n){function a(n,a,r,s,i,o,u){function l(e){var t=y[e].dialog;v=g.leaveRequest.status_id,r.open({title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return g.leaveRequest[e]().then(function(){m(e)}).catch(function(e){u.error("Error:",e)})}})}function c(){var e=g.absenceTypes[g.leaveRequest.type_id].allow_request_cancelation;return"admin"===g.role||"manager"===g.role||("3"===e?t().isBefore(g.leaveRequest.from_date):"2"===e)}function d(){Array.isArray(g.leaveRequestStatuses)&&(g.leaveRequestStatuses=e.indexBy(g.leaveRequestStatuses,"value")),Array.isArray(g.absenceTypes)&&(g.absenceTypes=e.indexBy(g.absenceTypes,"id"))}function f(e,t,n,a,r){e.stopPropagation(),s.openModal(t,n,a,r)}function m(t){var n=e.find(g.leaveRequestStatuses,function(e){return e.name===o.statusNames.awaitingApproval}).value;v===n&&i.publish("ManagerBadge:: Update Count"),a.$emit("LeaveRequest::"+("delete"===t?"deleted":"edit"),g.leaveRequest)}function h(){var t=g.leaveRequestStatuses[g.leaveRequest.status_id].name,n=e.compact(e.map(y,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!c()&&e.pull(n,"cancel"),"admin"!==g.role&&e.pull(n,"delete"),"staff"===g.role&&e.pull(n,"approve","reject"),"staff"!==g.role&&p(n),g.allowedActions=e.map(n,function(e){return{key:e,label:y[e].label,isDirectAction:y[e].isDirectAction}})}function p(t){e.each(t,function(e,n){"edit"===e&&(t[n]="respond"),"respond"===e&&(t[n]="edit")})}n.debug("Component: leave-request-action-dropdown");var v,g=this,b=o.statusNames,y={edit:{label:"Edit",allowedStatuses:[b.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[b.moreInformationRequired]},view:{label:"View",allowedStatuses:[b.approved,b.rejected,b.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[b.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[b.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[b.awaitingApproval,b.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[b.awaitingApproval,b.moreInformationRequired,b.approved,b.rejected,b.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};g.allowedActions=[],g.action=l,g.openLeavePopup=f,function(){d(),h()}()}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","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,s,i,o){function u(){var t=e.indexBy(f.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){f.comment.contacts=e.indexBy(t.list,"contact_id")})}function l(){return f.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),f.request.comments.length&&u()})}function c(){return f.loading.component=!0,o.get().then(function(e){d=e.contactId}).then(function(){f.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var d=null,f=this;f.loading={component:!0},f.comment={text:"",contacts:{}},function(){l(),c()}(),f.addComment=function(){f.request.comments.push({contact_id:d,leave_request_id:f.request.id,text:f.comment.text}),f.comment.text=""},f.formatDateTime=function(e){return t.utc(e,s.serverDateTimeFormat).local().format(r.DATE_FORMAT.toUpperCase()+" HH:mm")},f.getActiveComments=function(){return f.request.comments.filter(function(e){return!e.toBeDeleted})},f.getCommentorName=function(e){return e===d?"Me":f.comment.contacts[e]?f.comment.contacts[e].display_name:void 0},f.isMode=function(e){return f.mode===e},f.orderComment=function(e){return t(e.created_at,s.serverDateTimeFormat)},f.removeCommentVisibility=function(e){return!e.comment_id||f.canManage}}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"directives/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","HR_settings","shared-settings","Contact","Session",a]})}),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,s,i,o,u,l){function c(){return e.filter(w.request.files,function(e){return e.toBeDeleted})}function d(){return w.fileUploader&&w.fileUploader.queue?w.fileUploader.queue:[]; -}function f(){$.push(a.$on("LeaveRequestPopup::submit",y))}function m(){v().then(function(){w.fileUploader=u.uploader({entityTable:"civicrm_hrleaveandabsences_leave_request",crmAttachmentToken:i.attachmentToken,queueLimit:i.fileUploader.queueLimit,allowedMimeTypes:q})})}function h(){return _.length>0?_.map(function(e){return e.label}).join(", "):""}function p(){return w.request.loadAttachments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function v(){return r.all(_.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){q[e.label]=t})})).catch(function(){q=null})}function g(){return o.valuesOf("safe_file_extension").then(function(e){_=e})}function b(){e.forEach($,function(e){e()})}function y(e,t){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var _=[],$=[],q={},w=Object.create(this);return w.filesLoaded=!1,w.today=Date.now(),w.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",w.userDateFormat=s.DATE_FORMAT,w.listFileTypes=h,w.$onDestroy=b,w.canUploadMore=function(){return w.getFilesCount()0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function x(e){var t=[y(o.statusNames.moreInformationRequired),y(o.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=x(n)),n.length)return{IN:n}}function M(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=U),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,A(n))}function E(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function j(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function B(){a.$on("LeaveRequest::updatedByManager",function(){F.refresh()}),a.$on("LeaveRequest::new",function(){F.refresh()}),a.$on("LeaveRequest::edit",function(){F.refresh()}),a.$on("LeaveRequest::deleted",function(){F.refresh()})}function N(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,U={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[U],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},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:"me"}},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.clearStaffSelection=f,F.filterLeaveRequestByStatus=h,F.getAbsenceTypesByID=p,F.getArrayOfSize=v,F.getLeaveStatusByValue=g,F.getNavBadge=b,F.getUserNameByID=_,F.labelPeriod=$,F.openLeavePopup=I,F.refresh=M,F.refreshWithFilter=E,F.refreshWithFilterByAssignee=j,F.totalNoOfPages=N,function(){s(o.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([q(),w(),T(),P(),S(),D(),O()]).then(function(){F.loading.page=!1,A()}),B()})}()}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"]}),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,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,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,r,s){return t.debug("WorkPatternAPI.getCalendar",n,a,r,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{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,s,i){function o(t,n){return l().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,s.serverDateFormat).clone()}function l(){return c=c||i.valuesOf("hrleaveandabsences_work_day_type")}var c;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return o.call(this,e,"non_working_day")},isWeekend:function(e){return o.call(this,e,"weekend")},isWorkingDay:function(e){return o.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,s,i,o){return t.debug("Calendar.get"),a.getCalendar(n,s,i,o).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})}})}])}),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/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance",function(t,n,a,r){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)})})}})}])}),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,s,i){e.debug("LeaveRequestAPI.all");var o=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?o.resolve({list:[],total:0,allIds:[]}):o.resolve(this.getAll("LeaveRequest",t,n,r,s,"getFull",i)),o.promise},balanceChangeByAbsenceType:function(t,n,r,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var o={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",o,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(t){e.debug("LeaveRequestAPI.calculateBalanceChange",t);var n=a.defer();return!t||t.contact_id&&t.from_date&&t.from_date_type||n.reject("contact_id, from_date and from_date_type in params are mandatory"),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){n.resolve(e.values)}),n.promise},create:function(t){e.debug("LeaveRequestAPI.create",t);var n=a.defer();return t&&(t.to_date&&!t.to_date_type?n.reject("to_date_type is mandatory"):t.contact_id&&t.from_date&&t.from_date_type&&t.status_id||n.reject("contact_id, from_date, status_id and from_date_type params are mandatory")),this.sendPOST("LeaveRequest","create",t).then(function(e){n.resolve(e.values[0])}),n.promise},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","get",{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","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI",function(t,n,a,r,s,i){function o(e){return c(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 u(e){return c(e).then(function(e){return this.status_id===e.value}.bind(this))}function l(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function c(e){return a.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return t.find(function(t){return t.name===e})})}function d(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),t.all(n)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},cancel:function(){return o.call(this,r.statusNames.cancelled)},approve:function(){return o.call(this,r.statusNames.approved)},reject:function(){return o.call(this,r.statusNames.rejected)},sendBack:function(){return o.call(this,r.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return t.all([d.call(this),l.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([d.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){return t.comment_id?void(t.toBeDeleted=!0):void(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)},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return u.call(this,r.statusNames.approved)},isAwaitingApproval:function(){return u.call(this,r.statusNames.awaitingApproval)},isCancelled:function(){return u.call(this,r.statusNames.cancelled)},isRejected:function(){return u.call(this,r.statusNames.rejected)},isSentBack:function(){return u.call(this,r.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):n(r.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)):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,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,s,i){return n.all(this.processFilters(e),t,r,s,i).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)},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange"),n.calculateBalanceChange(t)},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,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 r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(s.serverDateFormat),i={date:r};return a.all(i).then(function(e){return!!e.length})}})}])}),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/calendar-model","leave-absences/shared/models/entitlement-model","leave-absences/shared/models/leave-request-model","leave-absences/shared/models/public-holiday-model"],function(e,t,n,a){"use strict";function r(t,r,s,i,o,u,l,c,d,f,m,h,p,v,g,b,y){function _(){var e=this.requestStatuses[y.statusNames.awaitingApproval].value;je.status_id===e&&e!==this.request.status_id&&f.publish("ManagerBadge:: Update Count")}function $(){var e=this;return e._setDateAndTypes(),q.call(e)?(e.loading.showBalanceChange=!0,g.calculateBalanceChange(L.call(e)).then(function(t){t&&(e.balance.change=t,e._calculateOpeningAndClosingBalance(),ce.call(e)),e.loading.showBalanceChange=!1}).catch(B.bind(e))):r.resolve()}function q(){return!!(this.request.from_date&&this.request.to_date&&this.request.from_date_type&&this.request.to_date_type)}function w(){var e=q.call(this);return this.isMode("edit")&&(e=e&&N.call(this)),this.canManage&&this.requestStatuses&&(e=e&&!!this.getStatusFromValue(this.newStatusOnSave)),e=e&&!!this.period.id,e&&!this.isMode("view")}function A(){this._reset(),this._calculateOpeningAndClosingBalance()}function P(){this.isSelfRecord?this.request.status_id=this.requestStatuses[y.statusNames.awaitingApproval].value:this.canManage&&(this.request.status_id=this.newStatusOnSave||this.request.status_id)}function C(){this.errors=[]}function D(){return this.request.create().then(ge).then(function(){le.call(this,"LeaveRequest::new")}.bind(this))}function S(){o.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return this.directiveOptions.leaveRequest.delete().then(function(){this.dismissModal(),s.$emit("LeaveRequest::deleted",this.directiveOptions.leaveRequest)}.bind(this))}.bind(this)})}function R(){this.$modalInstance.dismiss({$value:"cancel"})}function T(e,t){var a;return e?(a=this.requestDayTypes.slice(0),e=this._convertDateToServerFormat(e),b.isPublicHoliday(e).then(function(t){return t?a.filter(function(e){return"public_holiday"===e.name}):x.call(this,e,a).then(function(e){return e.length?e:a.filter(function(e){return n.includes(["all_day","half_day_am","half_day_pm"],e.name)})})}.bind(this)).then(function(e){return me.call(this,t,e),e}.bind(this))):r.reject([])}function O(e){return a(e,y.serverDateTimeFormat).format(this.uiOptions.userDateFormat.toUpperCase()+" HH:mm")}function I(){var e=this.getStatusFromValue(this.request.status_id);return k.call(this,e.name)}function k(e){return n.map(Me[e],function(e){return this.requestStatuses[e]}.bind(this))}function x(e,t){return e=a(e),r.all([this.calendar.isNonWorkingDay(e),this.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(t){return t.name===e}):[]})}function L(){return n.pick(this.request,["contact_id","from_date","from_date_type","to_date","to_date_type"])}function M(){return n.find(this.absenceTypes,function(e){return e.id===this.request.type_id}.bind(this))}function E(){return!this.request||e.equals({},this.requestStatuses)?[]:this.request.status_id?I.call(this):k.call(this,"none")}function j(e){return n.find(this.requestStatuses,function(t){return t.value===e})}function B(e){this.errors=n.isArray(e)?e:[e],this.loading.showBalanceChange=!1,this.loading.absenceTypes=!1,this.loading.fromDayTypes=!1,this.loading.toDayTypes=!1,this.submitting=!1}function N(){return!e.equals(je,this.request.attributes())||this.fileUploader&&0!==this.fileUploader.queue.length||this.canManage&&this.newStatusOnSave}function F(){this.period=n.find(this.absencePeriods,function(e){return e.current})}function U(){var e=this;return e.postContactSelection=!0,e.request.contact_id?r.all([e._loadAbsenceTypes(),e._loadCalendar()]).then(function(){return ne.call(e)}).then(function(){return W.call(e)}).then(function(){return he.call(e),K.call(e),H.call(e),e.isMode("edit")&&pe.call(e),e.postContactSelection=!1,e.calculateBalanceChange()}).catch(function(e){if(e!==Ve)return r.reject(e)}):r.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Me.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Me.awaiting_approval=e,Me.more_information_required=e,Me.rejected=e,Me.approved=e,Me.cancelled=[y.statusNames.awaitingApproval].concat(e)}function H(){return this.canManage?i.find(this.request.contact_id).then(function(e){this.contactName=e.display_name}.bind(this)):r.resolve()}function W(){if(this.isMode("create"))return r.resolve();var e=this.request.attributes();return this.uiOptions.fromDate=this._convertDateFormatFromServer(this.request.from_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.fromDate,"from").then(function(){return this.request.to_date=e.to_date,this.request.to_date_type=e.to_date_type,this.uiOptions.toDate=this._convertDateFormatFromServer(this.request.to_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.toDate,"to")}.bind(this))}function G(){Be.push(s.$on("LeaveRequestPopup::requestObjectUpdated",pe.bind(this)),s.$on("LeaveRequestPopup::childComponent::register",function(){Ee++}))}function z(){if(this.request.id){this.mode="edit";var e=[this.requestStatuses[y.statusNames.approved].value,this.requestStatuses[y.statusNames.adminApproved].value,this.requestStatuses[y.statusNames.rejected].value,this.requestStatuses[y.statusNames.cancelled].value];this.isRole("staff")&&e.indexOf(this.request.status_id)>-1&&(this.mode="view")}else this.mode="create"}function Y(){return Fe="staff",d(y.permissions.admin.administer).then(function(e){Fe=e?"admin":Fe}).then(function(){return"staff"===Fe&&d(y.permissions.ssp.manage).then(function(e){Fe=e?"manager":Fe})}).finally(function(){this.canManage=this.isRole("manager")||this.isRole("admin"),this.isSelfRecord=this.directiveOptions.isSelfRecord}.bind(this))}function K(){(this.isRole("admin")||this.isMode("create")&&this.isRole("manager"))&&(this.newStatusOnSave=this.requestStatuses[y.statusNames.approved].value)}function J(e){var t=this.getStatusFromValue(this.request.status_id);return!!t&&t.name===e}function X(e){return this.request.request_type===e}function Z(e){return this.mode===e}function Q(e){return Fe===e}function ee(e,t){var n=this.period.id;return t=t||"from",this.loading[t+"DayTypes"]=!0,this._checkAndSetAbsencePeriod(e).then(function(){var e=n===this.period.id;if(!e)return this.uiOptions.multipleDays&&"from"===t&&(this.uiOptions.showBalance=!1,this.uiOptions.toDate=null,this.request.to_date=null,this.request.to_date_type=null),r.all([this._loadAbsenceTypes(),this._loadCalendar()])}.bind(this)).then(function(){return this._setMinMaxDate(),T.call(this,e,t)}.bind(this)).finally(function(){this.loading[t+"DayTypes"]=!1}.bind(this))}function te(){var e=this;return u.all().then(function(t){e.absencePeriods=t})}function ne(){var e=this;return c.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(t){e.requestDayTypes=t})}function ae(){return v.get().then(function(e){Ne=e.contactId})}function re(){return this.directiveOptions.selectedContactId?i.find(this.directiveOptions.selectedContactId).then(function(e){this.managedContacts=[e]}.bind(this)):this.isRole("admin")?i.all().then(function(e){this.managedContacts=n.remove(e.list,function(e){return e.id!==Ne})}.bind(this)):i.find(Ne).then(function(e){return e.leaveManagees()}).then(function(e){this.managedContacts=e}.bind(this))}function se(){var e=this;return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){e.requestStatuses=n.indexBy(t,"name")})}function ie(e,t){return t.map(function(t){var a=n.find(e,function(e){return e.id===t.type_id});return{id:t.type_id,title:a.title+" ( "+t.remainder.current+" ) ",remainder:t.remainder.current,allow_overuse:a.allow_overuse}})}function oe(){this.$modalInstance.close({$value:this.request})}function ue(){var e=(this.currentPage-1)*this.numPerPage,t=e+this.numPerPage;this.filteredbreakdown=Ue.balance.change.breakdown.slice(e,t)}function le(e){_.call(this),s.$emit(e,this.request),this.errors=[],this.ok()}function ce(){this.pagination.totalItems=this.balance.change.breakdown.length,this.pagination.filteredbreakdown=this.balance.change.breakdown,this.pagination.pageChanged()}function de(e){var t=this;return h.all({contact_id:t.request.contact_id,period_id:t.period.id,type_id:{IN:e.ids}},!0).then(function(n){if(t.absenceTypes=ie(e.types,n),!t.absenceTypes.length)return r.reject(Ve)})}function fe(){(this.isMode("edit")&&this.request.from_date===this.request.to_date||this.isMode("create")&&this.isLeaveType("sickness"))&&(this.uiOptions.multipleDays=!1)}function me(e,t){var a="request"+n.startCase(e)+"DayTypes";this[a]=t,this.isMode("create")&&(this.request[e+"_date_type"]=this[a][0].value)}function he(){this.isMode("create")?(this.selectedAbsenceType=this.absenceTypes[0],this.request.type_id=this.selectedAbsenceType.id):this.selectedAbsenceType=M.call(this)}function pe(){je=e.copy(this.request.attributes())}function ve(){var e=this.request.status_id;if(!this.isMode("view")&&!this.submitting)return this.submitting=!0, -P.call(this),qe.call(this).then(function(){return this.isMode("edit")?$e.call(this):D.call(this)}.bind(this)).catch(function(t){this.request.status_id=e,t&&B.call(this,t)}.bind(this)).finally(function(){this.submitting=!1}.bind(this))}function ge(){function e(e){e&&n.push(e),++a===Ee&&(be(),n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Ee>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function be(){n.forEach(Be,function(e){e()})}function ye(e,t){return this.loadAbsencePeriodDatesTypes(e,t).then(function(){return this.updateBalance()}.bind(this)).catch(function(e){B.call(this,e),this._setDateAndTypes()}.bind(this))}function _e(){this.selectedAbsenceType=M.call(this),this.balance.opening=this.selectedAbsenceType.remainder,this.calculateBalanceChange()}function $e(){return this.request.update().then(ge).then(function(){this.isRole("manager")?le.call(this,"LeaveRequest::updatedByManager"):(this.isRole("staff")||this.isRole("admin"))&&le.call(this,"LeaveRequest::edit")}.bind(this))}function qe(){return this.balance.closing<0&&"0"===this.selectedAbsenceType.allow_overuse?r.reject(["You cannot make a request for this leave type at this time as this would leave you with a negative balance"]):this.request.isValid()}function we(){this.balance.opening=this.selectedAbsenceType.remainder,this.balance.closing=this.balance.opening+this.balance.change.amount}function Ae(e){var t=a(e).format(this.uiOptions.userDateFormat.toUpperCase());return this.period=n.find(this.absencePeriods,function(e){return e.isInPeriod(t)}),this.period?r.resolve(!0):(this.period={},this.loading.fromDayTypes=!1,r.reject("Please change date as it is not in any absence period"))}function Pe(e){return a(e,y.serverDateFormat).toDate()}function Ce(e){return a(e).format(y.serverDateFormat)}function De(){return V.call(this),G.call(this),ae.call(this).then(Y.bind(this)).then(this._initRequest.bind(this)).then(se.bind(this)).then(function(){return z.call(this),this.canManage&&!this.isMode("edit")&&re.call(this)}.bind(this)).then(te.bind(this)).then(function(){F.call(this),this._setMinMaxDate()}.bind(this)).then(function(){if(this.directiveOptions.selectedContactId&&(this.request.contact_id=this.directiveOptions.selectedContactId),fe.call(this),this.request.contact_id)return this.initAfterContactSelection()}.bind(this)).catch(B.bind(this))}function Se(){var e={};return this.directiveOptions.leaveRequest?e=this.directiveOptions.leaveRequest.attributes():this.canManage||(e={contact_id:Ne}),e}function Re(){var e=this;return l.all(e.initParams.absenceType).then(function(t){var n=t.map(function(e){return e.id});return Le={types:t,ids:n},de.call(e,Le)})}function Te(){var e=this;return m.get(e.request.contact_id,e.period.start_date,e.period.end_date).then(function(t){e.calendar=t})}function Oe(){this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date_type=this.request.from_date_type,this.request.to_date=this.request.from_date,this.calculateBalanceChange()}function Ie(){this._setDates(),this.uiOptions.multipleDays?this.uiOptions.showBalance=!!(this.request.from_date&&this.request.from_date_type&&this.request.to_date&&this.request.to_date_type&&this.period.id):(this.uiOptions.fromDate&&(this.request.to_date_type=this.request.from_date_type),this.uiOptions.showBalance=!!this.request.from_date&&!!this.request.from_date_type&&!!this.period.id)}function ke(){this.request.from_date=this.uiOptions.fromDate?this._convertDateToServerFormat(this.uiOptions.fromDate):null,this.request.to_date=this.uiOptions.toDate?this._convertDateToServerFormat(this.uiOptions.toDate):null,!this.uiOptions.multipleDays&&this.uiOptions.fromDate&&(this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date=this.request.from_date)}function xe(){if(this.uiOptions.fromDate){var e=a(this.uiOptions.fromDate).add(1,"d").toDate();this.uiOptions.date.to.options.minDate=e,this.uiOptions.date.to.options.initDate=e,this.uiOptions.toDate&&a(this.uiOptions.toDate).isBefore(this.uiOptions.fromDate)&&(this.uiOptions.toDate=this.uiOptions.fromDate)}else this.uiOptions.date.to.options.minDate=this._convertDateFormatFromServer(this.period.start_date),this.uiOptions.date.to.options.initDate=this.uiOptions.date.to.options.minDate;this.uiOptions.date.to.options.maxDate=this._convertDateFormatFromServer(this.period.end_date)}t.debug("RequestCtrl");var Le,Me={},Ee=0,je={},Be=[],Ne="",Fe="",Ue=this,Ve="No entitlement";this.absencePeriods=[],this.absenceTypes=[],this.calendar={},this.canManage=!1,this.contactName=null,this.errors=[],this.fileUploader=null,this.isSelfRecord=!1,this.managedContacts=[],this.mode="",this.newStatusOnSave=null,this.period={},this.postContactSelection=!1,this.requestDayTypes=[],this.requestStatuses={},this.selectedAbsenceType={},this.statusNames=y.statusNames,this.submitting=!1,this.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},this.loading={absenceTypes:!0,showBalanceChange:!1,fromDayTypes:!1,toDayTypes:!1},this.pagination={currentPage:1,filteredbreakdown:this.balance.change.breakdown,numPerPage:7,totalItems:this.balance.change.breakdown.length,pageChanged:ue},this.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:p.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}}}},this.changeInNoOfDays=A,this.calculateBalanceChange=$,this.canSubmit=w,this.closeAlert=C,this.deleteLeaveRequest=S,this.dismissModal=R,this.formatDateTime=O,this.getStatuses=E,this.getStatusFromValue=j,this.initAfterContactSelection=U,this.isLeaveStatus=J,this.isLeaveType=X,this.isMode=Z,this.isRole=Q,this.ok=oe,this.submit=ve,this.loadAbsencePeriodDatesTypes=ee,this.updateAbsencePeriodDatesTypes=ye,this.updateBalance=_e,this._calculateOpeningAndClosingBalance=we,this._checkAndSetAbsencePeriod=Ae,this._convertDateToServerFormat=Ce,this._convertDateFormatFromServer=Pe,this._init=De,this._initRequestAttributes=Se,this._loadCalendar=Te,this._loadAbsenceTypes=Re,this._reset=Oe,this._setDates=ke,this._setDateAndTypes=Ie,this._setMinMaxDate=xe}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","Contact","dialog","AbsencePeriod","AbsenceType","api.optionGroup","checkPermissions","pubSub","Calendar","Entitlement","HR_settings","Session","LeaveRequest","PublicHoliday","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/leave-request.controller",["leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/leave-request.instance"],function(e){function t(e,t,n,a,r){function s(){var e=o._initRequestAttributes();o.request=r.init(e)}t.debug("LeaveRequestCtrl");var i=e("RequestCtrl"),o=Object.create(i);return o.directiveOptions=a,o.$modalInstance=n,o.initParams={absenceType:{is_sick:!1}},o._initRequest=s,function(){o.loading.absenceTypes=!0,o._init().finally(function(){o.loading.absenceTypes=!1})}(),o}e.controller("LeaveRequestCtrl",t),t.$inject=["$controller","$log","$uibModalInstance","directiveOptions","LeaveRequestInstance"]}),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(){var e=this.sickness_required_documents?this.sickness_required_documents.split(","):[];return e},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/controllers/sub-controllers/sick-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/sickness-request.instance"],function(e,t){function n(t,n,a,r,s,i,o){function u(){return h.canSubmit.call(this)&&!!p.request.sickness_reason}function l(t){var n=p.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(p.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){p.sicknessDocumentTypes=e})}function f(){return s.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){p.sicknessReasons=e.indexBy(t,"name")})}function m(){var e=p._initRequestAttributes();p.request=o.init(e)}n.debug("SicknessRequestCtrl");var h=t("RequestCtrl"),p=Object.create(h);return p.directiveOptions=i,p.$modalInstance=r,p.initParams={absenceType:{is_sick:!0}},p.canSubmit=u,p.isChecked=l,p.isDocumentInRequest=c,p._initRequest=m,function(){p.loading.absenceTypes=!0,p._init().then(function(){return a.all([d(),f()])}).finally(function(){p.loading.absenceTypes=!1})}(),p}t.controller("SicknessRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","directiveOptions","SicknessRequestInstance"]}),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/sub-controllers/toil-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/toil-request.instance"],function(e,t){function n(t,n,a,r,s,i,o,u){function l(){P.request.toil_to_accrue&&(P.loading.showBalanceChange=!0,P._setDateAndTypes(),P.balance.change.amount=+P.request.toil_to_accrue,P._calculateOpeningAndClosingBalance(),P.uiOptions.showBalance=!0,P.request.to_date_type=P.request.from_date_type="1",P.loading.showBalanceChange=!1)}function c(){return!P.canManage&&P.request.id?a.resolve(P.request.toil_expiry_date):P.requestCanExpire?p().catch(function(e){return e.length&&(P.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(P.request.type_id,e)}).then(function(e){return P.request.toil_expiry_date=e,P.uiOptions.expiryDate=new Date(e),e}):(P.request.toil_expiry_date=!1,a.resolve(!1))}function d(){return P.uiOptions.multipleDays&&P.request.to_date||!P.uiOptions.multipleDays&&P.request.from_date}function f(){return A.canSubmit.call(this)&&!!P.request.toil_duration&&!!P.request.toil_to_accrue&&!!P.request.from_date&&!!P.request.to_date}function m(){A.changeInNoOfDays.call(this),d()&&P.calculateToilExpiryDate()}function h(){P.request.toil_expiry_date=!1,P.uiOptions.expiryDate=null}function p(){return v(P.uiOptions.multipleDays?{hasErrors:!P.request.to_date&&!P.request.from_date,label:"To Date",value:P.request.to_date}:{hasErrors:!P.request.from_date,label:"From Date",value:P.request.from_date})}function v(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(e.value):a.reject([])}function g(){P.canManage&&(P.uiOptions.expiryDate=P._convertDateFormatFromServer(P.request.toil_expiry_date))}function b(){return i.canExpire(P.request.type_id).then(function(e){P.requestCanExpire=e})}function y(e){var t=P.period.id;return P._checkAndSetAbsencePeriod(e).then(function(){var e=t===P.period.id;if(!e)return P.uiOptions.multipleDays&&(P.uiOptions.showBalance=!1,P.uiOptions.toDate=null,P.request.to_date=null),a.all([P._loadAbsenceTypes(),P._loadCalendar()])})}function _(){return s.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){P.toilAmounts=e.indexBy(t,"value")})}function $(e){return P.loadAbsencePeriodDatesTypes().then(function(){P._setMinMaxDate(),P._setDates(),P.updateBalance(),P.calculateToilExpiryDate()}).catch(function(e){P.errors=[e]})}function q(){P.uiOptions.expiryDate&&(P.request.toil_expiry_date=P._convertDateToServerFormat(P.uiOptions.expiryDate))}function w(){var e=P._initRequestAttributes();P.request=u.init(e),P.request.to_date_type=P.request.from_date_type="1"}n.debug("ToilRequestCtrl");var A=t("RequestCtrl"),P=Object.create(A);return P.requestCanExpire=!0,P.directiveOptions=o,P.$modalInstance=r,P.initParams={absenceType:{allow_accruals_request:!0}},P.calculateBalanceChange=l,P.calculateToilExpiryDate=c,P.canSubmit=f,P.changeInNoOfDays=m,P.clearExpiryDate=h,P.loadAbsencePeriodDatesTypes=y,P.updateAbsencePeriodDatesTypes=$,P.updateExpiryDate=q,P._initRequest=w,function(){P.loading.absenceTypes=!0,P._init().then(function(){return b()}).then(function(){return g(),_()}).finally(function(){P.loading.absenceTypes=!1})}(),P}t.controller("ToilRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","AbsenceType","directiveOptions","TOILRequestInstance"]}),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-popup.service",["common/lodash","leave-absences/shared/modules/services","common/services/notification.service"],function(e,t){"use strict";function n(t,n,a,r,s,i,o,u,l,c){function d(e){return l.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function f(e,t){return t?t.request_type:e||null}function m(t,a,r,i){var u=e.capitalize(f(a,t))+"RequestCtrl";s.open({appendTo:n.children().eq(0),templateUrl:o.sharedPathTpl+"directives/leave-request-popup/leave-request-popup.html",controller:u,controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveRequest:t,selectedContactId:r,isSelfRecord:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function h(e){return c.find(e).then(function(e){return d(e).then(function(t){t?m(e,e.request_type,e.contact_id,"my-leave"===a.section):i.error("Error","You dont have permission to see this leave request")})}).catch(function(e){i.error("Error",e)})}return t.debug("LeavePopup"),{openModal:m,openModalByID:h}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$q","$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",function(e,t){e.debug("Component: manager-leave-container"),t.section="manager-leave"}],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,s,i){s.debugEnabled(i.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.balance-report",{url:"/balance-report",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","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-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/leave-request.controller","leave-absences/shared/controllers/sub-controllers/sick-request.controller","leave-absences/shared/controllers/sub-controllers/toil-request.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.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(){}); \ No newline at end of file +if(U(n)&&0===n.length)return n;n=r(n);var a=h(n,e);return t===!0?0===m(a,i).length:s(a)}}function u(e){return function(t,n){var a=r(t),s=r(n);if(a.length!==s.length)return!1;for(var i=0;i=":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.defaults(t||{},{is_active:!0})).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(r.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",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/absence-type-api","leave-absences/shared/instances/absence-type.instance"],function(e){"use strict";e.factory("AbsenceType",["$log","Model","AbsenceTypeAPI","AbsenceTypeInstance",function(e,t,n,a){return e.debug("AbsenceType"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return a.init(e,!0)})})},calculateToilExpiryDate:function(e,t,a){return n.calculateToilExpiryDate(e,t,a)},canExpire:function(e){return n.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})}})}])}),define("leave-absences/shared/modules/components",["common/angular"],function(e){return e.module("leave-absences.components",[])}),define("leave-absences/shared/apis/leave-balance-report.api",["leave-absences/shared/modules/apis","mocks/data/leave-balance-report.data"],function(e,t){"use strict";e.factory("LeaveBalanceReportAPI",["$q","$log","api",function(e,n,a){return a.extend({getAll:function(a,r,s){n.debug("LeaveBalanceReportAPI.all");var i=t.all().values;if(r){var o,u;r.page=r.page||1,r.size=r.size||i.length,u=(r.page-1)*r.size,o=u+r.size,i=i.slice(u,o)}return e.resolve({list:i,total:t.all().values.length,allIds:i.map(function(e){return e.id}).join(",")})}})}])}),define("leave-absences/shared/models/leave-balance-report.model",["leave-absences/shared/modules/models","leave-absences/shared/apis/leave-balance-report.api","common/models/model"],function(e){"use strict";e.factory("LeaveBalanceReport",["Model","LeaveBalanceReportAPI",function(e,t){return e.extend({all:function(e,n,a){return t.getAll(e,n,a)}})}])}),define("leave-absences/shared/components/leave-balance-tab.component",["common/angular","common/lodash","leave-absences/shared/modules/components","leave-absences/shared/models/leave-balance-report.model","common/services/notification.service"],function(e,t,n){function a(n,a,r,s,i){function o(){return a.all({options:{sort:"title ASC"}}).then(function(e){m.absenceTypes=e})}function u(){return i.get().then(function(e){d=e.contact_id})}function l(e){return e=e||1,m.loading.report=!0,r.all({managed_by:d},{page:e,size:f}).then(function(e){m.report=c(e.list),m.reportCount=e.total}).catch(function(e){s.error("Error",e.error_message)}).finally(function(){m.loading.report=!1})}function c(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})}var d,f=50,m=this;m.absenceTypes=[],m.loading={report:!0},m.report=[],m.reportCount=0,function(){m.loading.report=!0;var e=1;n.all([o(),u()]).then(l.bind(this,e)).catch(function(e){s.error("Error",e)})}()}n.component("leaveBalanceTab",{controller:a,controllerAs:"leaveBalanceTab",templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-balance-tab.html"}]}),a.$inject=["$q","AbsenceType","LeaveBalanceReport","notificationService","Session"]}),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"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all().then(function(e){s.lookupContacts=e.list}).then(a)}}}function a(){return t.all(r(),null,"display_name").then(function(e){return e.list})}function r(){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("LeaveCalendarAdminController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,n()}}}n.controller("LeaveCalendarAdminController",["$log","Contact",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(r)}}}function r(){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,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,s,i,o,u,l,c,d,f,m,h,p){function v(){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(R(t)),t.add(1,"month");E.months=e}function g(){i.$new().$watch(function(){return E.selectedMonths},function(t,n){null===n||e.equals(t,n)||O()})}function b(e){x("injected").then(function(){O(e)}).then(function(){E.loading.calendar=!1}),S().then(function(){E.injectMonths=!0})}function y(){L=a("LeaveCalendar"+t.capitalize(M)+"Controller").init(E)}function _(e){return e.current?"Current Period ("+e.title+")":e.title}function $(){return l.all().then(function(e){E.absencePeriods=t.sortBy(e,"start_date"),E.selectedPeriod=t.find(E.absencePeriods,function(e){return!!e.current})}).then(v).then(I)}function q(){return c.all({is_active:!0})}function w(){return m.valuesOf(["hrleaveandabsences_leave_request_status","hrleaveandabsences_leave_request_day_type"])}function A(){return L.loadContacts().then(function(e){E.contacts=e})}function P(){return m.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 f.all()}function D(){return r.all([q(),C(),w()]).then(function(e){E.supportData.absenceTypes=e[0],E.supportData.publicHolidays=e[1],E.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,E.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type})}function S(){var e=r.resolve();return E.injectMonths&&(e=x("destroyed"),E.injectMonths=!1),e}function R(e){return{index:e.month(),year:e.year(),name:e.format("MMM")}}function T(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){E.loading.calendar=!0}).then("period"===e?v:t.noop).then("contacts"===e?A:t.noop).then(function(){b("contacts"===e)})}function O(e){var n=E.selectedMonths.length?E.months.filter(function(e){return t.includes(E.selectedMonths,e.index)}):E.months;i.$emit("LeaveCalendar::showMonths",n,!!e)}function I(){E.selectedMonths=[n().month()]}function k(){return E.roleOverride?r.resolve().then(function(){M=E.roleOverride}):r.all([p(u.permissions.admin.administer),p(u.permissions.ssp.manage)]).then(function(e){M=e[0]?"admin":e[1]?"manager":"staff"})}function x(e){return r(function(n){var a=0,r=i.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===E.months.length&&(r(),n())})})}s.debug("Component: leave-calendar");var L,M,E=this;E.absencePeriods=[],E.contacts=[],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:!1,department:null,level_type:null,location:null,region:null}},E.labelPeriod=_,E.refresh=T,function(){k().then(g).then(y).then(function(){return r.all([A(),$(),D()])}).then(function(){return E.showFilters?P():t.noop}).then(function(){b()}).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","$timeout","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","PublicHoliday","OptionGroup","Calendar","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["leave-absences/shared/modules/components"],function(e){function t(e,t){"use strict";function n(e,n,a,r,s){e.stopPropagation(),t.openModal(n,a,r,s)}e.debug("Component: leave-calendar-day");var a=this;a.openLeavePopup=n}e.component("leaveCalendarDay",{bindings:{contactData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:t}),t.$inject=["$log","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.collapsed=!1,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"],function(e,t,n){function a(n,a,r,s,i,o){function u(e,t){v([t]),x(t)}function l(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:c(e)}}function c(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(B.period.start_date)&&r.isSameOrBefore(B.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function d(e){return E[e]}function f(){return B.showOnlyWithLeaveRequests?B.contacts.filter(function(t){return e.includes(Object.keys(j),t.id)}):B.contacts}function m(e){return t(e,o.serverDateFormat)}function h(e,t){D(t),x(t)}function p(){B.supportData.dayTypes=e.indexBy(B.supportData.dayTypes,"name"),B.supportData.leaveRequestStatuses=e.indexBy(B.supportData.leaveRequestStatuses,"value"),B.supportData.publicHolidays=e.transform(B.supportData.publicHolidays,function(e,t){e[m(t.date).valueOf()]=t},{})}function v(e){return e.forEach(function(e){var t=$(e);j[e.contact_id]=j[e.contact_id]||{},t.forEach(function(t){j[e.contact_id][t.date]=e})}),a.resolve()}function g(){M.push(r.$on("LeaveCalendar::showMonths",O)),M.push(r.$on("LeaveRequest::new",u)),M.push(r.$on("LeaveRequest::edit",k)),M.push(r.$on("LeaveRequest::updatedByManager",k)),M.push(r.$on("LeaveRequest::deleted",h))}function b(e,n,a){var r=B.supportData.dayTypes[e];return t(a).isSame(n.from_date)?r.value===n.from_date_type:t(a).isSame(n.to_date)?r.value===n.to_date_type:void 0}function y(e){var t=B.supportData.leaveRequestStatuses[e.status_id];return t.name===o.statusNames.awaitingApproval}function _(e){return!!B.supportData.publicHolidays[m(e).valueOf()]}function $(n){for(var a=[],r=t(n.from_date).clone(),s=t(n.to_date);r.isSameOrBefore(s);)r.month()===B.month.index&&r.year()===B.month.year&&a.push(e.find(B.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function q(t){return e.find(j[t.contact_id],function(e){return t.id===e.id})}function w(t){var n=e.find(B.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function A(){return B.month.loading=!0,a.all([C(),P()]).then(function(){return T()}).then(function(){L=!0}).then(function(){B.month.loading=!1})}function P(){var e={from:B.month.days[0].date,to:B.month.days[B.month.days.length-1].date};return i.all({from_date:e,to_date:e,options:{or:[["from_date","to_date"]]},status_id:{IN:[w(o.statusNames.approved),w(o.statusNames.adminApproved),w(o.statusNames.awaitingApproval)]},contact_id:{IN:B.contacts.map(function(e){return e.id})}},null,null,null,!1).then(function(e){return v(e.list)})}function C(){var t=B.month.days[0].date,n=B.month.days[B.month.days.length-1].date;return s.get(B.contacts.map(function(e){return e.id}),t,n).then(function(t){E=e.indexBy(t,"contact_id")})}function D(t){j[t.contact_id]=e.omit(j[t.contact_id],function(e){return e.id===t.id})}function S(){r.$emit("LeaveCalendar::monthDestroyed"),M.map(function(e){e()})}function R(t,n,r){var s,i;return t.contactsData[n]=t.contactsData[n]||{},i=d(n),s=r===!0?a.resolve():a.all([i.isWeekend(m(t.date)),i.isNonWorkingDay(m(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:_(t.date)})}),s.then(function(){return j[n]?j[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?I(a):null,isAccruedTOIL:a?a.balance_change>0:null,isRequested:a?y(a):null,isAM:a?b("half_day_am",a,t.date):null,isPM:a?b("half_day_pm",a,t.date):null})})}function T(){return a.all(B.month.days.map(function(e){return a.all(B.contacts.map(function(t){return R(e,t.id)}))}))}function O(t,n,a){var r=!!e.find(n,function(e){return e.index===B.month.index});r?(B.currentPage=0,B.visible=!0,(a||!L)&&A()):B.visible=!1}function I(t){var n=e.find(B.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 k(e,t){var n=q(t);h(null,n),u(null,t)}function x(e){return a.all($(e).map(function(t){return R(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var L=!1,M=[],E={},j={},B=this;B.currentPage=0,B.pageSize=20,B.visible=!1,B.showContactName=!!B.showContactName,B.showOnlyWithLeaveRequests=!!B.showOnlyWithLeaveRequests,B.$onDestroy=S,B.contactsList=f,function(){var e=t().month(B.month.index).year(B.month.year);p(),g(),B.month=l(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",month:"<",period:"<",showContactName:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","shared-settings",a]})}),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"],function(e,t,n){function a(n,a,r,s,i,o,u){function l(e){var t=y[e].dialog;v=g.leaveRequest.status_id,r.open({title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return g.leaveRequest[e]().then(function(){m(e)}).catch(function(e){u.error("Error:",e)})}})}function c(){var e=g.absenceTypes[g.leaveRequest.type_id].allow_request_cancelation;return"admin"===g.role||"manager"===g.role||("3"===e?t().isBefore(g.leaveRequest.from_date):"2"===e)}function d(){Array.isArray(g.leaveRequestStatuses)&&(g.leaveRequestStatuses=e.indexBy(g.leaveRequestStatuses,"value")),Array.isArray(g.absenceTypes)&&(g.absenceTypes=e.indexBy(g.absenceTypes,"id"))}function f(e,t,n,a,r){e.stopPropagation(),s.openModal(t,n,a,r)}function m(t){var n=e.find(g.leaveRequestStatuses,function(e){return e.name===o.statusNames.awaitingApproval}).value;v===n&&i.publish("ManagerBadge:: Update Count"),a.$emit("LeaveRequest::"+("delete"===t?"deleted":"edit"),g.leaveRequest)}function h(){var t=g.leaveRequestStatuses[g.leaveRequest.status_id].name,n=e.compact(e.map(y,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!c()&&e.pull(n,"cancel"),"admin"!==g.role&&e.pull(n,"delete"),"staff"===g.role&&e.pull(n,"approve","reject"),"staff"!==g.role&&p(n),g.allowedActions=e.map(n,function(e){return{key:e,label:y[e].label,isDirectAction:y[e].isDirectAction}})}function p(t){e.each(t,function(e,n){"edit"===e&&(t[n]="respond"),"respond"===e&&(t[n]="edit")})}n.debug("Component: leave-request-action-dropdown");var v,g=this,b=o.statusNames,y={edit:{label:"Edit",allowedStatuses:[b.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[b.moreInformationRequired]},view:{label:"View",allowedStatuses:[b.approved,b.rejected,b.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[b.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[b.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[b.awaitingApproval,b.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[b.awaitingApproval,b.moreInformationRequired,b.approved,b.rejected,b.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};g.allowedActions=[],g.action=l,g.openLeavePopup=f,function(){d(),h()}()}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","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,s,i,o){function u(){var t=e.indexBy(f.request.comments,"contact_id"),n=Object.keys(t);return i.all({id:{IN:n}},{page:1,size:0}).then(function(t){f.comment.contacts=e.indexBy(t.list,"contact_id")})}function l(){return f.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),f.request.comments.length&&u()})}function c(){return f.loading.component=!0,o.get().then(function(e){d=e.contactId}).then(function(){f.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var d=null,f=this;f.loading={component:!0},f.comment={text:"",contacts:{}},function(){l(),c()}(),f.addComment=function(){f.request.comments.push({contact_id:d,leave_request_id:f.request.id,text:f.comment.text}),f.comment.text=""},f.formatDateTime=function(e){return t.utc(e,s.serverDateTimeFormat).local().format(r.DATE_FORMAT.toUpperCase()+" HH:mm")},f.getActiveComments=function(){return f.request.comments.filter(function(e){return!e.toBeDeleted})},f.getCommentorName=function(e){return e===d?"Me":f.comment.contacts[e]?f.comment.contacts[e].display_name:void 0},f.isMode=function(e){return f.mode===e},f.orderComment=function(e){return t(e.created_at,s.serverDateTimeFormat)},f.removeCommentVisibility=function(e){return!e.comment_id||f.canManage}}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"directives/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","HR_settings","shared-settings","Contact","Session",a]})}),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,s,i,o,u,l){function c(){return e.filter(w.request.files,function(e){ +return e.toBeDeleted})}function d(){return w.fileUploader&&w.fileUploader.queue?w.fileUploader.queue:[]}function f(){$.push(a.$on("LeaveRequestPopup::submit",y))}function m(){v().then(function(){w.fileUploader=u.uploader({entityTable:"civicrm_hrleaveandabsences_leave_request",crmAttachmentToken:i.attachmentToken,queueLimit:i.fileUploader.queueLimit,allowedMimeTypes:q})})}function h(){return _.length>0?_.map(function(e){return e.label}).join(", "):""}function p(){return w.request.loadAttachments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function v(){return r.all(_.map(function(e){return l.getMimeTypeFor(e.label).then(function(t){q[e.label]=t})})).catch(function(){q=null})}function g(){return o.valuesOf("safe_file_extension").then(function(e){_=e})}function b(){e.forEach($,function(e){e()})}function y(e,t){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var _=[],$=[],q={},w=Object.create(this);return w.filesLoaded=!1,w.today=Date.now(),w.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",w.userDateFormat=s.DATE_FORMAT,w.listFileTypes=h,w.$onDestroy=b,w.canUploadMore=function(){return w.getFilesCount()0&&F.filters.leaveRequest.contact_id?F.filters.leaveRequest.contact_id:{IN:F.filteredUsers.map(function(e){return e.id})}}function x(e){var t=[y(o.statusNames.moreInformationRequired),y(o.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=x(n)),n.length)return{IN:n}}function M(e,t,n){e="number"==typeof e?e:1,t&&(F.filters.leaveRequest.leaveStatus=U),(e<=F.totalNoOfPages()||0===F.totalNoOfPages())&&(F.pagination.page=e,A(n))}function E(e){F.filters.leaveRequest.leaveStatus=e,F.refresh(1,!1,"table")}function j(e){F.filters.leaveRequest.assignedTo=e,F.refresh()}function B(){a.$on("LeaveRequest::updatedByManager",function(){F.refresh()}),a.$on("LeaveRequest::new",function(){F.refresh()}),a.$on("LeaveRequest::edit",function(){F.refresh()}),a.$on("LeaveRequest::deleted",function(){F.refresh()})}function N(){return Math.ceil(F.leaveRequests.table.total/F.pagination.size)}t.debug("Component: manage-leave-requests");var F=this,U={name:"all",label:"All"};F.absencePeriods=[],F.absenceTypes=[],F.filteredUsers=[],F.isFilterExpanded=!1,F.isAdmin=!1,F.leaveRequests={table:{list:[]},filter:{list:[]}},F.leaveRequestStatuses=[U],F.loading={content:!0,page:!0,table:!0},F.pagination={page:1,size:7},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:"me"}},F.filtersByAssignee=[{type:"me",label:"Assigned To Me"},{type:"unassigned",label:"Unassigned"},{type:"all",label:"All"}],F.clearStaffSelection=f,F.filterLeaveRequestByStatus=h,F.getAbsenceTypesByID=p,F.getArrayOfSize=v,F.getLeaveStatusByValue=g,F.getNavBadge=b,F.getUserNameByID=_,F.labelPeriod=$,F.openLeavePopup=I,F.refresh=M,F.refreshWithFilter=E,F.refreshWithFilterByAssignee=j,F.totalNoOfPages=N,function(){s(o.permissions.admin.administer).then(function(e){F.isAdmin=e,n.all([q(),w(),T(),P(),S(),D(),O()]).then(function(){F.loading.page=!1,A()}),B()})}()}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"]}),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,s,i){return this.sendPOST("ContactWorkPattern","create",e.assign({},i,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,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,r,s){return t.debug("WorkPatternAPI.getCalendar",n,a,r,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{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,s,i){function o(t,n){return l().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,s.serverDateFormat).clone()}function l(){return c=c||i.valuesOf("hrleaveandabsences_work_day_type")}var c;return r.extend({defaultCustomData:function(){return{days:[]}},isNonWorkingDay:function(e){return o.call(this,e,"non_working_day")},isWeekend:function(e){return o.call(this,e,"weekend")},isWorkingDay:function(e){return o.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,s,i,o){return t.debug("Calendar.get"),a.getCalendar(n,s,i,o).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})}})}])}),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/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance",function(t,n,a,r){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)})})}})}])}),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,s,i){e.debug("LeaveRequestAPI.all");var o=a.defer();return t&&t.contact_id&&t.contact_id.IN&&0===t.contact_id.IN.length?o.resolve({list:[],total:0,allIds:[]}):o.resolve(this.getAll("LeaveRequest",t,n,r,s,"getFull",i)),o.promise},balanceChangeByAbsenceType:function(t,n,r,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var i=a.defer();t&&n||i.reject("contact_id and period_id are mandatory");var o={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",o,!1).then(function(e){i.resolve(e.values)}),i.promise},calculateBalanceChange:function(t){e.debug("LeaveRequestAPI.calculateBalanceChange",t);var n=a.defer();return!t||t.contact_id&&t.from_date&&t.from_date_type||n.reject("contact_id, from_date and from_date_type in params are mandatory"),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){n.resolve(e.values)}),n.promise},create:function(t){e.debug("LeaveRequestAPI.create",t);var n=a.defer();return t&&(t.to_date&&!t.to_date_type?n.reject("to_date_type is mandatory"):t.contact_id&&t.from_date&&t.from_date_type&&t.status_id||n.reject("contact_id, from_date, status_id and from_date_type params are mandatory")),this.sendPOST("LeaveRequest","create",t).then(function(e){n.resolve(e.values[0])}),n.promise},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","get",{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","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI",function(t,n,a,r,s,i){function o(e){return c(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 u(e){return c(e).then(function(e){return this.status_id===e.value}.bind(this))}function l(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(i.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function c(e){return a.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return t.find(function(t){return t.name===e})})}function d(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return i.saveComment(e,t)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return i.deleteComment(e.comment_id)})),t.all(n)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},cancel:function(){return o.call(this,r.statusNames.cancelled)},approve:function(){return o.call(this,r.statusNames.approved)},reject:function(){return o.call(this,r.statusNames.rejected)},sendBack:function(){return o.call(this,r.statusNames.moreInformationRequired)},update:function(){return i.update(this.toAPI()).then(function(){return t.all([d.call(this),l.call(this)])}.bind(this))},create:function(){return i.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([d.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){return t.comment_id?void(t.toBeDeleted=!0):void(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)},isValid:function(){return i.isValid(this.toAPI())},isApproved:function(){return u.call(this,r.statusNames.approved)},isAwaitingApproval:function(){return u.call(this,r.statusNames.awaitingApproval)},isCancelled:function(){return u.call(this,r.statusNames.cancelled)},isRejected:function(){return u.call(this,r.statusNames.rejected)},isSentBack:function(){return u.call(this,r.statusNames.moreInformationRequired)},loadComments:function(){return this.id?i.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):n(r.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)):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,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,s,i){return n.all(this.processFilters(e),t,r,s,i).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)},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange"),n.calculateBalanceChange(t)},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,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 r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(s.serverDateFormat),i={date:r};return a.all(i).then(function(e){return!!e.length})}})}])}),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/calendar-model","leave-absences/shared/models/entitlement-model","leave-absences/shared/models/leave-request-model","leave-absences/shared/models/public-holiday-model"],function(e,t,n,a){"use strict";function r(t,r,s,i,o,u,l,c,d,f,m,h,p,v,g,b,y){function _(){var e=this.requestStatuses[y.statusNames.awaitingApproval].value;je.status_id===e&&e!==this.request.status_id&&f.publish("ManagerBadge:: Update Count")}function $(){var e=this;return e._setDateAndTypes(),q.call(e)?(e.loading.showBalanceChange=!0,g.calculateBalanceChange(L.call(e)).then(function(t){t&&(e.balance.change=t,e._calculateOpeningAndClosingBalance(),ce.call(e)),e.loading.showBalanceChange=!1}).catch(B.bind(e))):r.resolve()}function q(){return!!(this.request.from_date&&this.request.to_date&&this.request.from_date_type&&this.request.to_date_type)}function w(){var e=q.call(this);return this.isMode("edit")&&(e=e&&N.call(this)),this.canManage&&this.requestStatuses&&(e=e&&!!this.getStatusFromValue(this.newStatusOnSave)),e=e&&!!this.period.id,e&&!this.isMode("view")}function A(){this._reset(),this._calculateOpeningAndClosingBalance()}function P(){this.isSelfRecord?this.request.status_id=this.requestStatuses[y.statusNames.awaitingApproval].value:this.canManage&&(this.request.status_id=this.newStatusOnSave||this.request.status_id)}function C(){this.errors=[]}function D(){return this.request.create().then(ge).then(function(){le.call(this,"LeaveRequest::new")}.bind(this))}function S(){o.open({title:"Confirm Deletion?",copyCancel:"Cancel",copyConfirm:"Confirm",classConfirm:"btn-danger",msg:"This cannot be undone",onConfirm:function(){return this.directiveOptions.leaveRequest.delete().then(function(){this.dismissModal(),s.$emit("LeaveRequest::deleted",this.directiveOptions.leaveRequest)}.bind(this))}.bind(this)})}function R(){this.$modalInstance.dismiss({$value:"cancel"})}function T(e,t){var a;return e?(a=this.requestDayTypes.slice(0),e=this._convertDateToServerFormat(e),b.isPublicHoliday(e).then(function(t){return t?a.filter(function(e){return"public_holiday"===e.name}):x.call(this,e,a).then(function(e){return e.length?e:a.filter(function(e){return n.includes(["all_day","half_day_am","half_day_pm"],e.name)})})}.bind(this)).then(function(e){return me.call(this,t,e),e}.bind(this))):r.reject([])}function O(e){return a(e,y.serverDateTimeFormat).format(this.uiOptions.userDateFormat.toUpperCase()+" HH:mm")}function I(){var e=this.getStatusFromValue(this.request.status_id);return k.call(this,e.name)}function k(e){return n.map(Me[e],function(e){return this.requestStatuses[e]}.bind(this))}function x(e,t){return e=a(e),r.all([this.calendar.isNonWorkingDay(e),this.calendar.isWeekend(e)]).then(function(e){return e[0]?"non_working_day":e[1]?"weekend":null}).then(function(e){return e?t.filter(function(t){return t.name===e}):[]})}function L(){return n.pick(this.request,["contact_id","from_date","from_date_type","to_date","to_date_type"])}function M(){return n.find(this.absenceTypes,function(e){return e.id===this.request.type_id}.bind(this))}function E(){return!this.request||e.equals({},this.requestStatuses)?[]:this.request.status_id?I.call(this):k.call(this,"none")}function j(e){return n.find(this.requestStatuses,function(t){return t.value===e})}function B(e){this.errors=n.isArray(e)?e:[e],this.loading.showBalanceChange=!1,this.loading.absenceTypes=!1,this.loading.fromDayTypes=!1,this.loading.toDayTypes=!1,this.submitting=!1}function N(){return!e.equals(je,this.request.attributes())||this.fileUploader&&0!==this.fileUploader.queue.length||this.canManage&&this.newStatusOnSave}function F(){this.period=n.find(this.absencePeriods,function(e){return e.current})}function U(){var e=this;return e.postContactSelection=!0,e.request.contact_id?r.all([e._loadAbsenceTypes(),e._loadCalendar()]).then(function(){return ne.call(e)}).then(function(){return W.call(e)}).then(function(){return he.call(e),K.call(e),H.call(e),e.isMode("edit")&&pe.call(e),e.postContactSelection=!1,e.calculateBalanceChange()}).catch(function(e){if(e!==Ve)return r.reject(e)}):r.reject("The contact id was not set")}function V(){var e=[y.statusNames.moreInformationRequired,y.statusNames.approved,y.statusNames.rejected,y.statusNames.cancelled];Me.none=[y.statusNames.moreInformationRequired,y.statusNames.approved],Me.awaiting_approval=e,Me.more_information_required=e,Me.rejected=e,Me.approved=e,Me.cancelled=[y.statusNames.awaitingApproval].concat(e)}function H(){return this.canManage?i.find(this.request.contact_id).then(function(e){this.contactName=e.display_name}.bind(this)):r.resolve()}function W(){if(this.isMode("create"))return r.resolve();var e=this.request.attributes();return this.uiOptions.fromDate=this._convertDateFormatFromServer(this.request.from_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.fromDate,"from").then(function(){return this.request.to_date=e.to_date,this.request.to_date_type=e.to_date_type,this.uiOptions.toDate=this._convertDateFormatFromServer(this.request.to_date),this.loadAbsencePeriodDatesTypes(this.uiOptions.toDate,"to")}.bind(this))}function G(){Be.push(s.$on("LeaveRequestPopup::requestObjectUpdated",pe.bind(this)),s.$on("LeaveRequestPopup::childComponent::register",function(){Ee++}))}function z(){if(this.request.id){this.mode="edit";var e=[this.requestStatuses[y.statusNames.approved].value,this.requestStatuses[y.statusNames.adminApproved].value,this.requestStatuses[y.statusNames.rejected].value,this.requestStatuses[y.statusNames.cancelled].value];this.isRole("staff")&&e.indexOf(this.request.status_id)>-1&&(this.mode="view")}else this.mode="create"}function Y(){return Fe="staff",d(y.permissions.admin.administer).then(function(e){Fe=e?"admin":Fe}).then(function(){return"staff"===Fe&&d(y.permissions.ssp.manage).then(function(e){Fe=e?"manager":Fe})}).finally(function(){this.canManage=this.isRole("manager")||this.isRole("admin"),this.isSelfRecord=this.directiveOptions.isSelfRecord}.bind(this))}function K(){(this.isRole("admin")||this.isMode("create")&&this.isRole("manager"))&&(this.newStatusOnSave=this.requestStatuses[y.statusNames.approved].value)}function J(e){var t=this.getStatusFromValue(this.request.status_id);return!!t&&t.name===e}function X(e){return this.request.request_type===e}function Z(e){return this.mode===e}function Q(e){return Fe===e}function ee(e,t){var n=this.period.id;return t=t||"from",this.loading[t+"DayTypes"]=!0,this._checkAndSetAbsencePeriod(e).then(function(){var e=n===this.period.id;if(!e)return this.uiOptions.multipleDays&&"from"===t&&(this.uiOptions.showBalance=!1,this.uiOptions.toDate=null,this.request.to_date=null,this.request.to_date_type=null),r.all([this._loadAbsenceTypes(),this._loadCalendar()])}.bind(this)).then(function(){return this._setMinMaxDate(),T.call(this,e,t)}.bind(this)).finally(function(){this.loading[t+"DayTypes"]=!1}.bind(this))}function te(){var e=this;return u.all().then(function(t){e.absencePeriods=t})}function ne(){var e=this;return c.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(t){e.requestDayTypes=t})}function ae(){return v.get().then(function(e){Ne=e.contactId})}function re(){return this.directiveOptions.selectedContactId?i.find(this.directiveOptions.selectedContactId).then(function(e){this.managedContacts=[e]}.bind(this)):this.isRole("admin")?i.all().then(function(e){this.managedContacts=n.remove(e.list,function(e){return e.id!==Ne})}.bind(this)):i.find(Ne).then(function(e){return e.leaveManagees()}).then(function(e){this.managedContacts=e}.bind(this))}function se(){var e=this;return c.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){e.requestStatuses=n.indexBy(t,"name")})}function ie(e,t){return t.map(function(t){var a=n.find(e,function(e){return e.id===t.type_id});return{id:t.type_id,title:a.title+" ( "+t.remainder.current+" ) ",remainder:t.remainder.current,allow_overuse:a.allow_overuse}})}function oe(){this.$modalInstance.close({$value:this.request})}function ue(){var e=(this.currentPage-1)*this.numPerPage,t=e+this.numPerPage;this.filteredbreakdown=Ue.balance.change.breakdown.slice(e,t)}function le(e){_.call(this),s.$emit(e,this.request),this.errors=[],this.ok()}function ce(){this.pagination.totalItems=this.balance.change.breakdown.length,this.pagination.filteredbreakdown=this.balance.change.breakdown,this.pagination.pageChanged()}function de(e){var t=this;return h.all({contact_id:t.request.contact_id,period_id:t.period.id,type_id:{IN:e.ids}},!0).then(function(n){if(t.absenceTypes=ie(e.types,n),!t.absenceTypes.length)return r.reject(Ve)})}function fe(){(this.isMode("edit")&&this.request.from_date===this.request.to_date||this.isMode("create")&&this.isLeaveType("sickness"))&&(this.uiOptions.multipleDays=!1)}function me(e,t){var a="request"+n.startCase(e)+"DayTypes";this[a]=t,this.isMode("create")&&(this.request[e+"_date_type"]=this[a][0].value)}function he(){this.isMode("create")?(this.selectedAbsenceType=this.absenceTypes[0],this.request.type_id=this.selectedAbsenceType.id):this.selectedAbsenceType=M.call(this)}function pe(){je=e.copy(this.request.attributes()); +}function ve(){var e=this.request.status_id;if(!this.isMode("view")&&!this.submitting)return this.submitting=!0,P.call(this),qe.call(this).then(function(){return this.isMode("edit")?$e.call(this):D.call(this)}.bind(this)).catch(function(t){this.request.status_id=e,t&&B.call(this,t)}.bind(this)).finally(function(){this.submitting=!1}.bind(this))}function ge(){function e(e){e&&n.push(e),++a===Ee&&(be(),n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Ee>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function be(){n.forEach(Be,function(e){e()})}function ye(e,t){return this.loadAbsencePeriodDatesTypes(e,t).then(function(){return this.updateBalance()}.bind(this)).catch(function(e){B.call(this,e),this._setDateAndTypes()}.bind(this))}function _e(){this.selectedAbsenceType=M.call(this),this.balance.opening=this.selectedAbsenceType.remainder,this.calculateBalanceChange()}function $e(){return this.request.update().then(ge).then(function(){this.isRole("manager")?le.call(this,"LeaveRequest::updatedByManager"):(this.isRole("staff")||this.isRole("admin"))&&le.call(this,"LeaveRequest::edit")}.bind(this))}function qe(){return this.balance.closing<0&&"0"===this.selectedAbsenceType.allow_overuse?r.reject(["You cannot make a request for this leave type at this time as this would leave you with a negative balance"]):this.request.isValid()}function we(){this.balance.opening=this.selectedAbsenceType.remainder,this.balance.closing=this.balance.opening+this.balance.change.amount}function Ae(e){var t=a(e).format(this.uiOptions.userDateFormat.toUpperCase());return this.period=n.find(this.absencePeriods,function(e){return e.isInPeriod(t)}),this.period?r.resolve(!0):(this.period={},this.loading.fromDayTypes=!1,r.reject("Please change date as it is not in any absence period"))}function Pe(e){return a(e,y.serverDateFormat).toDate()}function Ce(e){return a(e).format(y.serverDateFormat)}function De(){return V.call(this),G.call(this),ae.call(this).then(Y.bind(this)).then(this._initRequest.bind(this)).then(se.bind(this)).then(function(){return z.call(this),this.canManage&&!this.isMode("edit")&&re.call(this)}.bind(this)).then(te.bind(this)).then(function(){F.call(this),this._setMinMaxDate()}.bind(this)).then(function(){if(this.directiveOptions.selectedContactId&&(this.request.contact_id=this.directiveOptions.selectedContactId),fe.call(this),this.request.contact_id)return this.initAfterContactSelection()}.bind(this)).catch(B.bind(this))}function Se(){var e={};return this.directiveOptions.leaveRequest?e=this.directiveOptions.leaveRequest.attributes():this.canManage||(e={contact_id:Ne}),e}function Re(){var e=this;return l.all(e.initParams.absenceType).then(function(t){var n=t.map(function(e){return e.id});return Le={types:t,ids:n},de.call(e,Le)})}function Te(){var e=this;return m.get(e.request.contact_id,e.period.start_date,e.period.end_date).then(function(t){e.calendar=t})}function Oe(){this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date_type=this.request.from_date_type,this.request.to_date=this.request.from_date,this.calculateBalanceChange()}function Ie(){this._setDates(),this.uiOptions.multipleDays?this.uiOptions.showBalance=!!(this.request.from_date&&this.request.from_date_type&&this.request.to_date&&this.request.to_date_type&&this.period.id):(this.uiOptions.fromDate&&(this.request.to_date_type=this.request.from_date_type),this.uiOptions.showBalance=!!this.request.from_date&&!!this.request.from_date_type&&!!this.period.id)}function ke(){this.request.from_date=this.uiOptions.fromDate?this._convertDateToServerFormat(this.uiOptions.fromDate):null,this.request.to_date=this.uiOptions.toDate?this._convertDateToServerFormat(this.uiOptions.toDate):null,!this.uiOptions.multipleDays&&this.uiOptions.fromDate&&(this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date=this.request.from_date)}function xe(){if(this.uiOptions.fromDate){var e=a(this.uiOptions.fromDate).add(1,"d").toDate();this.uiOptions.date.to.options.minDate=e,this.uiOptions.date.to.options.initDate=e,this.uiOptions.toDate&&a(this.uiOptions.toDate).isBefore(this.uiOptions.fromDate)&&(this.uiOptions.toDate=this.uiOptions.fromDate)}else this.uiOptions.date.to.options.minDate=this._convertDateFormatFromServer(this.period.start_date),this.uiOptions.date.to.options.initDate=this.uiOptions.date.to.options.minDate;this.uiOptions.date.to.options.maxDate=this._convertDateFormatFromServer(this.period.end_date)}t.debug("RequestCtrl");var Le,Me={},Ee=0,je={},Be=[],Ne="",Fe="",Ue=this,Ve="No entitlement";this.absencePeriods=[],this.absenceTypes=[],this.calendar={},this.canManage=!1,this.contactName=null,this.errors=[],this.fileUploader=null,this.isSelfRecord=!1,this.managedContacts=[],this.mode="",this.newStatusOnSave=null,this.period={},this.postContactSelection=!1,this.requestDayTypes=[],this.requestStatuses={},this.selectedAbsenceType={},this.statusNames=y.statusNames,this.submitting=!1,this.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},this.loading={absenceTypes:!0,showBalanceChange:!1,fromDayTypes:!1,toDayTypes:!1},this.pagination={currentPage:1,filteredbreakdown:this.balance.change.breakdown,numPerPage:7,totalItems:this.balance.change.breakdown.length,pageChanged:ue},this.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:p.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}}}},this.changeInNoOfDays=A,this.calculateBalanceChange=$,this.canSubmit=w,this.closeAlert=C,this.deleteLeaveRequest=S,this.dismissModal=R,this.formatDateTime=O,this.getStatuses=E,this.getStatusFromValue=j,this.initAfterContactSelection=U,this.isLeaveStatus=J,this.isLeaveType=X,this.isMode=Z,this.isRole=Q,this.ok=oe,this.submit=ve,this.loadAbsencePeriodDatesTypes=ee,this.updateAbsencePeriodDatesTypes=ye,this.updateBalance=_e,this._calculateOpeningAndClosingBalance=we,this._checkAndSetAbsencePeriod=Ae,this._convertDateToServerFormat=Ce,this._convertDateFormatFromServer=Pe,this._init=De,this._initRequestAttributes=Se,this._loadCalendar=Te,this._loadAbsenceTypes=Re,this._reset=Oe,this._setDates=ke,this._setDateAndTypes=Ie,this._setMinMaxDate=xe}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","Contact","dialog","AbsencePeriod","AbsenceType","api.optionGroup","checkPermissions","pubSub","Calendar","Entitlement","HR_settings","Session","LeaveRequest","PublicHoliday","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/leave-request.controller",["leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/leave-request.instance"],function(e){function t(e,t,n,a,r){function s(){var e=o._initRequestAttributes();o.request=r.init(e)}t.debug("LeaveRequestCtrl");var i=e("RequestCtrl"),o=Object.create(i);return o.directiveOptions=a,o.$modalInstance=n,o.initParams={absenceType:{is_sick:!1}},o._initRequest=s,function(){o.loading.absenceTypes=!0,o._init().finally(function(){o.loading.absenceTypes=!1})}(),o}e.controller("LeaveRequestCtrl",t),t.$inject=["$controller","$log","$uibModalInstance","directiveOptions","LeaveRequestInstance"]}),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(){var e=this.sickness_required_documents?this.sickness_required_documents.split(","):[];return e},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/controllers/sub-controllers/sick-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/sickness-request.instance"],function(e,t){function n(t,n,a,r,s,i,o){function u(){return h.canSubmit.call(this)&&!!p.request.sickness_reason}function l(t){var n=p.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function c(t){return!!e.find(p.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){p.sicknessDocumentTypes=e})}function f(){return s.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){p.sicknessReasons=e.indexBy(t,"name")})}function m(){var e=p._initRequestAttributes();p.request=o.init(e)}n.debug("SicknessRequestCtrl");var h=t("RequestCtrl"),p=Object.create(h);return p.directiveOptions=i,p.$modalInstance=r,p.initParams={absenceType:{is_sick:!0}},p.canSubmit=u,p.isChecked=l,p.isDocumentInRequest=c,p._initRequest=m,function(){p.loading.absenceTypes=!0,p._init().then(function(){return a.all([d(),f()])}).finally(function(){p.loading.absenceTypes=!1})}(),p}t.controller("SicknessRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","directiveOptions","SicknessRequestInstance"]}),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/sub-controllers/toil-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/toil-request.instance"],function(e,t){function n(t,n,a,r,s,i,o,u){function l(){P.request.toil_to_accrue&&(P.loading.showBalanceChange=!0,P._setDateAndTypes(),P.balance.change.amount=+P.request.toil_to_accrue,P._calculateOpeningAndClosingBalance(),P.uiOptions.showBalance=!0,P.request.to_date_type=P.request.from_date_type="1",P.loading.showBalanceChange=!1)}function c(){return!P.canManage&&P.request.id?a.resolve(P.request.toil_expiry_date):P.requestCanExpire?p().catch(function(e){return e.length&&(P.errors=e),a.reject(e)}).then(function(e){return i.calculateToilExpiryDate(P.request.type_id,e)}).then(function(e){return P.request.toil_expiry_date=e,P.uiOptions.expiryDate=new Date(e),e}):(P.request.toil_expiry_date=!1,a.resolve(!1))}function d(){return P.uiOptions.multipleDays&&P.request.to_date||!P.uiOptions.multipleDays&&P.request.from_date}function f(){return A.canSubmit.call(this)&&!!P.request.toil_duration&&!!P.request.toil_to_accrue&&!!P.request.from_date&&!!P.request.to_date}function m(){A.changeInNoOfDays.call(this),d()&&P.calculateToilExpiryDate()}function h(){P.request.toil_expiry_date=!1,P.uiOptions.expiryDate=null}function p(){return v(P.uiOptions.multipleDays?{hasErrors:!P.request.to_date&&!P.request.from_date,label:"To Date",value:P.request.to_date}:{hasErrors:!P.request.from_date,label:"From Date",value:P.request.from_date})}function v(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(e.value):a.reject([])}function g(){P.canManage&&(P.uiOptions.expiryDate=P._convertDateFormatFromServer(P.request.toil_expiry_date))}function b(){return i.canExpire(P.request.type_id).then(function(e){P.requestCanExpire=e})}function y(e){var t=P.period.id;return P._checkAndSetAbsencePeriod(e).then(function(){var e=t===P.period.id;if(!e)return P.uiOptions.multipleDays&&(P.uiOptions.showBalance=!1,P.uiOptions.toDate=null,P.request.to_date=null),a.all([P._loadAbsenceTypes(),P._loadCalendar()])})}function _(){return s.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){P.toilAmounts=e.indexBy(t,"value")})}function $(e){return P.loadAbsencePeriodDatesTypes().then(function(){P._setMinMaxDate(),P._setDates(),P.updateBalance(),P.calculateToilExpiryDate()}).catch(function(e){P.errors=[e]})}function q(){P.uiOptions.expiryDate&&(P.request.toil_expiry_date=P._convertDateToServerFormat(P.uiOptions.expiryDate))}function w(){var e=P._initRequestAttributes();P.request=u.init(e),P.request.to_date_type=P.request.from_date_type="1"}n.debug("ToilRequestCtrl");var A=t("RequestCtrl"),P=Object.create(A);return P.requestCanExpire=!0,P.directiveOptions=o,P.$modalInstance=r,P.initParams={absenceType:{allow_accruals_request:!0}},P.calculateBalanceChange=l,P.calculateToilExpiryDate=c,P.canSubmit=f,P.changeInNoOfDays=m,P.clearExpiryDate=h,P.loadAbsencePeriodDatesTypes=y,P.updateAbsencePeriodDatesTypes=$,P.updateExpiryDate=q,P._initRequest=w,function(){P.loading.absenceTypes=!0,P._init().then(function(){return b()}).then(function(){return g(),_()}).finally(function(){P.loading.absenceTypes=!1})}(),P}t.controller("ToilRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","AbsenceType","directiveOptions","TOILRequestInstance"]}),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-popup.service",["common/lodash","leave-absences/shared/modules/services","common/services/notification.service"],function(e,t){"use strict";function n(t,n,a,r,s,i,o,u,l,c){function d(e){return l.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function f(e,t){return t?t.request_type:e||null}function m(t,a,r,i){var u=e.capitalize(f(a,t))+"RequestCtrl";s.open({appendTo:n.children().eq(0),templateUrl:o.sharedPathTpl+"directives/leave-request-popup/leave-request-popup.html",controller:u,controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveRequest:t,selectedContactId:r,isSelfRecord:i}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function h(e){return c.find(e).then(function(e){return d(e).then(function(t){t?m(e,e.request_type,e.contact_id,"my-leave"===a.section):i.error("Error","You dont have permission to see this leave request")})}).catch(function(e){i.error("Error",e)})}return t.debug("LeavePopup"),{openModal:m,openModalByID:h}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$q","$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",function(e,t){e.debug("Component: manager-leave-container"),t.section="manager-leave"}],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,s,i){s.debugEnabled(i.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.balance-report",{url:"/balance-report",template:""})}])})}(CRM),define("leave-absences/manager-leave/app",["common/angular","common/angularBootstrap","common/text-angular","common/directives/loading","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-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/leave-request.controller","leave-absences/shared/controllers/sub-controllers/sick-request.controller","leave-absences/shared/controllers/sub-controllers/toil-request.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.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(){}); \ 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 3077f5a143e..fb118172e41 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 @@ -7,5 +7,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 s(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 o(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),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(g[n]=a,B(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)}b.pop(),g[n]=s}}function h(e){return N(e)&&e.then&&e.$$promises}if(!N(u))throw new Error("'invocables' must be an object");var p=o(u||{}),v=[],b=[],g={};return H(u,m),u=b=g=null,function(a,s,o){function i(){--_||($||r(y,s.$$values),b.$$values=y,b.$$promises=b.$$promises||!0,delete b.$$inheritedValues,m.resolve(y))}function u(e){b.$$failure=e,m.reject(e)}function c(n,r,s){function c(e){d.reject(e),u(e)}function l(){if(!j(b.$$failure))try{d.resolve(t.invoke(r,o,y)),d.promise.then(function(e){y[n]=e,i()},c)}catch(e){c(e)}}var d=e.defer(),f=0;H(s,function(e){g.hasOwnProperty(e)&&!a.hasOwnProperty(e)&&(f++,g[e].then(function(t){y[e]=t,--f||l()},c))}),f||l(),g[n]=d.promise}if(h(a)&&o===n&&(o=s,s=a,a=null),a){if(!N(a))throw new Error("'locals' must be an object")}else a=l;if(s){if(!h(s))throw new Error("'parent' must be a promise returned by $resolve.resolve()")}else s=d;var m=e.defer(),b=m.promise,g=b.$$promises={},y=V({},a),_=1+v.length/3,$=!1;if(j(s.$$failure))return u(s.$$failure),b;s.$$inheritedValues&&r(y,f(s.$$inheritedValues,p)),V(g,s.$$promises),s.$$values?($=r(y,f(s.$$values,p)),b.$$inheritedValues=f(s.$$values,p),i()):(s.$$inheritedValues&&(b.$$inheritedValues=f(s.$$inheritedValues,p)),s.then(i,u));for(var q=0,w=v.length;q=0));)g=s(b.id,b.type,b.cfg,"path"),d+=o(b.segment,g.type.pattern.source,g.squash,g.isOptional),m.push(b.segment),f=c.lastIndex;y=e.substring(f);var _=y.indexOf("?");if(_>=0){var $=this.sourceSearch=y.substring(_);if(y=y.substring(0,_),this.sourcePath=e.substring(0,f+_),$.length>0)for(f=0;u=l.exec($);)b=i(u,!0),g=s(b.id,b.type,b.cfg,"search"),f=c.lastIndex}else this.sourcePath=e,this.sourceSearch="";d+=o(y)+(t.strict===!1?"/?":"")+"$",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 s(){return{strict:p,caseInsensitive:f}}function u(e){return F(e)||U(e)&&F(e[e.length-1])}function c(){for(;q.length;){var e=q.shift();if(e.pattern)throw new Error("You cannot override a type's .pattern at runtime.");t.extend(b[e.name],d.invoke(e.def))}}function l(e){V(this,e||{})}Y=this;var d,f=!1,p=!0,v=!1,b={},$=!0,q=[],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 e===!0||e===!1},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)&&(p=e),p},this.defaultSquashPolicy=function(e){if(!j(e))return v;if(e!==!0&&e!==!1&&!B(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 g(e,V(s(),t))},this.isMatcher=function(e){if(!N(e))return!1;var t=!0;return H(g.prototype,function(n,a){F(n)&&(t=t&&j(e[a])&&F(e[a]))}),t},this.type=function(e,t,n){if(!j(t))return b[e];if(b.hasOwnProperty(e))throw new Error("A type named '"+e+"' has already been defined.");return b[e]=new y(V({name:e},t)),n&&(q.push({name:e,def:n}),$||c()),this},H(w,function(e,t){b[t]=new y(V({name:t},e))}),b=a(b,{}),this.$get=["$injector",function(e){return d=e,$=!1,c(),H(w,function(e,t){b[t]||(b[t]=new y(e))}),this}],this.Param=function(e,a,r,s){function c(e){var t=N(e)?o(e):[],n=i(t,"value")===-1&&i(t,"type")===-1&&i(t,"squash")===-1&&i(t,"array")===-1;return n&&(e={value:e}),e.$$fn=u(e.value)?e.value:function(){return e.value},e}function l(n,a,r){if(n.type&&a)throw new Error("Param '"+e+"' has two type configurations.");return a?a:n.type?t.isString(n.type)?b[n.type]:n.type instanceof y?n.type:new y(n.type):"config"===r?b.any:b.string}function f(){var t={array:"search"===s&&"auto"},n=e.match(/\[\]$/)?{array:!0}:{};return V(t,n,r).array}function p(e,t){var n=e.squash;if(!t||n===!1)return!1;if(!j(n)||null==n)return v;if(n===!0||B(n))return n;throw new Error("Invalid squash policy: '"+n+"'. Valid policies: false, true, or arbitrary string")}function g(e,t,a,r){var s,o,u=[{from:"",to:a||t?n:""},{from:null,to:a||t?n:""}];return s=U(e.replace)?e.replace:[],B(r)&&s.push({from:r,to:n}),o=h(s,function(e){return e.from}),m(u,function(e){return i(o,e.from)===-1}).concat(s)}function _(){if(!d)throw new Error("Injectable functions cannot be called at configuration time");var e=d.invoke(r.$$fn);if(null!==e&&e!==n&&!w.type.is(e))throw new Error("Default value ("+e+") for parameter '"+w.id+"' is not an instance of Type ("+w.type.name+")");return e}function $(e){function t(e){return function(t){return t.from===e}}function n(e){var n=h(m(w.replace,t(e)),function(e){return e.to});return n.length?n[0]:e}return e=n(e),j(e)?w.type.$normalize(e):_()}function q(){return"{Param:"+e+" "+a+" squash: '"+C+"' optional: "+P+"}"}var w=this;r=c(r),a=l(r,a,s);var A=f();a=A?a.$asArray(A,"search"===s):a,"string"!==a.name||A||"path"!==s||r.value!==n||(r.value="");var P=r.value!==n,C=p(r,P),D=g(r,A,P,C);V(this,{id:e,type:a,location:s,array:A,squash:C,replace:D,isOptional:P,value:$,dynamic:n,config:r,toString:q})},l.prototype={$$new:function(){return a(this,V(new l,{$$parent:this}))},$$keys:function(){for(var e=[],t=[],n=this,a=o(l.prototype);n;)t.push(n),n=n.$$parent;return t.reverse(),H(t,function(t){H(o(t),function(t){i(e,t)===-1&&i(a,t)===-1&&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 s=e&&e[r],o=t&&t[r];a[r].type.equals(s,o)||(n=!1)}),n},$$validates:function(e){var a,r,s,o,i,u=this.$$keys();for(a=0;a=0)throw new Error("State must have a valid name");if(C.hasOwnProperty(n))throw new Error("State '"+n+"' is already defined");var r=n.indexOf(".")!==-1?n.substring(0,n.lastIndexOf(".")):B(t.parent)?t.parent:N(t.parent)&&B(t.parent.name)?t.parent.name:"";if(r&&!C[r])return m(r,t.self);for(var s in T)F(T[s])&&(t[s]=T[s](t,T.$delegates[s]));return C[n]=t,!t[S]&&t.url&&e.when(t.url,["$match","$stateParams",function(e,n){P.$current.navigable==t&&c(e,n)||P.transitionTo(t,e,{inherit:!0,location:!1})}]),v(n),t}function g(e){return e.indexOf("*")>-1}function y(e){for(var t=e.split("."),n=P.$current.name.split("."),a=0,r=t.length;a=C;a--)o=h[a],o.self.onExit&&i.invoke(o.self.onExit,o.self,o.locals.globals),o.locals=null;for(a=C;a<_.length;a++)r=_[a],r.locals=x[a],r.self.onEnter&&i.invoke(r.self.onEnter,r.self,r.locals.globals);return P.transition!==F?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(P.$current=t,P.current=t.self,P.params=n,W(P.params,m),P.transition=null,s.location&&t.navigable&&v.push(t.navigable.url,t.navigable.locals.globals.$stateParams,{$$avoidResync:!0,replace:"replace"===s.location}),s.notify&&e.$broadcast("$stateChangeSuccess",t.self,n,c.self,d),v.update(!0),P.current)}).then(null,function(a){return a===D?T:P.transition!==F?(e.$broadcast("$stateChangeCancel",t.self,n,c.self,d),T):(P.transition=null,o=e.$broadcast("$stateChangeError",t.self,n,c.self,d,a),o.defaultPrevented||v.update(),r.reject(a))});return F},P.is=function(e,t,a){a=V({relative:P.$current},a||{});var r=f(e,a.relative);return j(r)?P.$current===r&&(!t||c(r.params.$$values(t),m)):n},P.includes=function(e,t,a){if(a=V({relative:P.$current},a||{}),B(e)&&g(e)){if(!y(e))return!1;e=P.$current.name}var r=f(e,a.relative);if(!j(r))return n;if(!j(P.$current.includes[r.name]))return!1;if(!t)return!0;for(var s=o(t),i=0;i2?l.enter(e,null,n).then(a):l.enter(e,null,n,a)},leave:function(e,n){t.version.minor>2?l.leave(e).then(n):l.leave(e,n)}};if(c){var r=c&&c(n,e);return{enter:function(e,t,n){r.enter(e,null,t),n()},leave:function(e,t){r.leave(e),t()}}}return a()}var u=o(),c=u("$animator"),l=u("$animate"),d={restrict:"ECA",terminal:!0,priority:400,transclude:"element",compile:function(n,o,u){return function(n,o,c){function l(){if(f&&(f.remove(),f=null),h&&(h.$destroy(),h=null),m){var e=m.data("$uiViewAnim");g.leave(m,function(){e.$$animLeave.resolve(),f=null}),f=m,m=null}}function d(i){var d,f=D(n,c,o,r),y=f&&e.$current&&e.$current.locals[f];if(i||y!==p){d=n.$new(),p=e.$current.locals[f],d.$emit("$viewContentLoading",f);var _=u(d,function(e){var r=s.defer(),i=s.defer(),u={$animEnter:r.promise,$animLeave:i.promise,$$animLeave:i};e.data("$uiViewAnim",u),g.enter(e,o,function(){r.resolve(),h&&h.$emit("$viewContentAnimationEnded"),(t.isDefined(b)&&!b||n.$eval(b))&&a(e)}),l()});m=_,h=d,h.$emit("$viewContentLoaded",f),h.$eval(v)}}var f,m,h,p,v=c.onload||"",b=c.autoscroll,g=i(c,n);o.inheritedData("$uiView"),n.$on("$stateChangeSuccess",function(){d(!1)}),d(!0)}}};return d}function C(e,n,a,r){return{restrict:"ECA",priority:-400,compile:function(s){var o=s.html();return function(s,i,u){var c=a.$current,l=D(s,u,i,r),d=c&&c.locals[l];if(d){i.data("$uiView",{name:l,state:d.$$state}),i.html(d.$template?d.$template:o);var f=t.extend({},d);s[d.$$resolveAs]=f;var m=e(i.contents());if(d.$$controller){d.$scope=s,d.$element=i;var h=n(d.$$controller,d);d.$$controllerAs&&(s[d.$$controllerAs]=h,s[d.$$controllerAs][d.$$resolveAs]=f),F(h.$onInit)&&h.$onInit(),i.data("$ngControllerController",h),i.children().data("$ngControllerController",h)}m(s)}}}}}function D(e,t,n,a){var r=a(t.uiView||t.name||"")(e),s=n.inheritedData("$uiView");return r.indexOf("@")>=0?r:r+"@"+(s?s.state.name:"")}function S(e,t){var n,a=e.match(/^\s*({[^}]*})\s*$/);if(a&&(e=t+"("+a[1]+")"),n=e.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/),!n||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 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(s){var o=s.which||s.button,i=r();if(!(o>1||s.ctrlKey||s.metaKey||s.shiftKey||e.attr("target"))){var u=n(function(){t.go(i.state,i.params,i.options)});s.preventDefault();var c=a.isAnchor&&!i.href?1:0;s.preventDefault=function(){c--<=0&&n.cancel(u)}}}}function I(e,t){return{relative:T(e)||t.$current,inherit:!0}}function k(e,n){return{restrict:"A",require:["?^uiSrefActive","?^uiSrefActiveEq"],link:function(a,r,s,o){var i,u=S(s.uiSref,e.current.name),c={state:u.state,href:null,params:null},l=R(r),d=o[1]||o[0],f=null;c.options=V(I(r,e),s.uiSrefOpts?a.$eval(s.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&&s.$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,s){function o(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=R(a),c=s[1]||s[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,o,!0),o(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,s){function o(t,n,r){var s=e.get(t,T(a)),o=i(t,n),u={state:s||{name:t},params:n,hash:o};return p.push(u),v[o]=r,function(){var e=p.indexOf(u);e!==-1&&p.splice(e,1)}}function i(e,n){if(!B(e))throw new Error("state should be a string");return N(n)?e+G(n):(n=t.$eval(n),N(n)?e+G(n):e)}function u(){for(var e=0;e0)){var n=o(e,t,h);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 L(e){var t=function(t,n,a){return e.includes(t,n,a)};return t.$stateful=!0,t}var j=t.isDefined,F=t.isFunction,B=t.isString,N=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),b.$inject=["$http","$templateCache","$injector"],t.module("ui.router.util").service("$templateFactory",b);var Y;g.prototype.concat=function(e,t){var n={caseInsensitive:Y.caseInsensitive(),strict:Y.strictMode(),squash:Y.defaultSquashPolicy()};return new g(this.sourcePath+e+this.sourceSearch,V(n,t),this)},g.prototype.toString=function(){return this.source},g.prototype.exec=function(e,t){function n(e){function t(e){return e.split("").reverse().join("")}function n(e){return e.replace(/\\-/g,"-")}var a=t(e).split(/-(?!\\)/),r=h(a,t);return h(r,n).reverse()}var a=this.regexp.exec(e);if(!a)return null;t=t||{};var r,s,o,i=this.parameters(),u=i.length,c=this.segments.length-1,l={};if(c!==a.length-1)throw new Error("Unbalanced capture group in route '"+this.source+"'");var d,f;for(r=0;r=":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.defaults(t||{},{is_active:!0})).then(function(e){return e.values})},calculateToilExpiryDate:function(a,s,o){return n.debug("AbsenceTypeAPI.calculateToilExpiryDate"),o=e.assign({},o,{absence_type_id:a,date:t(s).format(r.serverDateFormat)}),this.sendPOST("AbsenceType","calculateToilExpiryDate",o).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",["leave-absences/shared/modules/models","common/models/model","leave-absences/shared/apis/absence-type-api","leave-absences/shared/instances/absence-type.instance"],function(e){"use strict";e.factory("AbsenceType",["$log","Model","AbsenceTypeAPI","AbsenceTypeInstance",function(e,t,n,a){return e.debug("AbsenceType"),t.extend({all:function(e){return n.all(e).then(function(e){return e.map(function(e){return a.init(e,!0)})})},calculateToilExpiryDate:function(e,t,a){return n.calculateToilExpiryDate(e,t,a)},canExpire:function(e){return n.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})}})}])}),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,s,o){return this.sendPOST("ContactWorkPattern","create",e.assign({},o,{contact_id:t,pattern_id:n,effective_date:a,effective_end_date:r,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,r,s){return t.debug("WorkPatternAPI.getCalendar",n,a,r,s),this.sendGET("WorkPattern","getcalendar",e.assign({},s,{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,s,o){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,s.serverDateFormat).clone()}function c(){return l=l||o.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,s,o,i){return t.debug("Calendar.get"),a.getCalendar(n,s,o,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})}})}])}),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/instances/entitlement.instance"],function(e,t){"use strict";t.factory("Entitlement",["$log","Model","EntitlementAPI","EntitlementInstance",function(t,n,a,r){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)})})}})}])}),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,s,o){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,s,"getFull",o)),i.promise},balanceChangeByAbsenceType:function(t,n,r,s){e.debug("LeaveRequestAPI.balanceChangeByAbsenceType");var o=a.defer();t&&n||o.reject("contact_id and period_id are mandatory");var i={contact_id:t,period_id:n,statuses:r?{IN:r}:null,public_holiday:s||!1};return this.sendGET("LeaveRequest","getbalancechangebyabsencetype",i,!1).then(function(e){o.resolve(e.values)}),o.promise},calculateBalanceChange:function(t){e.debug("LeaveRequestAPI.calculateBalanceChange",t);var n=a.defer();return!t||t.contact_id&&t.from_date&&t.from_date_type||n.reject("contact_id, from_date and from_date_type in params are mandatory"),this.sendPOST("LeaveRequest","calculatebalancechange",t).then(function(e){n.resolve(e.values)}),n.promise},create:function(t){e.debug("LeaveRequestAPI.create",t);var n=a.defer();return t&&(t.to_date&&!t.to_date_type?n.reject("to_date_type is mandatory"):t.contact_id&&t.from_date&&t.from_date_type&&t.status_id||n.reject("contact_id, from_date, status_id and from_date_type params are mandatory")),this.sendPOST("LeaveRequest","create",t).then(function(e){n.resolve(e.values[0])}),n.promise},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","get",{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","leave-absences/shared/modules/models-instances","common/models/option-group","common/models/instances/instance"],function(e,t){"use strict";t.factory("LeaveRequestInstance",["$q","checkPermissions","OptionGroup","shared-settings","ModelInstance","LeaveRequestAPI",function(t,n,a,r,s,o){function i(e){return l(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 u(e){return l(e).then(function(e){return this.status_id===e.value}.bind(this))}function c(){var n=[];return e.forEach(this.files,function(e){e.toBeDeleted&&n.push(o.deleteAttachment(this.id,e.attachment_id))}.bind(this)),t.all(n)}function l(e){return a.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){return t.find(function(t){return t.name===e})})}function d(){var e=this.id,n=[];return n.push(t.sequence(this.comments.filter(function(e){return!e.comment_id}).map(function(t){return function(){return o.saveComment(e,t)}}))),n=n.concat(this.comments.filter(function(e){return e.comment_id&&e.toBeDeleted}).map(function(e){return o.deleteComment(e.comment_id)})),t.all(n)}return s.extend({defaultCustomData:function(){return{comments:[],files:[],request_type:"leave"}},cancel:function(){return i.call(this,r.statusNames.cancelled)},approve:function(){return i.call(this,r.statusNames.approved)},reject:function(){return i.call(this,r.statusNames.rejected)},sendBack:function(){return i.call(this,r.statusNames.moreInformationRequired)},update:function(){return o.update(this.toAPI()).then(function(){return t.all([d.call(this),c.call(this)])}.bind(this))},create:function(){return o.create(this.toAPI()).then(function(e){return this.id=e.id,t.all([d.call(this)])}.bind(this))},deleteAttachment:function(e){e.toBeDeleted||(e.toBeDeleted=!0)},deleteComment:function(t){return t.comment_id?void(t.toBeDeleted=!0):void(this.comments=e.reject(this.comments,function(e){return t.created_at===e.created_at&&t.text===e.text}))},delete:function(){return o.delete(this.id)},isValid:function(){return o.isValid(this.toAPI())},isApproved:function(){return u.call(this,r.statusNames.approved)},isAwaitingApproval:function(){return u.call(this,r.statusNames.awaitingApproval)},isCancelled:function(){return u.call(this,r.statusNames.cancelled)},isRejected:function(){return u.call(this,r.statusNames.rejected)},isSentBack:function(){return u.call(this,r.statusNames.moreInformationRequired)},loadComments:function(){return this.id?o.getComments(this.id).then(function(e){this.comments=e}.bind(this)):t.resolve()},roleOf:function(e){return this.contact_id===e?t.resolve("owner"):n(r.permissions.admin.administer).then(function(t){return t?"admin":o.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?o.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,t,n,a){return e.debug("LeaveRequest"),t.extend({all:function(e,t,r,s,o){return n.all(this.processFilters(e),t,r,s,o).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)},calculateBalanceChange:function(t){return e.debug("LeaveRequestAPI.calculateBalanceChange"),n.calculateBalanceChange(t)},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,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 r.init(e,!0)})})},isPublicHoliday:function(n){t.debug("PublicHoliday.isPublicHoliday",n);var r=e(n).format(s.serverDateFormat),o={date:r};return a.all(o).then(function(e){return!!e.length})}})}])}),define("leave-absences/shared/modules/components",["common/angular"],function(e){return e.module("leave-absences.components",[])}),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"],function(e,t,n){function a(e,t){function n(){return{loadContacts:function(){return t.all().then(function(e){s.lookupContacts=e.list}).then(a)}}}function a(){return t.all(r(),null,"display_name").then(function(e){return e.list})}function r(){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("LeaveCalendarAdminController");var s;return{init:function(e){return s=e,s.showContactName=!0,s.showFilters=!0,n()}}}n.controller("LeaveCalendarAdminController",["$log","Contact",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:o.contactId}).leaveManagees().then(function(e){o.lookupContacts=e}).then(r)}}}function r(){return t.all(s(),null,"display_name").then(function(e){return e.list})}function s(){return{department:o.filters.userSettings.department?o.filters.userSettings.department.value:null,level_type:o.filters.userSettings.level_type?o.filters.userSettings.level_type.value:null,location:o.filters.userSettings.location?o.filters.userSettings.location.value:null,region:o.filters.userSettings.region?o.filters.userSettings.region.value:null,id:{IN:o.filters.userSettings.contact?[o.filters.userSettings.contact.id]:o.lookupContacts.map(function(e){return e.id})}}}e.debug("LeaveCalendarManagerController");var o;return{init:function(e){return o=e,o.showContactName=!0,o.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,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,s,o,i,u,c,l,d,f,m,h,p){function v(){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(T(t)),t.add(1,"month");L.months=e}function b(){o.$new().$watch(function(){return L.selectedMonths},function(t,n){null===n||e.equals(t,n)||O()})}function g(e){x("injected").then(function(){O(e)}).then(function(){L.loading.calendar=!1}),S().then(function(){L.injectMonths=!0})}function y(){M=a("LeaveCalendar"+t.capitalize(E)+"Controller").init(L)}function _(e){return e.current?"Current Period ("+e.title+")":e.title}function $(){return c.all().then(function(e){L.absencePeriods=t.sortBy(e,"start_date"),L.selectedPeriod=t.find(L.absencePeriods,function(e){return!!e.current})}).then(v).then(I)}function q(){return l.all({is_active:!0})}function w(){return m.valuesOf(["hrleaveandabsences_leave_request_status","hrleaveandabsences_leave_request_day_type"])}function A(){return M.loadContacts().then(function(e){L.contacts=e})}function P(){return m.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 f.all()}function D(){return r.all([q(),C(),w()]).then(function(e){L.supportData.absenceTypes=e[0],L.supportData.publicHolidays=e[1],L.supportData.leaveRequestStatuses=e[2].hrleaveandabsences_leave_request_status,L.supportData.dayTypes=e[2].hrleaveandabsences_leave_request_day_type})}function S(){var e=r.resolve();return L.injectMonths&&(e=x("destroyed"),L.injectMonths=!1),e}function T(e){return{index:e.month(),year:e.year(),name:e.format("MMM")}}function R(e){e=t.includes(["contacts","period"],e)?e:"period",r.resolve().then(function(){L.loading.calendar=!0}).then("period"===e?v:t.noop).then("contacts"===e?A:t.noop).then(function(){g("contacts"===e)})}function O(e){var n=L.selectedMonths.length?L.months.filter(function(e){return t.includes(L.selectedMonths,e.index)}):L.months;o.$emit("LeaveCalendar::showMonths",n,!!e)}function I(){L.selectedMonths=[n().month()]}function k(){return L.roleOverride?r.resolve().then(function(){E=L.roleOverride}):r.all([p(u.permissions.admin.administer),p(u.permissions.ssp.manage)]).then(function(e){E=e[0]?"admin":e[1]?"manager":"staff"})}function x(e){return r(function(n){var a=0,r=o.$on("LeaveCalendar::month"+t.capitalize(e),function(){++a===L.months.length&&(r(),n())})})}s.debug("Component: leave-calendar");var M,E,L=this;L.absencePeriods=[],L.contacts=[],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:!1,department:null,level_type:null,location:null,region:null}},L.labelPeriod=_,L.refresh=R,function(){k().then(b).then(y).then(function(){return r.all([A(),$(),D()])}).then(function(){return L.showFilters?P():t.noop}).then(function(){g()}).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","$timeout","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","PublicHoliday","OptionGroup","Calendar","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["leave-absences/shared/modules/components"],function(e){function t(e,t){"use strict";function n(e,n,a,r,s){e.stopPropagation(),t.openModal(n,a,r,s)}e.debug("Component: leave-calendar-day");var a=this;a.openLeavePopup=n}e.component("leaveCalendarDay",{bindings:{contactData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:t}),t.$inject=["$log","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.collapsed=!1,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"],function(e,t,n){function a(n,a,r,s,o,i){function u(e,t){v([t]),x(t)}function c(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:l(e)}}function l(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(F.period.start_date)&&r.isSameOrBefore(F.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function d(e){return L[e]}function f(){return F.showOnlyWithLeaveRequests?F.contacts.filter(function(t){return e.includes(Object.keys(j),t.id)}):F.contacts}function m(e){return t(e,i.serverDateFormat)}function h(e,t){D(t),x(t)}function p(){F.supportData.dayTypes=e.indexBy(F.supportData.dayTypes,"name"),F.supportData.leaveRequestStatuses=e.indexBy(F.supportData.leaveRequestStatuses,"value"),F.supportData.publicHolidays=e.transform(F.supportData.publicHolidays,function(e,t){e[m(t.date).valueOf()]=t},{})}function v(e){var t=a.defer();return e.forEach(function(e){var t=$(e);j[e.contact_id]=j[e.contact_id]||{},t.forEach(function(t){j[e.contact_id][t.date]=e})}),t.resolve(),t.promise}function b(){E.push(r.$on("LeaveCalendar::showMonths",O)),E.push(r.$on("LeaveRequest::new",u)),E.push(r.$on("LeaveRequest::edit",k)),E.push(r.$on("LeaveRequest::updatedByManager",k)),E.push(r.$on("LeaveRequest::deleted",h))}function g(e,n,a){var r=F.supportData.dayTypes[e];return t(a).isSame(n.from_date)?r.value===n.from_date_type:t(a).isSame(n.to_date)?r.value===n.to_date_type:void 0}function y(e){var t=F.supportData.leaveRequestStatuses[e.status_id];return t.name===i.statusNames.awaitingApproval}function _(e){return!!F.supportData.publicHolidays[m(e).valueOf()]}function $(n){for(var a=[],r=t(n.from_date).clone(),s=t(n.to_date);r.isSameOrBefore(s);)a.push(e.find(F.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function q(t){return e.find(j[t.contact_id],function(e){return t.id===e.id})}function w(t){var n=e.find(F.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function A(){return F.month.loading=!0,a.all([C(),P()]).then(function(){return R()}).then(function(){M=!0}).then(function(){F.month.loading=!1})}function P(){return o.all({from_date:{from:F.month.days[0].date},to_date:{to:F.month.days[F.month.days.length-1].date},status_id:{IN:[w(i.statusNames.approved),w(i.statusNames.adminApproved),w(i.statusNames.awaitingApproval)]},contact_id:{IN:F.contacts.map(function(e){return e.id})}},null,null,null,!1).then(function(e){return v(e.list)})}function C(){var t=F.month.days[0].date,n=F.month.days[F.month.days.length-1].date;return s.get(F.contacts.map(function(e){return e.id}),t,n).then(function(t){L=e.indexBy(t,"contact_id")})}function D(t){j[t.contact_id]=e.omit(j[t.contact_id],function(e){return e.id===t.id})}function S(){r.$emit("LeaveCalendar::monthDestroyed"),E.map(function(e){e()})}function T(t,n,r){var s,o;return t.contactsData[n]=t.contactsData[n]||{},o=d(n),s=r===!0?a.resolve():a.all([o.isWeekend(m(t.date)),o.isNonWorkingDay(m(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:_(t.date)})}),s.then(function(){return j[n]?j[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?I(a):null,isAccruedTOIL:a?a.balance_change>0:null,isRequested:a?y(a):null,isAM:a?g("half_day_am",a,t.date):null,isPM:a?g("half_day_pm",a,t.date):null})})}function R(){return a.all(F.month.days.map(function(e){return a.all(F.contacts.map(function(t){return T(e,t.id)}))}))}function O(t,n,a){var r=!!e.find(n,function(e){return e.index===F.month.index});r?(F.currentPage=0,F.visible=!0,(a||!M)&&A()):F.visible=!1}function I(t){var n=e.find(F.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 k(e,t){var n=q(t);h(null,n),u(null,t)}function x(e){return a.all($(e).map(function(t){return T(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var M=!1,E=[],L={},j={},F=this;F.currentPage=0,F.pageSize=20,F.visible=!1,F.showContactName=!!F.showContactName,F.showOnlyWithLeaveRequests=!!F.showOnlyWithLeaveRequests,F.$onDestroy=S,F.contactsList=f,function(){var e=t().month(F.month.index).year(F.month.year);p(),b(),F.month=c(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",month:"<",period:"<",showContactName:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","shared-settings",a]})}),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"],function(e,t,n){function a(n,a,r,s,o,i,u){function c(e){var t=y[e].dialog;v=b.leaveRequest.status_id,r.open({title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return b.leaveRequest[e]().then(function(){m(e)}).catch(function(e){u.error("Error:",e)})}})}function l(){var e=b.absenceTypes[b.leaveRequest.type_id].allow_request_cancelation;return"admin"===b.role||"manager"===b.role||("3"===e?t().isBefore(b.leaveRequest.from_date):"2"===e)}function d(){Array.isArray(b.leaveRequestStatuses)&&(b.leaveRequestStatuses=e.indexBy(b.leaveRequestStatuses,"value")),Array.isArray(b.absenceTypes)&&(b.absenceTypes=e.indexBy(b.absenceTypes,"id"))}function f(e,t,n,a,r){e.stopPropagation(),s.openModal(t,n,a,r)}function m(t){var n=e.find(b.leaveRequestStatuses,function(e){return e.name===i.statusNames.awaitingApproval}).value;v===n&&o.publish("ManagerBadge:: Update Count"),a.$emit("LeaveRequest::"+("delete"===t?"deleted":"edit"),b.leaveRequest)}function h(){var t=b.leaveRequestStatuses[b.leaveRequest.status_id].name,n=e.compact(e.map(y,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!l()&&e.pull(n,"cancel"),"admin"!==b.role&&e.pull(n,"delete"),"staff"===b.role&&e.pull(n,"approve","reject"),"staff"!==b.role&&p(n),b.allowedActions=e.map(n,function(e){return{key:e,label:y[e].label,isDirectAction:y[e].isDirectAction}})}function p(t){e.each(t,function(e,n){"edit"===e&&(t[n]="respond"),"respond"===e&&(t[n]="edit")})}n.debug("Component: leave-request-action-dropdown");var v,b=this,g=i.statusNames,y={edit:{label:"Edit",allowedStatuses:[g.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[g.moreInformationRequired]},view:{label:"View",allowedStatuses:[g.approved,g.rejected,g.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired,g.approved,g.rejected,g.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};b.allowedActions=[],b.action=c,b.openLeavePopup=f,function(){d(),h()}()}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","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,s,o,i){function u(){var t=e.indexBy(f.request.comments,"contact_id"),n=Object.keys(t);return o.all({id:{IN:n}},{page:1,size:0}).then(function(t){f.comment.contacts=e.indexBy(t.list,"contact_id")})}function c(){return f.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),f.request.comments.length&&u()})}function l(){return f.loading.component=!0,i.get().then(function(e){d=e.contactId}).then(function(){f.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var d=null,f=this;f.loading={component:!0},f.comment={text:"",contacts:{}},function(){c(),l()}(),f.addComment=function(){f.request.comments.push({contact_id:d,leave_request_id:f.request.id,text:f.comment.text}),f.comment.text=""},f.formatDateTime=function(e){return t.utc(e,s.serverDateTimeFormat).local().format(r.DATE_FORMAT.toUpperCase()+" HH:mm")},f.getActiveComments=function(){return f.request.comments.filter(function(e){return!e.toBeDeleted})},f.getCommentorName=function(e){return e===d?"Me":f.comment.contacts[e]?f.comment.contacts[e].display_name:void 0},f.isMode=function(e){return f.mode===e},f.orderComment=function(e){return t(e.created_at,s.serverDateTimeFormat)},f.removeCommentVisibility=function(e){return!e.comment_id||f.canManage}}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"directives/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","HR_settings","shared-settings","Contact","Session",a]})}),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,s,o,i,u,c){function l(){return e.filter(w.request.files,function(e){return e.toBeDeleted})}function d(){return w.fileUploader&&w.fileUploader.queue?w.fileUploader.queue:[]}function f(){$.push(a.$on("LeaveRequestPopup::submit",y))}function m(){v().then(function(){w.fileUploader=u.uploader({entityTable:"civicrm_hrleaveandabsences_leave_request",crmAttachmentToken:o.attachmentToken,queueLimit:o.fileUploader.queueLimit,allowedMimeTypes:q})})}function h(){return _.length>0?_.map(function(e){return e.label}).join(", "):""}function p(){return w.request.loadAttachments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function v(){return r.all(_.map(function(e){return c.getMimeTypeFor(e.label).then(function(t){q[e.label]=t})})).catch(function(){q=null})}function b(){return i.valuesOf("safe_file_extension").then(function(e){_=e})}function g(){e.forEach($,function(e){e()})}function y(e,t){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var _=[],$=[],q={},w=Object.create(this);return w.filesLoaded=!1,w.today=Date.now(),w.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",w.userDateFormat=s.DATE_FORMAT,w.listFileTypes=h,w.$onDestroy=g,w.canUploadMore=function(){return w.getFilesCount()-1&&(this.mode="view")}else this.mode="create"}function z(){return Ne="staff",d(y.permissions.admin.administer).then(function(e){Ne=e?"admin":Ne}).then(function(){return"staff"===Ne&&d(y.permissions.ssp.manage).then(function(e){Ne=e?"manager":Ne})}).finally(function(){this.canManage=this.isRole("manager")||this.isRole("admin"),this.isSelfRecord=this.directiveOptions.isSelfRecord}.bind(this))}function K(){(this.isRole("admin")||this.isMode("create")&&this.isRole("manager"))&&(this.newStatusOnSave=this.requestStatuses[y.statusNames.approved].value)}function J(e){var t=this.getStatusFromValue(this.request.status_id);return!!t&&t.name===e}function X(e){return this.request.request_type===e}function Z(e){return this.mode===e}function Q(e){return Ne===e}function ee(e,t){var n=this.period.id;return t=t||"from",this.loading[t+"DayTypes"]=!0,this._checkAndSetAbsencePeriod(e).then(function(){var e=n===this.period.id;if(!e)return this.uiOptions.multipleDays&&"from"===t&&(this.uiOptions.showBalance=!1,this.uiOptions.toDate=null,this.request.to_date=null,this.request.to_date_type=null),r.all([this._loadAbsenceTypes(),this._loadCalendar()])}.bind(this)).then(function(){return this._setMinMaxDate(),R.call(this,e,t)}.bind(this)).finally(function(){this.loading[t+"DayTypes"]=!1}.bind(this))}function te(){var e=this;return u.all().then(function(t){e.absencePeriods=t})}function ne(){var e=this;return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(t){e.requestDayTypes=t})}function ae(){return v.get().then(function(e){Be=e.contactId})}function re(){return this.directiveOptions.selectedContactId?o.find(this.directiveOptions.selectedContactId).then(function(e){this.managedContacts=[e]}.bind(this)):this.isRole("admin")?o.all().then(function(e){this.managedContacts=n.remove(e.list,function(e){return e.id!==Be})}.bind(this)):o.find(Be).then(function(e){return e.leaveManagees()}).then(function(e){this.managedContacts=e}.bind(this))}function se(){var e=this;return l.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){e.requestStatuses=n.indexBy(t,"name")})}function oe(e,t){return t.map(function(t){var a=n.find(e,function(e){return e.id===t.type_id});return{id:t.type_id,title:a.title+" ( "+t.remainder.current+" ) ",remainder:t.remainder.current,allow_overuse:a.allow_overuse}})}function ie(){this.$modalInstance.close({$value:this.request})}function ue(){var e=(this.currentPage-1)*this.numPerPage,t=e+this.numPerPage;this.filteredbreakdown=Ue.balance.change.breakdown.slice(e,t)}function ce(e){_.call(this),s.$emit(e,this.request),this.errors=[],this.ok()}function le(){this.pagination.totalItems=this.balance.change.breakdown.length,this.pagination.filteredbreakdown=this.balance.change.breakdown,this.pagination.pageChanged()}function de(e){var t=this;return h.all({contact_id:t.request.contact_id,period_id:t.period.id,type_id:{IN:e.ids}},!0).then(function(n){if(t.absenceTypes=oe(e.types,n),!t.absenceTypes.length)return r.reject(He)})}function fe(){(this.isMode("edit")&&this.request.from_date===this.request.to_date||this.isMode("create")&&this.isLeaveType("sickness"))&&(this.uiOptions.multipleDays=!1)}function me(e,t){var a="request"+n.startCase(e)+"DayTypes";this[a]=t,this.isMode("create")&&(this.request[e+"_date_type"]=this[a][0].value)}function he(){this.isMode("create")?(this.selectedAbsenceType=this.absenceTypes[0],this.request.type_id=this.selectedAbsenceType.id):this.selectedAbsenceType=E.call(this)}function pe(){je=e.copy(this.request.attributes())}function ve(){var e=this.request.status_id;if(!this.isMode("view")&&!this.submitting)return this.submitting=!0,P.call(this),qe.call(this).then(function(){return this.isMode("edit")?$e.call(this):D.call(this)}.bind(this)).catch(function(t){this.request.status_id=e,t&&F.call(this,t)}.bind(this)).finally(function(){this.submitting=!1}.bind(this))}function be(){function e(e){e&&n.push(e),++a===Le&&(ge(),n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Le>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function ge(){n.forEach(Fe,function(e){e()})}function ye(e,t){return this.loadAbsencePeriodDatesTypes(e,t).then(function(){return this.updateBalance()}.bind(this)).catch(function(e){F.call(this,e),this._setDateAndTypes()}.bind(this))}function _e(){this.selectedAbsenceType=E.call(this),this.balance.opening=this.selectedAbsenceType.remainder,this.calculateBalanceChange()}function $e(){return this.request.update().then(be).then(function(){this.isRole("manager")?ce.call(this,"LeaveRequest::updatedByManager"):(this.isRole("staff")||this.isRole("admin"))&&ce.call(this,"LeaveRequest::edit")}.bind(this))}function qe(){return this.balance.closing<0&&"0"===this.selectedAbsenceType.allow_overuse?r.reject(["You cannot make a request for this leave type at this time as this would leave you with a negative balance"]):this.request.isValid()}function we(){this.balance.opening=this.selectedAbsenceType.remainder,this.balance.closing=this.balance.opening+this.balance.change.amount}function Ae(e){var t=a(e).format(this.uiOptions.userDateFormat.toUpperCase());return this.period=n.find(this.absencePeriods,function(e){return e.isInPeriod(t)}),this.period?r.resolve(!0):(this.period={},this.loading.fromDayTypes=!1,r.reject("Please change date as it is not in any absence period")); -}function Pe(e){return a(e,y.serverDateFormat).toDate()}function Ce(e){return a(e).format(y.serverDateFormat)}function De(){return H.call(this),G.call(this),ae.call(this).then(z.bind(this)).then(this._initRequest.bind(this)).then(se.bind(this)).then(function(){return Y.call(this),this.canManage&&!this.isMode("edit")&&re.call(this)}.bind(this)).then(te.bind(this)).then(function(){N.call(this),this._setMinMaxDate()}.bind(this)).then(function(){if(this.directiveOptions.selectedContactId&&(this.request.contact_id=this.directiveOptions.selectedContactId),fe.call(this),this.request.contact_id)return this.initAfterContactSelection()}.bind(this)).catch(F.bind(this))}function Se(){var e={};return this.directiveOptions.leaveRequest?e=this.directiveOptions.leaveRequest.attributes():this.canManage||(e={contact_id:Be}),e}function Te(){var e=this;return c.all(e.initParams.absenceType).then(function(t){var n=t.map(function(e){return e.id});return Me={types:t,ids:n},de.call(e,Me)})}function Re(){var e=this;return m.get(e.request.contact_id,e.period.start_date,e.period.end_date).then(function(t){e.calendar=t})}function Oe(){this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date_type=this.request.from_date_type,this.request.to_date=this.request.from_date,this.calculateBalanceChange()}function Ie(){this._setDates(),this.uiOptions.multipleDays?this.uiOptions.showBalance=!!(this.request.from_date&&this.request.from_date_type&&this.request.to_date&&this.request.to_date_type&&this.period.id):(this.uiOptions.fromDate&&(this.request.to_date_type=this.request.from_date_type),this.uiOptions.showBalance=!!this.request.from_date&&!!this.request.from_date_type&&!!this.period.id)}function ke(){this.request.from_date=this.uiOptions.fromDate?this._convertDateToServerFormat(this.uiOptions.fromDate):null,this.request.to_date=this.uiOptions.toDate?this._convertDateToServerFormat(this.uiOptions.toDate):null,!this.uiOptions.multipleDays&&this.uiOptions.fromDate&&(this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date=this.request.from_date)}function xe(){if(this.uiOptions.fromDate){var e=a(this.uiOptions.fromDate).add(1,"d").toDate();this.uiOptions.date.to.options.minDate=e,this.uiOptions.date.to.options.initDate=e,this.uiOptions.toDate&&a(this.uiOptions.toDate).isBefore(this.uiOptions.fromDate)&&(this.uiOptions.toDate=this.uiOptions.fromDate)}else this.uiOptions.date.to.options.minDate=this._convertDateFormatFromServer(this.period.start_date),this.uiOptions.date.to.options.initDate=this.uiOptions.date.to.options.minDate;this.uiOptions.date.to.options.maxDate=this._convertDateFormatFromServer(this.period.end_date)}t.debug("RequestCtrl");var Me,Ee={},Le=0,je={},Fe=[],Be="",Ne="",Ue=this,He="No entitlement";this.absencePeriods=[],this.absenceTypes=[],this.calendar={},this.canManage=!1,this.contactName=null,this.errors=[],this.fileUploader=null,this.isSelfRecord=!1,this.managedContacts=[],this.mode="",this.newStatusOnSave=null,this.period={},this.postContactSelection=!1,this.requestDayTypes=[],this.requestStatuses={},this.selectedAbsenceType={},this.statusNames=y.statusNames,this.submitting=!1,this.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},this.loading={absenceTypes:!0,showBalanceChange:!1,fromDayTypes:!1,toDayTypes:!1},this.pagination={currentPage:1,filteredbreakdown:this.balance.change.breakdown,numPerPage:7,totalItems:this.balance.change.breakdown.length,pageChanged:ue},this.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:p.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}}}},this.changeInNoOfDays=A,this.calculateBalanceChange=$,this.canSubmit=w,this.closeAlert=C,this.deleteLeaveRequest=S,this.dismissModal=T,this.formatDateTime=O,this.getStatuses=L,this.getStatusFromValue=j,this.initAfterContactSelection=U,this.isLeaveStatus=J,this.isLeaveType=X,this.isMode=Z,this.isRole=Q,this.ok=ie,this.submit=ve,this.loadAbsencePeriodDatesTypes=ee,this.updateAbsencePeriodDatesTypes=ye,this.updateBalance=_e,this._calculateOpeningAndClosingBalance=we,this._checkAndSetAbsencePeriod=Ae,this._convertDateToServerFormat=Ce,this._convertDateFormatFromServer=Pe,this._init=De,this._initRequestAttributes=Se,this._loadCalendar=Re,this._loadAbsenceTypes=Te,this._reset=Oe,this._setDates=ke,this._setDateAndTypes=Ie,this._setMinMaxDate=xe}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","Contact","dialog","AbsencePeriod","AbsenceType","api.optionGroup","checkPermissions","pubSub","Calendar","Entitlement","HR_settings","Session","LeaveRequest","PublicHoliday","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/leave-request.controller",["leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/leave-request.instance"],function(e){function t(e,t,n,a,r){function s(){var e=i._initRequestAttributes();i.request=r.init(e)}t.debug("LeaveRequestCtrl");var o=e("RequestCtrl"),i=Object.create(o);return i.directiveOptions=a,i.$modalInstance=n,i.initParams={absenceType:{is_sick:!1}},i._initRequest=s,function(){i.loading.absenceTypes=!0,i._init().finally(function(){i.loading.absenceTypes=!1})}(),i}e.controller("LeaveRequestCtrl",t),t.$inject=["$controller","$log","$uibModalInstance","directiveOptions","LeaveRequestInstance"]}),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(){var e=this.sickness_required_documents?this.sickness_required_documents.split(","):[];return e},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/controllers/sub-controllers/sick-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/sickness-request.instance"],function(e,t){function n(t,n,a,r,s,o,i){function u(){return h.canSubmit.call(this)&&!!p.request.sickness_reason}function c(t){var n=p.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function l(t){return!!e.find(p.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){p.sicknessDocumentTypes=e})}function f(){return s.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){p.sicknessReasons=e.indexBy(t,"name")})}function m(){var e=p._initRequestAttributes();p.request=i.init(e)}n.debug("SicknessRequestCtrl");var h=t("RequestCtrl"),p=Object.create(h);return p.directiveOptions=o,p.$modalInstance=r,p.initParams={absenceType:{is_sick:!0}},p.canSubmit=u,p.isChecked=c,p.isDocumentInRequest=l,p._initRequest=m,function(){p.loading.absenceTypes=!0,p._init().then(function(){return a.all([d(),f()])}).finally(function(){p.loading.absenceTypes=!1})}(),p}t.controller("SicknessRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","directiveOptions","SicknessRequestInstance"]}),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/sub-controllers/toil-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/toil-request.instance"],function(e,t){function n(t,n,a,r,s,o,i,u){function c(){P.request.toil_to_accrue&&(P.loading.showBalanceChange=!0,P._setDateAndTypes(),P.balance.change.amount=+P.request.toil_to_accrue,P._calculateOpeningAndClosingBalance(),P.uiOptions.showBalance=!0,P.request.to_date_type=P.request.from_date_type="1",P.loading.showBalanceChange=!1)}function l(){return!P.canManage&&P.request.id?a.resolve(P.request.toil_expiry_date):P.requestCanExpire?p().catch(function(e){return e.length&&(P.errors=e),a.reject(e)}).then(function(e){return o.calculateToilExpiryDate(P.request.type_id,e)}).then(function(e){return P.request.toil_expiry_date=e,P.uiOptions.expiryDate=new Date(e),e}):(P.request.toil_expiry_date=!1,a.resolve(!1))}function d(){return P.uiOptions.multipleDays&&P.request.to_date||!P.uiOptions.multipleDays&&P.request.from_date}function f(){return A.canSubmit.call(this)&&!!P.request.toil_duration&&!!P.request.toil_to_accrue&&!!P.request.from_date&&!!P.request.to_date}function m(){A.changeInNoOfDays.call(this),d()&&P.calculateToilExpiryDate()}function h(){P.request.toil_expiry_date=!1,P.uiOptions.expiryDate=null}function p(){return v(P.uiOptions.multipleDays?{hasErrors:!P.request.to_date&&!P.request.from_date,label:"To Date",value:P.request.to_date}:{hasErrors:!P.request.from_date,label:"From Date",value:P.request.from_date})}function v(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(e.value):a.reject([])}function b(){P.canManage&&(P.uiOptions.expiryDate=P._convertDateFormatFromServer(P.request.toil_expiry_date))}function g(){return o.canExpire(P.request.type_id).then(function(e){P.requestCanExpire=e})}function y(e){var t=P.period.id;return P._checkAndSetAbsencePeriod(e).then(function(){var e=t===P.period.id;if(!e)return P.uiOptions.multipleDays&&(P.uiOptions.showBalance=!1,P.uiOptions.toDate=null,P.request.to_date=null),a.all([P._loadAbsenceTypes(),P._loadCalendar()])})}function _(){return s.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){P.toilAmounts=e.indexBy(t,"value")})}function $(e){return P.loadAbsencePeriodDatesTypes().then(function(){P._setMinMaxDate(),P._setDates(),P.updateBalance(),P.calculateToilExpiryDate()}).catch(function(e){P.errors=[e]})}function q(){P.uiOptions.expiryDate&&(P.request.toil_expiry_date=P._convertDateToServerFormat(P.uiOptions.expiryDate))}function w(){var e=P._initRequestAttributes();P.request=u.init(e),P.request.to_date_type=P.request.from_date_type="1"}n.debug("ToilRequestCtrl");var A=t("RequestCtrl"),P=Object.create(A);return P.requestCanExpire=!0,P.directiveOptions=i,P.$modalInstance=r,P.initParams={absenceType:{allow_accruals_request:!0}},P.calculateBalanceChange=c,P.calculateToilExpiryDate=l,P.canSubmit=f,P.changeInNoOfDays=m,P.clearExpiryDate=h,P.loadAbsencePeriodDatesTypes=y,P.updateAbsencePeriodDatesTypes=$,P.updateExpiryDate=q,P._initRequest=w,function(){P.loading.absenceTypes=!0,P._init().then(function(){return g()}).then(function(){return b(),_()}).finally(function(){P.loading.absenceTypes=!1})}(),P}t.controller("ToilRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","AbsenceType","directiveOptions","TOILRequestInstance"]}),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-popup.service",["common/lodash","leave-absences/shared/modules/services","common/services/notification.service"],function(e,t){"use strict";function n(t,n,a,r,s,o,i,u,c,l){function d(e){return c.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function f(e,t){return t?t.request_type:e||null}function m(t,a,r,o){var u=e.capitalize(f(a,t))+"RequestCtrl";s.open({appendTo:n.children().eq(0),templateUrl:i.sharedPathTpl+"directives/leave-request-popup/leave-request-popup.html",controller:u,controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveRequest:t,selectedContactId:r,isSelfRecord:o}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function h(e){return l.find(e).then(function(e){return d(e).then(function(t){t?m(e,e.request_type,e.contact_id,"my-leave"===a.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return t.debug("LeavePopup"),{openModal:m,openModalByID:h}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$q","$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",function(e,t){e.debug("Component: my-leave-container"),t.section="my-leave"}]})}),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,s,o){s.debugEnabled(o.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/modules/dialog","common/models/option-group","common/directives/loading","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-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/leave-request.controller","leave-absences/shared/controllers/sub-controllers/sick-request.controller","leave-absences/shared/controllers/sub-controllers/toil-request.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.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(){}); \ No newline at end of file +return e.sharedPathTpl+"components/leave-calendar.html"}],controllerAs:"calendar",controller:["$controller","$q","$log","$rootScope","$timeout","shared-settings","AbsencePeriod","AbsenceType","LeaveRequest","PublicHoliday","OptionGroup","Calendar","checkPermissions",r]})}),define("leave-absences/shared/components/leave-calendar-day.component",["leave-absences/shared/modules/components"],function(e){function t(e,t){"use strict";function n(e,n,a,r,s){e.stopPropagation(),t.openModal(n,a,r,s)}e.debug("Component: leave-calendar-day");var a=this;a.openLeavePopup=n}e.component("leaveCalendarDay",{bindings:{contactData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-day.html"}],controllerAs:"day",controller:t}),t.$inject=["$log","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.collapsed=!1,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"],function(e,t,n){function a(n,a,r,s,o,i){function u(e,t){v([t]),x(t)}function c(e){return{index:e.month(),year:e.year(),name:e.format("MMMM"),loading:!0,days:l(e)}}function l(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(F.period.start_date)&&r.isSameOrBefore(F.period.end_date),contactsData:{}};return r.add(1,"day"),e})}function d(e){return L[e]}function f(){return F.showOnlyWithLeaveRequests?F.contacts.filter(function(t){return e.includes(Object.keys(j),t.id)}):F.contacts}function m(e){return t(e,i.serverDateFormat)}function h(e,t){D(t),x(t)}function p(){F.supportData.dayTypes=e.indexBy(F.supportData.dayTypes,"name"),F.supportData.leaveRequestStatuses=e.indexBy(F.supportData.leaveRequestStatuses,"value"),F.supportData.publicHolidays=e.transform(F.supportData.publicHolidays,function(e,t){e[m(t.date).valueOf()]=t},{})}function v(e){return e.forEach(function(e){var t=$(e);j[e.contact_id]=j[e.contact_id]||{},t.forEach(function(t){j[e.contact_id][t.date]=e})}),a.resolve()}function b(){E.push(r.$on("LeaveCalendar::showMonths",O)),E.push(r.$on("LeaveRequest::new",u)),E.push(r.$on("LeaveRequest::edit",k)),E.push(r.$on("LeaveRequest::updatedByManager",k)),E.push(r.$on("LeaveRequest::deleted",h))}function g(e,n,a){var r=F.supportData.dayTypes[e];return t(a).isSame(n.from_date)?r.value===n.from_date_type:t(a).isSame(n.to_date)?r.value===n.to_date_type:void 0}function y(e){var t=F.supportData.leaveRequestStatuses[e.status_id];return t.name===i.statusNames.awaitingApproval}function _(e){return!!F.supportData.publicHolidays[m(e).valueOf()]}function $(n){for(var a=[],r=t(n.from_date).clone(),s=t(n.to_date);r.isSameOrBefore(s);)r.month()===F.month.index&&r.year()===F.month.year&&a.push(e.find(F.month.days,function(e){return e.date===r.format("YYYY-MM-DD")})),r.add(1,"day");return a}function q(t){return e.find(j[t.contact_id],function(e){return t.id===e.id})}function w(t){var n=e.find(F.supportData.leaveRequestStatuses,function(e){return e.name===t});return n?n.value:null}function A(){return F.month.loading=!0,a.all([C(),P()]).then(function(){return R()}).then(function(){M=!0}).then(function(){F.month.loading=!1})}function P(){var e={from:F.month.days[0].date,to:F.month.days[F.month.days.length-1].date};return o.all({from_date:e,to_date:e,options:{or:[["from_date","to_date"]]},status_id:{IN:[w(i.statusNames.approved),w(i.statusNames.adminApproved),w(i.statusNames.awaitingApproval)]},contact_id:{IN:F.contacts.map(function(e){return e.id})}},null,null,null,!1).then(function(e){return v(e.list)})}function C(){var t=F.month.days[0].date,n=F.month.days[F.month.days.length-1].date;return s.get(F.contacts.map(function(e){return e.id}),t,n).then(function(t){L=e.indexBy(t,"contact_id")})}function D(t){j[t.contact_id]=e.omit(j[t.contact_id],function(e){return e.id===t.id})}function S(){r.$emit("LeaveCalendar::monthDestroyed"),E.map(function(e){e()})}function T(t,n,r){var s,o;return t.contactsData[n]=t.contactsData[n]||{},o=d(n),s=r===!0?a.resolve():a.all([o.isWeekend(m(t.date)),o.isNonWorkingDay(m(t.date))]).then(function(a){e.assign(t.contactsData[n],{isWeekend:a[0],isNonWorkingDay:a[1],isPublicHoliday:_(t.date)})}),s.then(function(){return j[n]?j[n][t.date]:null}).then(function(a){e.assign(t.contactsData[n],{leaveRequest:a||null,styles:a?I(a):null,isAccruedTOIL:a?a.balance_change>0:null,isRequested:a?y(a):null,isAM:a?g("half_day_am",a,t.date):null,isPM:a?g("half_day_pm",a,t.date):null})})}function R(){return a.all(F.month.days.map(function(e){return a.all(F.contacts.map(function(t){return T(e,t.id)}))}))}function O(t,n,a){var r=!!e.find(n,function(e){return e.index===F.month.index});r?(F.currentPage=0,F.visible=!0,(a||!M)&&A()):F.visible=!1}function I(t){var n=e.find(F.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 k(e,t){var n=q(t);h(null,n),u(null,t)}function x(e){return a.all($(e).map(function(t){return T(t,e.contact_id,!0)}))}n.debug("Component: leave-calendar-month");var M=!1,E=[],L={},j={},F=this;F.currentPage=0,F.pageSize=20,F.visible=!1,F.showContactName=!!F.showContactName,F.showOnlyWithLeaveRequests=!!F.showOnlyWithLeaveRequests,F.$onDestroy=S,F.contactsList=f,function(){var e=t().month(F.month.index).year(F.month.year);p(),b(),F.month=c(e),r.$emit("LeaveCalendar::monthInjected")}()}n.component("leaveCalendarMonth",{bindings:{contacts:"<",month:"<",period:"<",showContactName:"<",showOnlyWithLeaveRequests:"<",supportData:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"components/leave-calendar-month.html"}],controllerAs:"month",controller:["$log","$q","$rootScope","Calendar","LeaveRequest","shared-settings",a]})}),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"],function(e,t,n){function a(n,a,r,s,o,i,u){function c(e){var t=y[e].dialog;v=b.leaveRequest.status_id,r.open({title:"Confirm "+t.title+"?",copyCancel:"Cancel",copyConfirm:t.btnLabel,classConfirm:"btn-"+t.btnClass,msg:t.msg,onConfirm:function(){return b.leaveRequest[e]().then(function(){m(e)}).catch(function(e){u.error("Error:",e)})}})}function l(){var e=b.absenceTypes[b.leaveRequest.type_id].allow_request_cancelation;return"admin"===b.role||"manager"===b.role||("3"===e?t().isBefore(b.leaveRequest.from_date):"2"===e)}function d(){Array.isArray(b.leaveRequestStatuses)&&(b.leaveRequestStatuses=e.indexBy(b.leaveRequestStatuses,"value")),Array.isArray(b.absenceTypes)&&(b.absenceTypes=e.indexBy(b.absenceTypes,"id"))}function f(e,t,n,a,r){e.stopPropagation(),s.openModal(t,n,a,r)}function m(t){var n=e.find(b.leaveRequestStatuses,function(e){return e.name===i.statusNames.awaitingApproval}).value;v===n&&o.publish("ManagerBadge:: Update Count"),a.$emit("LeaveRequest::"+("delete"===t?"deleted":"edit"),b.leaveRequest)}function h(){var t=b.leaveRequestStatuses[b.leaveRequest.status_id].name,n=e.compact(e.map(y,function(n,a){return e.includes(n.allowedStatuses,t)?a:null}));!l()&&e.pull(n,"cancel"),"admin"!==b.role&&e.pull(n,"delete"),"staff"===b.role&&e.pull(n,"approve","reject"),"staff"!==b.role&&p(n),b.allowedActions=e.map(n,function(e){return{key:e,label:y[e].label,isDirectAction:y[e].isDirectAction}})}function p(t){e.each(t,function(e,n){"edit"===e&&(t[n]="respond"),"respond"===e&&(t[n]="edit")})}n.debug("Component: leave-request-action-dropdown");var v,b=this,g=i.statusNames,y={edit:{label:"Edit",allowedStatuses:[g.awaitingApproval]},respond:{label:"Respond",allowedStatuses:[g.moreInformationRequired]},view:{label:"View",allowedStatuses:[g.approved,g.rejected,g.cancelled]},approve:{label:"Approve",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Approval",btnClass:"success",btnLabel:"Approve",msg:"Please confirm approval"}},reject:{label:"Reject",isDirectAction:!0,allowedStatuses:[g.awaitingApproval],dialog:{title:"Rejection",btnClass:"warning",btnLabel:"Reject",msg:"Please confirm rejection"}},cancel:{label:"Cancel",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired],dialog:{title:"Cancellation",btnClass:"danger",btnLabel:"Confirm",msg:"Please confirm cancellation"}},delete:{label:"Delete",isDirectAction:!0,allowedStatuses:[g.awaitingApproval,g.moreInformationRequired,g.approved,g.rejected,g.cancelled],dialog:{title:"Deletion",btnClass:"danger",btnLabel:"Confirm",msg:"This cannot be undone"}}};b.allowedActions=[],b.action=c,b.openLeavePopup=f,function(){d(),h()}()}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","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,s,o,i){function u(){var t=e.indexBy(f.request.comments,"contact_id"),n=Object.keys(t);return o.all({id:{IN:n}},{page:1,size:0}).then(function(t){f.comment.contacts=e.indexBy(t.list,"contact_id")})}function c(){return f.request.loadComments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated"),f.request.comments.length&&u()})}function l(){return f.loading.component=!0,i.get().then(function(e){d=e.contactId}).then(function(){f.loading.component=!1})}n.debug("Component: leave-request-popup-comments-tab");var d=null,f=this;f.loading={component:!0},f.comment={text:"",contacts:{}},function(){c(),l()}(),f.addComment=function(){f.request.comments.push({contact_id:d,leave_request_id:f.request.id,text:f.comment.text}),f.comment.text=""},f.formatDateTime=function(e){return t.utc(e,s.serverDateTimeFormat).local().format(r.DATE_FORMAT.toUpperCase()+" HH:mm")},f.getActiveComments=function(){return f.request.comments.filter(function(e){return!e.toBeDeleted})},f.getCommentorName=function(e){return e===d?"Me":f.comment.contacts[e]?f.comment.contacts[e].display_name:void 0},f.isMode=function(e){return f.mode===e},f.orderComment=function(e){return t(e.created_at,s.serverDateTimeFormat)},f.removeCommentVisibility=function(e){return!e.comment_id||f.canManage}}n.component("leaveRequestPopupCommentsTab",{bindings:{canManage:"<",mode:"<",request:"<"},templateUrl:["shared-settings",function(e){return e.sharedPathTpl+"directives/leave-request-popup/leave-request-popup-comments-tab.html"}],controllerAs:"commentsCtrl",controller:["$log","$rootScope","HR_settings","shared-settings","Contact","Session",a]})}),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,s,o,i,u,c){function l(){return e.filter(w.request.files,function(e){return e.toBeDeleted})}function d(){return w.fileUploader&&w.fileUploader.queue?w.fileUploader.queue:[]}function f(){$.push(a.$on("LeaveRequestPopup::submit",y))}function m(){v().then(function(){w.fileUploader=u.uploader({entityTable:"civicrm_hrleaveandabsences_leave_request",crmAttachmentToken:o.attachmentToken,queueLimit:o.fileUploader.queueLimit,allowedMimeTypes:q})})}function h(){return _.length>0?_.map(function(e){return e.label}).join(", "):""}function p(){return w.request.loadAttachments().then(function(){a.$broadcast("LeaveRequestPopup::requestObjectUpdated")})}function v(){return r.all(_.map(function(e){return c.getMimeTypeFor(e.label).then(function(t){q[e.label]=t})})).catch(function(){q=null})}function b(){return i.valuesOf("safe_file_extension").then(function(e){_=e})}function g(){e.forEach($,function(e){e()})}function y(e,t){w.fileUploader.queue&&w.fileUploader.queue.length>0?w.fileUploader.uploadAll({entityID:w.request.id}).then(function(){t()}).catch(t):t()}n.debug("Component: leave-request-popup-files-tab");var _=[],$=[],q={},w=Object.create(this);return w.filesLoaded=!1,w.today=Date.now(),w.userDateFormatWithTime=s.DATE_FORMAT+" HH:mm",w.userDateFormat=s.DATE_FORMAT,w.listFileTypes=h,w.$onDestroy=g,w.canUploadMore=function(){return w.getFilesCount()-1&&(this.mode="view")}else this.mode="create"}function z(){return Ne="staff",d(y.permissions.admin.administer).then(function(e){Ne=e?"admin":Ne}).then(function(){return"staff"===Ne&&d(y.permissions.ssp.manage).then(function(e){Ne=e?"manager":Ne})}).finally(function(){this.canManage=this.isRole("manager")||this.isRole("admin"),this.isSelfRecord=this.directiveOptions.isSelfRecord}.bind(this))}function K(){(this.isRole("admin")||this.isMode("create")&&this.isRole("manager"))&&(this.newStatusOnSave=this.requestStatuses[y.statusNames.approved].value)}function J(e){var t=this.getStatusFromValue(this.request.status_id);return!!t&&t.name===e}function X(e){return this.request.request_type===e}function Z(e){return this.mode===e}function Q(e){return Ne===e}function ee(e,t){var n=this.period.id;return t=t||"from",this.loading[t+"DayTypes"]=!0,this._checkAndSetAbsencePeriod(e).then(function(){var e=n===this.period.id;if(!e)return this.uiOptions.multipleDays&&"from"===t&&(this.uiOptions.showBalance=!1,this.uiOptions.toDate=null,this.request.to_date=null,this.request.to_date_type=null),r.all([this._loadAbsenceTypes(),this._loadCalendar()])}.bind(this)).then(function(){return this._setMinMaxDate(),R.call(this,e,t)}.bind(this)).finally(function(){this.loading[t+"DayTypes"]=!1}.bind(this))}function te(){var e=this;return u.all().then(function(t){e.absencePeriods=t})}function ne(){var e=this;return l.valuesOf("hrleaveandabsences_leave_request_day_type").then(function(t){e.requestDayTypes=t})}function ae(){return v.get().then(function(e){Be=e.contactId})}function re(){return this.directiveOptions.selectedContactId?o.find(this.directiveOptions.selectedContactId).then(function(e){this.managedContacts=[e]}.bind(this)):this.isRole("admin")?o.all().then(function(e){this.managedContacts=n.remove(e.list,function(e){return e.id!==Be})}.bind(this)):o.find(Be).then(function(e){return e.leaveManagees()}).then(function(e){this.managedContacts=e}.bind(this))}function se(){var e=this;return l.valuesOf("hrleaveandabsences_leave_request_status").then(function(t){e.requestStatuses=n.indexBy(t,"name")})}function oe(e,t){return t.map(function(t){var a=n.find(e,function(e){return e.id===t.type_id});return{id:t.type_id,title:a.title+" ( "+t.remainder.current+" ) ",remainder:t.remainder.current,allow_overuse:a.allow_overuse}})}function ie(){this.$modalInstance.close({$value:this.request})}function ue(){var e=(this.currentPage-1)*this.numPerPage,t=e+this.numPerPage;this.filteredbreakdown=Ue.balance.change.breakdown.slice(e,t)}function ce(e){_.call(this),s.$emit(e,this.request),this.errors=[],this.ok()}function le(){this.pagination.totalItems=this.balance.change.breakdown.length,this.pagination.filteredbreakdown=this.balance.change.breakdown,this.pagination.pageChanged()}function de(e){var t=this;return h.all({contact_id:t.request.contact_id,period_id:t.period.id,type_id:{IN:e.ids}},!0).then(function(n){if(t.absenceTypes=oe(e.types,n),!t.absenceTypes.length)return r.reject(He)})}function fe(){(this.isMode("edit")&&this.request.from_date===this.request.to_date||this.isMode("create")&&this.isLeaveType("sickness"))&&(this.uiOptions.multipleDays=!1)}function me(e,t){var a="request"+n.startCase(e)+"DayTypes";this[a]=t,this.isMode("create")&&(this.request[e+"_date_type"]=this[a][0].value)}function he(){this.isMode("create")?(this.selectedAbsenceType=this.absenceTypes[0],this.request.type_id=this.selectedAbsenceType.id):this.selectedAbsenceType=E.call(this)}function pe(){je=e.copy(this.request.attributes())}function ve(){var e=this.request.status_id;if(!this.isMode("view")&&!this.submitting)return this.submitting=!0,P.call(this),qe.call(this).then(function(){return this.isMode("edit")?$e.call(this):D.call(this)}.bind(this)).catch(function(t){this.request.status_id=e,t&&F.call(this,t)}.bind(this)).finally(function(){this.submitting=!1}.bind(this))}function be(){function e(e){e&&n.push(e),++a===Le&&(ge(),n.length>0?t.reject(n):t.resolve())}var t=r.defer(),n=[],a=0;return Le>0?s.$broadcast("LeaveRequestPopup::submit",e):t.resolve(),t.promise}function ge(){n.forEach(Fe,function(e){e()})}function ye(e,t){return this.loadAbsencePeriodDatesTypes(e,t).then(function(){return this.updateBalance()}.bind(this)).catch(function(e){F.call(this,e),this._setDateAndTypes()}.bind(this))}function _e(){this.selectedAbsenceType=E.call(this),this.balance.opening=this.selectedAbsenceType.remainder,this.calculateBalanceChange()}function $e(){return this.request.update().then(be).then(function(){this.isRole("manager")?ce.call(this,"LeaveRequest::updatedByManager"):(this.isRole("staff")||this.isRole("admin"))&&ce.call(this,"LeaveRequest::edit")}.bind(this))}function qe(){return this.balance.closing<0&&"0"===this.selectedAbsenceType.allow_overuse?r.reject(["You cannot make a request for this leave type at this time as this would leave you with a negative balance"]):this.request.isValid()}function we(){this.balance.opening=this.selectedAbsenceType.remainder,this.balance.closing=this.balance.opening+this.balance.change.amount}function Ae(e){var t=a(e).format(this.uiOptions.userDateFormat.toUpperCase());return this.period=n.find(this.absencePeriods,function(e){return e.isInPeriod(t)}),this.period?r.resolve(!0):(this.period={}, +this.loading.fromDayTypes=!1,r.reject("Please change date as it is not in any absence period"))}function Pe(e){return a(e,y.serverDateFormat).toDate()}function Ce(e){return a(e).format(y.serverDateFormat)}function De(){return H.call(this),G.call(this),ae.call(this).then(z.bind(this)).then(this._initRequest.bind(this)).then(se.bind(this)).then(function(){return Y.call(this),this.canManage&&!this.isMode("edit")&&re.call(this)}.bind(this)).then(te.bind(this)).then(function(){N.call(this),this._setMinMaxDate()}.bind(this)).then(function(){if(this.directiveOptions.selectedContactId&&(this.request.contact_id=this.directiveOptions.selectedContactId),fe.call(this),this.request.contact_id)return this.initAfterContactSelection()}.bind(this)).catch(F.bind(this))}function Se(){var e={};return this.directiveOptions.leaveRequest?e=this.directiveOptions.leaveRequest.attributes():this.canManage||(e={contact_id:Be}),e}function Te(){var e=this;return c.all(e.initParams.absenceType).then(function(t){var n=t.map(function(e){return e.id});return Me={types:t,ids:n},de.call(e,Me)})}function Re(){var e=this;return m.get(e.request.contact_id,e.period.start_date,e.period.end_date).then(function(t){e.calendar=t})}function Oe(){this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date_type=this.request.from_date_type,this.request.to_date=this.request.from_date,this.calculateBalanceChange()}function Ie(){this._setDates(),this.uiOptions.multipleDays?this.uiOptions.showBalance=!!(this.request.from_date&&this.request.from_date_type&&this.request.to_date&&this.request.to_date_type&&this.period.id):(this.uiOptions.fromDate&&(this.request.to_date_type=this.request.from_date_type),this.uiOptions.showBalance=!!this.request.from_date&&!!this.request.from_date_type&&!!this.period.id)}function ke(){this.request.from_date=this.uiOptions.fromDate?this._convertDateToServerFormat(this.uiOptions.fromDate):null,this.request.to_date=this.uiOptions.toDate?this._convertDateToServerFormat(this.uiOptions.toDate):null,!this.uiOptions.multipleDays&&this.uiOptions.fromDate&&(this.uiOptions.toDate=this.uiOptions.fromDate,this.request.to_date=this.request.from_date)}function xe(){if(this.uiOptions.fromDate){var e=a(this.uiOptions.fromDate).add(1,"d").toDate();this.uiOptions.date.to.options.minDate=e,this.uiOptions.date.to.options.initDate=e,this.uiOptions.toDate&&a(this.uiOptions.toDate).isBefore(this.uiOptions.fromDate)&&(this.uiOptions.toDate=this.uiOptions.fromDate)}else this.uiOptions.date.to.options.minDate=this._convertDateFormatFromServer(this.period.start_date),this.uiOptions.date.to.options.initDate=this.uiOptions.date.to.options.minDate;this.uiOptions.date.to.options.maxDate=this._convertDateFormatFromServer(this.period.end_date)}t.debug("RequestCtrl");var Me,Ee={},Le=0,je={},Fe=[],Be="",Ne="",Ue=this,He="No entitlement";this.absencePeriods=[],this.absenceTypes=[],this.calendar={},this.canManage=!1,this.contactName=null,this.errors=[],this.fileUploader=null,this.isSelfRecord=!1,this.managedContacts=[],this.mode="",this.newStatusOnSave=null,this.period={},this.postContactSelection=!1,this.requestDayTypes=[],this.requestStatuses={},this.selectedAbsenceType={},this.statusNames=y.statusNames,this.submitting=!1,this.balance={closing:0,opening:0,change:{amount:0,breakdown:[]}},this.loading={absenceTypes:!0,showBalanceChange:!1,fromDayTypes:!1,toDayTypes:!1},this.pagination={currentPage:1,filteredbreakdown:this.balance.change.breakdown,numPerPage:7,totalItems:this.balance.change.breakdown.length,pageChanged:ue},this.uiOptions={isChangeExpanded:!1,multipleDays:!0,userDateFormat:p.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}}}},this.changeInNoOfDays=A,this.calculateBalanceChange=$,this.canSubmit=w,this.closeAlert=C,this.deleteLeaveRequest=S,this.dismissModal=T,this.formatDateTime=O,this.getStatuses=L,this.getStatusFromValue=j,this.initAfterContactSelection=U,this.isLeaveStatus=J,this.isLeaveType=X,this.isMode=Z,this.isRole=Q,this.ok=ie,this.submit=ve,this.loadAbsencePeriodDatesTypes=ee,this.updateAbsencePeriodDatesTypes=ye,this.updateBalance=_e,this._calculateOpeningAndClosingBalance=we,this._checkAndSetAbsencePeriod=Ae,this._convertDateToServerFormat=Ce,this._convertDateFormatFromServer=Pe,this._init=De,this._initRequestAttributes=Se,this._loadCalendar=Re,this._loadAbsenceTypes=Te,this._reset=Oe,this._setDates=ke,this._setDateAndTypes=Ie,this._setMinMaxDate=xe}t.controller("RequestCtrl",r),r.$inject=["$log","$q","$rootScope","Contact","dialog","AbsencePeriod","AbsenceType","api.optionGroup","checkPermissions","pubSub","Calendar","Entitlement","HR_settings","Session","LeaveRequest","PublicHoliday","shared-settings"]}),define("leave-absences/shared/controllers/sub-controllers/leave-request.controller",["leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/leave-request.instance"],function(e){function t(e,t,n,a,r){function s(){var e=i._initRequestAttributes();i.request=r.init(e)}t.debug("LeaveRequestCtrl");var o=e("RequestCtrl"),i=Object.create(o);return i.directiveOptions=a,i.$modalInstance=n,i.initParams={absenceType:{is_sick:!1}},i._initRequest=s,function(){i.loading.absenceTypes=!0,i._init().finally(function(){i.loading.absenceTypes=!1})}(),i}e.controller("LeaveRequestCtrl",t),t.$inject=["$controller","$log","$uibModalInstance","directiveOptions","LeaveRequestInstance"]}),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(){var e=this.sickness_required_documents?this.sickness_required_documents.split(","):[];return e},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/controllers/sub-controllers/sick-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/sickness-request.instance"],function(e,t){function n(t,n,a,r,s,o,i){function u(){return h.canSubmit.call(this)&&!!p.request.sickness_reason}function c(t){var n=p.request.getDocumentArray();return!!e.find(n,function(e){return e===t})}function l(t){return!!e.find(p.sicknessDocumentTypes,function(e){return e.value===t})}function d(){return s.valuesOf("hrleaveandabsences_leave_request_required_document").then(function(e){p.sicknessDocumentTypes=e})}function f(){return s.valuesOf("hrleaveandabsences_sickness_reason").then(function(t){p.sicknessReasons=e.indexBy(t,"name")})}function m(){var e=p._initRequestAttributes();p.request=i.init(e)}n.debug("SicknessRequestCtrl");var h=t("RequestCtrl"),p=Object.create(h);return p.directiveOptions=o,p.$modalInstance=r,p.initParams={absenceType:{is_sick:!0}},p.canSubmit=u,p.isChecked=c,p.isDocumentInRequest=l,p._initRequest=m,function(){p.loading.absenceTypes=!0,p._init().then(function(){return a.all([d(),f()])}).finally(function(){p.loading.absenceTypes=!1})}(),p}t.controller("SicknessRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","directiveOptions","SicknessRequestInstance"]}),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/sub-controllers/toil-request.controller",["common/lodash","leave-absences/shared/modules/controllers","leave-absences/shared/controllers/request.controller","leave-absences/shared/instances/toil-request.instance"],function(e,t){function n(t,n,a,r,s,o,i,u){function c(){P.request.toil_to_accrue&&(P.loading.showBalanceChange=!0,P._setDateAndTypes(),P.balance.change.amount=+P.request.toil_to_accrue,P._calculateOpeningAndClosingBalance(),P.uiOptions.showBalance=!0,P.request.to_date_type=P.request.from_date_type="1",P.loading.showBalanceChange=!1)}function l(){return!P.canManage&&P.request.id?a.resolve(P.request.toil_expiry_date):P.requestCanExpire?p().catch(function(e){return e.length&&(P.errors=e),a.reject(e)}).then(function(e){return o.calculateToilExpiryDate(P.request.type_id,e)}).then(function(e){return P.request.toil_expiry_date=e,P.uiOptions.expiryDate=new Date(e),e}):(P.request.toil_expiry_date=!1,a.resolve(!1))}function d(){return P.uiOptions.multipleDays&&P.request.to_date||!P.uiOptions.multipleDays&&P.request.from_date}function f(){return A.canSubmit.call(this)&&!!P.request.toil_duration&&!!P.request.toil_to_accrue&&!!P.request.from_date&&!!P.request.to_date}function m(){A.changeInNoOfDays.call(this),d()&&P.calculateToilExpiryDate()}function h(){P.request.toil_expiry_date=!1,P.uiOptions.expiryDate=null}function p(){return v(P.uiOptions.multipleDays?{hasErrors:!P.request.to_date&&!P.request.from_date,label:"To Date",value:P.request.to_date}:{hasErrors:!P.request.from_date,label:"From Date",value:P.request.from_date})}function v(e){if(e.hasErrors){var t="Please select "+e.label+" to find expiry date";return a.reject([t])}return e.value?a.resolve(e.value):a.reject([])}function b(){P.canManage&&(P.uiOptions.expiryDate=P._convertDateFormatFromServer(P.request.toil_expiry_date))}function g(){return o.canExpire(P.request.type_id).then(function(e){P.requestCanExpire=e})}function y(e){var t=P.period.id;return P._checkAndSetAbsencePeriod(e).then(function(){var e=t===P.period.id;if(!e)return P.uiOptions.multipleDays&&(P.uiOptions.showBalance=!1,P.uiOptions.toDate=null,P.request.to_date=null),a.all([P._loadAbsenceTypes(),P._loadCalendar()])})}function _(){return s.valuesOf("hrleaveandabsences_toil_amounts").then(function(t){P.toilAmounts=e.indexBy(t,"value")})}function $(e){return P.loadAbsencePeriodDatesTypes().then(function(){P._setMinMaxDate(),P._setDates(),P.updateBalance(),P.calculateToilExpiryDate()}).catch(function(e){P.errors=[e]})}function q(){P.uiOptions.expiryDate&&(P.request.toil_expiry_date=P._convertDateToServerFormat(P.uiOptions.expiryDate))}function w(){var e=P._initRequestAttributes();P.request=u.init(e),P.request.to_date_type=P.request.from_date_type="1"}n.debug("ToilRequestCtrl");var A=t("RequestCtrl"),P=Object.create(A);return P.requestCanExpire=!0,P.directiveOptions=i,P.$modalInstance=r,P.initParams={absenceType:{allow_accruals_request:!0}},P.calculateBalanceChange=c,P.calculateToilExpiryDate=l,P.canSubmit=f,P.changeInNoOfDays=m,P.clearExpiryDate=h,P.loadAbsencePeriodDatesTypes=y,P.updateAbsencePeriodDatesTypes=$,P.updateExpiryDate=q,P._initRequest=w,function(){P.loading.absenceTypes=!0,P._init().then(function(){return g()}).then(function(){return b(),_()}).finally(function(){P.loading.absenceTypes=!1})}(),P}t.controller("ToilRequestCtrl",n),n.$inject=["$controller","$log","$q","$uibModalInstance","api.optionGroup","AbsenceType","directiveOptions","TOILRequestInstance"]}),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-popup.service",["common/lodash","leave-absences/shared/modules/services","common/services/notification.service"],function(e,t){"use strict";function n(t,n,a,r,s,o,i,u,c,l){function d(e){return c.get().then(function(t){return e.roleOf(t.contactId)}).then(function(e){return"none"!==e})}function f(e,t){return t?t.request_type:e||null}function m(t,a,r,o){var u=e.capitalize(f(a,t))+"RequestCtrl";s.open({appendTo:n.children().eq(0),templateUrl:i.sharedPathTpl+"directives/leave-request-popup/leave-request-popup.html",controller:u,controllerAs:"$ctrl",windowClass:"chr_leave-request-modal",resolve:{directiveOptions:function(){return{leaveRequest:t,selectedContactId:r,isSelfRecord:o}},format:["DateFormat",function(e){return e.getDateFormat()}]}})}function h(e){return l.find(e).then(function(e){return d(e).then(function(t){t?m(e,e.request_type,e.contact_id,"my-leave"===a.section):o.error("Error","You dont have permission to see this leave request")})}).catch(function(e){o.error("Error",e)})}return t.debug("LeavePopup"),{openModal:m,openModalByID:h}}t.factory("LeavePopup",n),n.$inject=["$log","$rootElement","$rootScope","$q","$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",function(e,t){e.debug("Component: my-leave-container"),t.section="my-leave"}]})}),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,s,o){s.debugEnabled(o.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/modules/dialog","common/models/option-group","common/directives/loading","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-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/leave-request.controller","leave-absences/shared/controllers/sub-controllers/sick-request.controller","leave-absences/shared/controllers/sub-controllers/toil-request.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.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(){}); \ No newline at end of file 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 301426a9951..364ef7e9d92 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 @@ -163,8 +163,6 @@ define([ * @return {Promise} */ function indexLeaveRequests (leaveRequestsList) { - var deferred = $q.defer(); - leaveRequestsList.forEach(function (leaveRequest) { var days = leaveRequestDays(leaveRequest); @@ -175,9 +173,7 @@ define([ }); }); - deferred.resolve(); - - return deferred.promise; + return $q.resolve(); } /** @@ -248,9 +244,12 @@ define([ var toDate = moment(leaveRequest.to_date); while (pointerDate.isSameOrBefore(toDate)) { - days.push(_.find(vm.month.days, function (day) { - return day.date === pointerDate.format('YYYY-MM-DD'); - })); + // Ensure that pointerDate is in same month/year that component represents + if (pointerDate.month() === vm.month.index && pointerDate.year() === vm.month.year) { + days.push(_.find(vm.month.days, function (day) { + return day.date === pointerDate.format('YYYY-MM-DD'); + })); + } pointerDate.add(1, 'day'); } @@ -315,9 +314,18 @@ define([ * @return {Promise} */ function loadMonthLeaveRequests () { + var range = { + from: vm.month.days[0].date, + to: vm.month.days[vm.month.days.length - 1].date + }; + return LeaveRequest.all({ - from_date: { from: vm.month.days[0].date }, - to_date: { to: vm.month.days[vm.month.days.length - 1].date }, + from_date: range, + to_date: range, + // The following syntax is a valid CRM API syntax for OR operator - + // Ex. [['field1', 'field2'], ['field3', 'field4']] is the syntax for: + // (field1 OR field2) AND (field3 OR field4) + options: { or: [['from_date', 'to_date']] }, status_id: {'IN': [ leaveRequestStatusValueFromName(sharedSettings.statusNames.approved), leaveRequestStatusValueFromName(sharedSettings.statusNames.adminApproved), 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 479b1ed2755..84d610720b1 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 @@ -149,13 +149,16 @@ })); }); - it("uses the selected months' first and last day as date delimiters", function () { + it('loads all requests touching the specified month', function () { var month = controller.month; - - expect(LeaveRequest.all.calls.mostRecent().args[0]).toEqual(jasmine.objectContaining({ - from_date: { from: month.days[0].date }, - to_date: { to: month.days[month.days.length - 1].date } - })); + var range = { + from: month.days[0].date, + to: month.days[month.days.length - 1].date + }; + + expect(LeaveRequest.all.calls.mostRecent().args[0]).toEqual( + jasmine.objectContaining({ from_date: range, to_date: range } + )); }); });