function formatDuration(a,b){for(var c=[1e3,60,60,24],d={short:[["d","d"],["h","h"],["m","m"],["s","s"],["ms","ms"]],plain:[[" days"," day"],[" hours"," hour"],[" minutes"," minute"],[" seconds"," second"],[" milliseconds"," millisecond"]]},e=[],f=0;f1?0:1]),a-=i*g}return e.join(" ")}Raven.config("https://955d3ea58ca247e9a709d307fee3bf47@app.getsentry.com/35873"),window.onerror=Raven.process,angular.module("tkApp",["ngCookies","ngResource","ngSanitize","ngAnimate","ui.router","ui.bootstrap","geolocation","ui.tree","xeditable","infinite-scroll","restangular","akoenig.deckgrid","angularFileUpload","angularMoment","selectionModel","ui.select","oc.lazyLoad","ui.bootstrap"]).config(["$urlRouterProvider","$stateProvider","$httpProvider","$provide","RestangularProvider",function(a,b,c,d,e){e.setBaseUrl("api"),e.setMethodOverriders(["PATCH"]),e.addResponseInterceptor(function(a,b,c,d,e,f){var g;if("getList"===b){g=a.items?a.items:_.isArray(a)?a:[a],g.meta={};for(var h in a)"items"!==h&&(g.meta[h]=a[h])}else g=a;return g}),e.setRestangularFields({id:"uuid"}),e.setFullRequestInterceptor(function(a,b,c,d,e,f){return"remove"==b&&(a=null),{headers:e,params:f,element:a,httpConfig:{}}}),d.factory("apiEndpointInterceptor",["$q","ApiLocatorService",function(a,b){return{request:function(c){return a.when(c).then(function(a){var c=a.url;return 0===c.indexOf("api")&&(a.url=b.getDataEndpoint()+c.substr(3,c.length),a.withCredentials=!0),a})}}}]),d.factory("authenticationListener",["$location",function(a){return{error:function(b){401==status&&a.path("/login")}}}]),c.interceptors.push("apiEndpointInterceptor"),Date.prototype.toString=function(){return this.getTime()/1e3}}]).run(["editableOptions","$rootScope","FileUploader",function(a,b,c){if(a.theme="bs3",b.moment=moment,!b.fileUploader){var d=new c({removeAfterUpload:!0,withCredentials:!0});b.fileUploader=d}}]).constant("googleApiKey","AIzaSyDu2f676hoer0BlfE7n6DKrrEEp5F-h9KY"),function(){function a(c){var d=0;return c=c.replace(/(\d),(\d)/g,"$1$2"),c.replace(b,function(b,c,e){e=a[e]||a[e.toLowerCase().replace(/s$/,"")]||1,d+=parseFloat(c,10)*e}),d}var b=/(-?\d*\.?\d+(?:e[-+]?\d+)?)\s*([a-zμ]*)/gi;a.nanosecond=a.ns=1e-6,a.μs=a.microsecond=.001,a.millisecond=a.ms=1,a.second=a.sec=a.s=1e3*a.ms,a.minute=a.min=a.m=60*a.s,a.hour=a.hr=a.h=60*a.m,a.day=a.d=24*a.h,a.week=a.wk=a.w=7*a.d,a.month=30.4375*a.d,a.year=a.yr=a.y=365.25*a.d,window.parseDuration=a}(),angular.module("tkApp").config(["$urlRouterProvider","$stateProvider",function(a,b){a.when("/projects/:uuid","/projects/{uuid}/overview").otherwise("/home"),b.state("authenticated",{abstract:!0,resolve:{passport:["AuthService",function(a){return a.authorize()}]}}).state("login",{url:"/login",templateUrl:"views/login.html",controller:"LoginCtrl"}).state("resetPassword",{url:"/resetPassword",templateUrl:"views/resetPassword.html",controller:"ResetPasswordCtrl"}).state("confirmPasswordReset",{url:"/confirmPasswordReset/:uuid/:hash",templateUrl:"views/confirmPasswordReset.html",controller:"ConfirmPasswordResetCtrl"}).state("home",{parent:"authenticated",url:"/home",templateUrl:"views/home.html",controller:"HomeCtrl"}).state("teams",{parent:"authenticated",url:"/teams",templateUrl:"views/teams.html",controller:"TeamsCtrl"}).state("reports",{parent:"authenticated",url:"/reports",template:"",abstract:!0}).state("reports.list",{url:"",templateUrl:"views/reports.html"}).state("reports.hours",{url:"/hours",resolve:{KendoModule:["$ocLazyLoad",function(a){return a.load({name:"kendo.directives",files:["lib/kendoui/js/kendo.all.min.js","lib/kendoui/js/jszip.min.js","lib/kendoui/styles/kendo.common.min.css","lib/kendoui/styles/kendo.bootstrap.min.css","bower_components/select2/select2.min.js","bower_components/select2/select2.css","bower_components/select2-bootstrap-css/select2-bootstrap.css"]})}]},templateUrl:"views/reports/hours.html",controller:"ReportsHoursCtrl"}).state("projects",{parent:"authenticated",url:"/projects",template:"",abstract:!0}).state("projects.list",{url:"",templateUrl:"views/project.html",controller:"ProjectsCtrl",reloadOnSearch:!1}).state("projects.project",{url:"/:uuid",templateUrl:"views/projects/project.html",controller:"ProjectCtrl"}).state("projects.project.overview",{url:"/",templateUrl:"views/projects/overview.html"}).state("projects.project.timecards",{url:"/timecards",templateUrl:"views/projects/timecards.html",controller:"ProjectTimecardsCtrl"}).state("projects.project.timecards.card",{url:"/:userId",templateUrl:"views/projects/timecards/cardList.html",controller:"ProjectTimecardsCardListCtrl"}).state("projects.project.tasks",{url:"/tasks",templateUrl:"views/projects/tasks.html",controller:"ProjectTaskListCtrl"}).state("projects.project.gallery",{url:"/gallery",templateUrl:"views/projects/gallery.html",controller:"ProjectGalleryCtrl"}).state("people",{parent:"authenticated",url:"/people",template:'',abstract:!0}).state("people.list",{url:"/list",templateUrl:"views/people.html",controller:"PeopleCtrl"}).state("people.person",{url:"/:userId",templateUrl:"views/people/person.html",controller:"ProfileCtrl",abstract:!0}).state("people.person.profile",{url:"",templateUrl:"views/people/profile.html",controller:"ProfileCtrl"}).state("people.person.timeline",{url:"/timeline",templateUrl:"views/people/timeline.html",controller:"people.TimelineCtrl"}).state("people.password",{url:"/:userId/update-password",templateUrl:"views/updatePassword.html",controller:"updatePasswordCtrl"}).state("payroll",{parent:"authenticated",url:"/payroll",template:'',abstract:!0,resolve:{KendoModule:["$ocLazyLoad",function(a){return a.load({name:"kendo.directives",files:["lib/kendoui/js/kendo.web.min.js","lib/kendoui/styles/kendo.common.min.css","lib/kendoui/styles/kendo.bootstrap.min.css"]})}]}}).state("payroll.main",{url:"",templateUrl:"views/payroll/main.html",controller:"PayrollMainController"}).state("payroll.configuration",{url:"/configuration?isDefault&id",templateUrl:"views/payroll/configuration.html",controller:"PayrollFormController"}).state("payroll.list",{url:"/list",templateUrl:"views/payroll/grid.html",controller:"PayrollGridController"}).state("payroll.profiles",{url:"/profiles",abstract:!0,template:''}).state("payroll.profiles.new",{url:"/new",templateUrl:"views/payroll/profile/create.html",controller:"PayrollFormController"}).state("payroll.profiles.edit",{url:"/:id",templateUrl:"views/payroll/profile/edit.html",controller:"PayrollFormController"}).state("payroll.enrollment",{url:"/enrollment",template:'',abstract:!0}).state("payroll.enrollment.employees",{url:"/employees",templateUrl:"views/payroll/enrollment/employees.html",controller:"PayrollProfileEmployeeEnrollment"}).state("map",{parent:"authenticated",url:"/map?latitude&longitude&precision",templateUrl:"views/map.html",controller:"MapCtrl"})}]),angular.module("tkApp").controller("ResetPasswordCtrl",["$scope","$http",function(a,b){var c={400:{title:"Sorry!",type:"danger",message:"We don't recognize the username and/or email you provided. Please double check them, and try again."},other:{title:"Oh No!",type:"warning",message:"Our servers are acting funny. A team of highly caffeinated programmers has been dispatched and will furiously mash buttons until things work again. Please try again later!"}};a.reset=function(){return a.error=!1,a.success=!1,!!a.request.$valid&&b.put("api/password",{username:a.username,email:a.email}).success(function(){a.success=!0}).error(function(b,d){a.error=c[d]?c[d]:c.other})}}]),angular.module("tkApp").controller("ConfirmPasswordResetCtrl",["$scope","$http","$stateParams",function(a,b,c){var d={400:{title:"Sorry!",type:"danger",message:"The link you've used to reset your password is invalid or expired. Please request another link."},other:{title:"Oh No!",type:"warning",message:"Our servers are acting funny. A team of highly caffeinated programmers has been dispatched and will furiously mash buttons until things work again. Please try again later!"}};a.verified=!1,a.mismatch=!1,a.uuid=c.uuid,a.hash=c.hash,a.init=function(){b.get("api/password/"+a.uuid+"/"+a.hash).then(function(){a.verified=!0},function(b){a.error=d[b.status]?d[b.status]:d.other})},a.reset=function(){return a.error=!1,!!a.request.$valid&&b.post("api/password/"+a.uuid+"/"+a.hash,{password:a.password}).success(function(){a.success=!0}).error(function(b,c){a.error=d[c]?d[c]:d.other})},a.change=function(){a.password!==a.repeatPassword?a.mismatch=!0:a.mismatch=!1},a.init()}]),angular.module("tkApp").controller("TaskSelectorModalCtrl",["$scope","$modalInstance","$http","$timeout",function(a,b,c,d){a.view="projects",a.search={},a.projects={after:0,busy:!1,items:[],next:function(){if(!this.busy){this.busy=!0;var b=a.projects;c.get("api/project?limit=20&offset="+b.after).then(function(a){b.items=b.items.concat(_.pluck(a.data.items,"project")),b.after+=20,b.busy=!1})}}};var e=function(b){c.get("api/task?views=children,project&limit=20&query="+b).then(function(b){a.searchResults=_.chain(b.data.items).map(function(a){return{id:a.uuid,uuid:a.uuid,text:a.name,project:a.project}}).groupBy(function(a){return a.project.name}).map(function(a,b){return{text:b,children:a}}).value()})},f=function(b,c){a.slideDirection="slide-"+b,d(function(){a.view=c},0)};a.$watch("search.text",function(a){a?(f("left","search"),e(a)):f("right","projects")}),a.reset=function(){a.search.text="",f("right","projects")},a.showProject=function(b){c.get("api/task/"+b+"?views=children").then(function(b){var c=function(a){var b=[a];return a.children&&(b=b.concat(_.flatten(_.map(a.children,function(a){return c(a)})))),b};f("left","tasks"),a.tasks=c(b.data)})},a.selectTask=function(a){b.close(a.uuid)},a.close=function(){b.close(!1)}}]),angular.module("tkApp").directive("loginForm",["$rootScope","$location","$location",function(a,b,b){return{scope:{fn:"&loginForm"},link:function(a,c,d){c.find("#submit-button").click(function(d){d.preventDefault();var e=$(this);e.addClass("loading");var f=a.fn();f.then&&f.then(function(d){e.removeClass("loading");var f=c.find("input");f.prop("disabled",!0),c.submit(),f.prop("disabled",!1),b.path("/home"),a.$emit("login",d.data)},function(){e.removeClass("loading")})})}}}]),angular.module("tkApp").directive("commentField",["$parse","$q",function(a,b){return{scope:{fn:"&commentField",text:"=asyncText"},link:function(a,c,d){var e;c.on("keydown",function(d){if(!e&&13===d.which&&!d.shiftKey){d.preventDefault();var f=a.fn({text:d.target.value});f&&(e=!0,c.attr("disabled","true"),c.find("[async-class]").addClass(function(a){return $(this).attr("async-class")}),b.when(f).then(function(){return d.target.value="",f}).finally(function(a){return e=!1,c.removeAttr("disabled"),c.find("[async-class]").removeClass(function(a){return $(this).attr("async-class")}),a}))}})}}}]),angular.module("tkApp").directive("visibleWhenAuthenticated",["$parse","$q","AuthService","$rootScope",function(a,b,c,d){return{restrict:"A",link:function(a,b){d.$watch("passport",function(a){$(b).hide(),a&&c.getPassport().then(function(a){a.isAuthenticated()&&$(b).show()})})}}}]).directive("visibleWithPermission",["$parse","$q","AuthService","$rootScope",function(a,b,c,d){return{restrict:"A",scope:{permission:"@visibleWithPermission"},link:function(a,b,e){d.$watch("passport",function(d){var e=a.permission;e&&($(b).hide(),c.getPassport().then(function(a){a&&a.hasPermission.apply(a,e.split(":")).then(function(a){a&&$(b).show()})}))})}}}]).directive("visibleWithRole",["AuthService","$rootScope",function(a,b){return{restrict:"A",scope:{role:"@visibleWithRole"},link:function(c,d,e){b.$watch("passport",function(b){var e=c.role;e&&($(d).hide(),a.getPassport().then(function(a){a&&a.hasRole(e).then(function(a){a&&$(d).show()})}))})}}}]).directive("styleWithPermission",["$parse","$q","AuthService","$rootScope",function(a,b,c,d){var e=/^([A-Z]+(?:\:[A-Z]+)*)\(\s*(?:['"](.*)['"])\s*,\s*(?:['"](.*)['"])\s*\)$/;return{restrict:"A",scope:{stylePermission:"@styleWithPermission"},link:function(a,b,f){d.$watch("passport",function(d){var f=e.exec(a.stylePermission);f&&($(b).addClass(f[3]),c.getPassport().then(function(a){a.hasPermission.apply(a,f[1].split(":"))&&($(b).addClass(f[2]),$(b).removeClass(f[3]))}))})}}}]),angular.module("tkApp").directive("asyncClick",["$parse","$q",function(a,b){return{scope:{fn:"&asyncClick",text:"=asyncText"},link:function(a,c,d){var e=!1;c.on("click",function(){if(!e){var d=a.fn();d&&(e=!0,c.attr("disabled","true"),c.find("[async-class]").addClass(function(a){return $(this).attr("async-class")}),b.when(d).then(function(a){if(a&&"string"==typeof a){$(c).popover(a.content?a:{content:a,placement:"left",trigger:"focus"}).popover("toggle");var b=function(){$(c).popover("destroy"),$("body").unbind("click",b)};$("body").on("click",b),setTimeout(b,5e3)}}).finally(function(){e=!1,c.removeAttr("disabled"),c.find("[async-class]").removeClass(function(a){return $(this).attr("async-class")})}))}})}}}]),angular.module("tkApp").directive("urlNav",["$rootScope","$location",function(a,b){var c=function(a){var c=b.path(),d=c.indexOf("/",1);d>-1&&(c=c.substr(0,d)),a.find("LI.active").removeClass("active"),a.find("A").filter(function(){return this.href.indexOf("#"+c)>-1}).parents("LI").addClass("active")};return{link:function(b,d,e){c(d),a.$on("$locationChangeStart",function(){c(d)})}}}]),angular.module("tkApp").directive("captureImage",["$parse","$q","$compile","$timeout",function(a,b,c,d){return{link:function(a,b,e){b.addClass("img-uploader-button");var f=e.captureImage,g=c('')(a);g.insertAfter(b),b.click(function(){g.click()});var h=$('');h.hide(),angular.isFunction(a[f])&&g.change(function(c){$(c.target).val()&&""!==$(c.target).val()&&(b.prepend(h),h.show(),h.removeClass("success failure fa-times fa-check-square"),h.addClass("fa-spinner fa-spin"),a[f].call(g,c).then(function(){h.removeClass("fa-spinner fa-spin"),h.addClass("fa-check-square success"),d(function(){h.fadeOut("slow",function(){h.detach()})},3e3)},function(){h.removeClass("fa-spinner fa-spin"),h.addClass("fa-times failure"),d(function(){h.fadeOut("slow",function(){h.detach()})},3e3)}))})}}}]),angular.module("tkApp").directive("filterList",["$rootScope","$location",function(a,b){var c=function(a,b){a.find("a").removeClass("active").filter(function(){return $(this).attr("param-value")==b}).addClass("active")};return{link:function(d,e,f){var g=f.searchParam;e.find("a").filter(function(){return $(this).attr("param-value")}).each(function(){this.href="javascript:;"}).click(function(){b.search(g,$(this).attr("param-value")),a.$apply()}),c(e,b.search()[g]),a.$on("$locationChangeSuccess",function(){c(e,b.search()[g])})}}}]),angular.module("tkApp").directive("durationText",["$parse","$interval",function(a,b){return{restrict:"AE",require:"?ngModel",link:function(c,d,e){var f,g=function(){f&&d.html(h((new Date).getTime()-f.getTime()))},h=function(a){var b=a/1e3,c=b/60,d=c/60;return b<5?"A few moments":b<60?Math.floor(b)+"s":c<60?Math.floor(c)+"m "+Math.floor(a%6e4/1e3)+"s":Math.floor(d)+"h "+Math.floor(a%36e5/6e4)+"m"};c.$watch(a(e.durationText),function(a){f=a,g()});var i=b(function(){g()},1e3);c.$on("$destroy",function(){b.cancel(i)})}}}]),angular.module("tkApp").directive("punchClock",function(){return{templateUrl:"views/punchClock.html",scope:!0,controller:["$scope","$http","$modal","PunchService","AuthService","$q","$timeout",function(a,b,c,d,e,f,g){a.$on("taskUpdate",function(a){i()});var h=function(){return d.punchOut().then(function(){delete a.latestSegment,a.$emit("punchUpdate")})},i=function(){return d.getCurrent({views:["segment","task"]}).then(function(b){a.working=!0,_.extend(a,b)})};e.getPassport().then(i),_.extend(a,{selectTask:function(){return c.open({templateUrl:"/views/taskSelectorModal.html",controller:"TaskSelectorModalCtrl"}).result.then(function(b){if(b)return a.setTask(b)})},setTask:function(b){return d.updateCurrent({task:b}).then(function(){return i()}).then(function(){a.$emit("punchUpdate")})},togglePunch:function(){return a.latestSegment?h():a.selectTask()},togglePause:function(){var b="BREAK"!=a.latestSegment.segmentType?"BREAK":"WORKING";return d.updateCurrent({type:b}).then(function(){return a.$emit("punchUpdate"),i()})},onFileChange:function(b){return f(function(b,c){return d.uploadFile(a.latestSegment.uuid).then(function(){a.$emit("punchUpdate"),b()},c)})}})}]}}),angular.module("tkApp").directive("projectSelector",function(){return{restrict:"A",templateUrl:"views/projects/projectList.html",require:"^ngModel",scope:!0,link:function(a,b,c,d){d.$render=function(){a.selected=d.$modelValue},a.$watch("selected",function(b){d.$setViewValue(a.selected=b,"select")})},controller:["$scope","$http",function(a,b){var c=0,d=!1;a.projects=[],a.listMore=function(){this.busy||(this.busy=!0,b.get("api/project?limit=20&offset="+c).then(function(b){a.projects=a.projects.concat(_.pluck(b.data.items,"project")),c+=20,d=!1}))},a.select=function(b){a.selected=b.uuid},a.isSelected=function(b){return a.selected==b.uuid}}]}}),angular.module("tkApp").directive("imageloaded",function(){return{restrict:"A",link:function(a,b,c){var d=c.loadedclass;b.bind("load",function(a){angular.element(b).addClass(d)})}}}),angular.module("tkApp").directive("flipClock",["$parse",function(a){return{restrict:"AE",require:"?ngModel",link:function(b,c,d,e){var f=c.FlipClock(0,{clockFace:"HousrCounter"});f.stop(),d.running&&b.$watch(a(d.running),function(a){f[a?"start":"stop"]()}),d.from&&b.$watch(a(d.from),function(a){a&&f.setTime(((new Date).getTime()-a)/1e3)}),d.value&&b.$watch(a(d.value),function(a){void 0!==a&&f.setTime(a/1e3)})}}}]),angular.module("tkApp").directive("datePicker",["$parse","$q",function(a,b){return{scope:{fn:"&datePicker"},link:function(a,b,c){$(b).datepicker({autoclose:!0}).on("changeDate",function(b){a.$apply(function(){a.fn(b)})})}}}]),angular.module("tkApp").directive("imageScroller",["$parse","$q","$compile","$timeout","$interval",function(a,b,c,d,e){return{restrict:"AE",scope:{imageScroller:"=imageScroller"},link:function(a,b){function c(){l&&(n.addClass("is-loading"),l.getNextAvailableResource(1,b.outerWidth(),-1).then(function(a){h(4e3),k=l.$current,b.find("i.pre-loader").hide(),f(k),l.hasNext&&g()},function(){n.hide(),b.find("i.pre-loader").hide();var a=$("");a.load(function(){f(a)})}))}function e(a){var c=k;!function(a,c){a&&(a.css("bottom",b.outerHeight()),d(function(){a.css("bottom",Math.min(0,-a.outerHeight()+m)),a.removeClass("hightlight"),d(function(){a.detach()},3e3)},2e3)),k=c,f(c)}(c,a)}function f(a){a.addClass("hightlight"),b.append(a),a.css("bottom",Math.min(0,-a.outerHeight()+m)),b.find("i.pre-loader").addClass("disabled"),d(function(){a.css("bottom",0)},15),h(4500)}function g(){i=d(function(){n.addClass("is-loading"),l.next().then(function(a){e(a),g()})},15e3)}function h(a){var a=a||3e3;d.cancel(j),j=d(function(){n.removeClass("is-loading")},a)}var i,j,k,l=a.imageScroller,m=b.height(),n=b.find(".image-pager");c(),b.find("i.js-slide-next").click(function(){n.addClass("is-loading"),l.hasNext&&(d.cancel(i),l.next().then(function(a){e(a),g()}))}),b.find("i.js-slide-previous").click(function(){n.addClass("is-loading"),l.hasPrevious&&(d.cancel(i),l.previous().then(function(a){e(a),g()}))}),a.$on("$destroy",function(){d.cancel(i),d.cancel(j),b.find("img").detach()})}}}]),angular.module("tkApp").directive("fancylink",["$parse","$q","$compile","$rootScope","$controller",function(a,b,c,d,e){return{restrict:"A",link:function(a,b,d){var e='',f=c(e)(a);b.append(f),d.fancylinkHref&&d.fancylinkHref.length>0&&$(f).fancybox({openEffect:"none",closeEffect:"none",afterLoad:function(){var b='
',e=c(b)(a);this.inner.prepend(e)}})}}}]),angular.module("tkApp").directive("galleryItem",["$compile","$timeout","MediaLocator",function(a,b,c){function d(b,d,e,f,g,h){var i=c.getMediaLink(f.storageUuid,$(document).width())+".jpg";e.getResource(f.$index+1,g,-1).then(function(c){h.find(".preloader").fadeOut();var e=$("");e.append(c),e=a(e)(b),e=$(e),e.fancybox({openEffect:"none",closeEffect:"none",afterLoad:function(){var c='
',e=a(c)(b);this.inner.prepend(e)}}),e.hide(),h.append(e),e.fadeIn()})}var e;return{restrict:"A",link:function(a,c,f){e=e||a;var g;if(a.mother&&(g=a.mother[f.resourceScroller]),f.galleryItem&&g){var h=angular.fromJson(f.galleryItem);g.has(h.$index+1)?(c.find(".preloader").hide(),d(a,f,g,h,null,c)):b(function(){var b=Math.max(300,c.width());d(a,f,g,h,b,c)},300)}}}}]),angular.module("tkApp").directive("thumbnail",["$compile","$timeout","MediaLocator",function(a,b,c){return{restrict:"A",link:function(b,d,e){var f=300,g=angular.fromJson(e.thumbnailData);0===d.find(".preloader").length&&d.append($('
'));var h=$('');h=$(a(h)(b)),h.fancybox({openEffect:"none",closeEffect:"none"}),h.find("img").load(function(){d.find(".preloader").fadeOut(),h.hide(),d.append(h),h.fadeIn()})}}}]),angular.module("tkApp").directive("navBar",["$rootScope","$location",function(a,b){return{link:function(a,b,c){var d=$(b),e=d.find(".toggle");e.click(function(){e.toggleClass("active"),d.find("ul.menu-items").toggleClass("visible")}),$("#custom-nav li").click(function(){$(this).hasClass("has-dropdown")||(e.hasClass("active")&&e.click(),$(this).closest(".has-dropdown").blur())})}}}]),angular.module("tkApp").directive("mapLink",["googleApiKey",function(a){return{restrict:"AE",scope:{location:"=mapLink"},link:function(a,b,c,d){if(a.location){var e=a.location,f="map.html?longitude="+e.longitude+"&latitude="+e.latitude;if(e.accuracy){var g=parseInt(e.accuracy);g&&(f+="&accuracy="+g)}b.attr("href",f),b.attr("target","_blank")}}}}]),angular.module("tkApp").directive("asyncSwitch",["$parse","$q",function(a,b){return{link:function(a,b,c){var d=b,e=a[c.asyncSwitch],f="fa fa-spinner fa-spin",g="fa fa-check success",h="fa fa-times failure",i=1500,j=d.find("i");angular.isFunction(e)&&d.on("click",function(){d.hasClass("busy")||(j.show(),d.addClass("busy"),j.addClass(f),e().then(function(){d.toggleClass("toggle"),d.removeClass("busy"),j.removeClass(f),j.addClass(g),setTimeout(function(){j.fadeOut(function(){j.removeClass(g)})},i)},function(){j.removeClass(f),d.removeClass("busy"),j.addClass(h),j.fadeOut(),setTimeout(function(){j.fadeOut(function(){j.removeClass(h)})},i)}))})}}}]),angular.module("tkApp").directive("mainPreloader",["$parse","$q","$compile","$timeout","$interval",function(a,b,c,d,e){return{restrict:"AE",link:function(a,b,c){$("#loading-overlay").fadeOut("slow")}}}]),angular.module("tkApp").directive("selectTwo",function(){return{restrict:"A",require:"^ngModel",scope:{opts:"=selectTwo"},link:function(a,b,c,d){$(b).select2(a.opts).on("change",function(a){d.$setViewValue(a.val,"select")})}}}),angular.module("tkApp").directive("dateRange",["$parse",function(a){return{restrict:"A",require:"^ngModel",link:function(a,b,c,d){$(b).daterangepicker({ranges:{Today:[moment(),moment()],"This Week":[moment().startOf("week"),moment()],"This Month":[moment().startOf("month"),moment()],"This Year":[moment().startOf("year"),moment()]},startDate:moment().startOf("month"),endDate:moment()},function(a,b){d.$setViewValue({from:a,to:b},"select")}),d.$render=function(){var a=d.$viewValue,c=$(b).data("daterangepicker");a&&(c.setStartDate(a.from),c.setEndDate(a.to))}}}}]),angular.module("tkApp").directive("projectInput",["ProjectService",function(a){return{restrict:"A",require:"^ngModel",scope:!0,link:function(b,c,d,e){$(c).select2({placeholder:"All",allowClear:!0,multiple:!0,initSelection:function(b,c){var d=$(b).val();a.get(d).then(function(a){c(_.map(a,function(a){return{id:a.uuid,text:a.name}}))})},query:function(b){a.list({page:b.page-1,limit:20,query:b.term}).then(function(a){b.callback({results:_.map(a,function(a){return{id:a.project.uuid,text:a.project.name}}),more:a.more})})}}).on("change",function(a){e.$setViewValue(a.val,"select")}),e.$render=function(){$(c).val(e.$viewValue)}}}}]),angular.module("tkApp").directive("userInput",["UserService",function(a){return{restrict:"A",require:"^ngModel",scope:!0,link:function(b,c,d,e){$(c).select2({placeholder:"All",allowClear:!0,multiple:!0,query:function(b){a.list({offset:b.page-1,limit:20,query:b.term}).then(function(a){b.callback({results:_.map(a,function(a){return{id:a.uuid,text:a.firstName+" "+a.lastName}}),more:a.more})})}}).on("change",function(a){e.$setViewValue(a.val,"select")})}}}]),angular.module("tkApp").directive("timeline",function(){return{templateUrl:"views/timeline/timeline.html",controller:"TimelineCtrl",scope:{timelineProject:"=",timelineUser:"="}}}),angular.module("tkApp").controller("TimelineCtrl",["$scope","$rootScope","TimelineService","TimezoneService","AuthService","CommentService","MediaLocator","$modal",function(a,b,c,d,e,f,g,h){function i(){m=a.timelineProject,n=a.timelineUser,a.editable=!1,a.reload()}function j(a,b){_.each(p[a],function(a){a.punchSelected=b})}function k(a){_.chain(a).map(_.property("entries")).flatten().reduce(function(a,b){var c=a[b.punch.uuid]=a[b.punch.uuid]||[];return c.push(b),a},p)}var l,m,n,o=["data",function(a){_.extend(this,{day:a.day,totals:a.totals,entries:_.map(a.entries,function(a){var b=moment.duration(a.duration,"milliseconds");return _.extend(a,{duration:a.duration>0?b:null,can:{editFlag:e.hasPermission("TIMELINE_ENTRY",a,"FLAG"),edit:e.hasPermission("TIMELINE",a,"MODIFY")},src:"ATTACH_IMAGE"===a.type?g.getMediaLink(a.attachmentUuid,1e3)+".jpg":null})})})}],p={},q=!0;a.filters={date:{start:null,end:null},flagged:!1},_.extend(a,{clearFilters:function(){a.filters.date={start:null,end:null}},reload:function(){l=null,q=!0,p={},a.days=[],a.loadMore()},isFromAnotherProject:function(a){return m&&a.segment&&a.segment.project.uuid!=m},createPunch:function(){h.open({templateUrl:"/views/timeline/dialog/createPunch.html",controller:"timeline.dialog.CreatePunchCtrl",resolve:{config:function(){return{userId:n,projectId:m}}}}).result.then(function(b){b&&(a.filters.date.start=a.filters.date.end=new Date(b.in))})},loadMore:function(){!a.loading&&q&&(a.loading=!0,e.getPassport().then(function(b){return c.listGroupedByDay(b.user.timeZone,{start:l,user:n,project:m,views:["task","project"],startDate:a.filters.date.start?a.filters.date.start.getTime():void 0,endDate:a.filters.date.end?a.filters.date.end.getTime():void 0,flagged:a.filters.flagged},o).then(function(b){a.days=(a.days||[]).concat(b.groups),k(b.groups),l=b.lastPunch,q=b.hasMore})}).finally(function(){a.loading=!1}))},updatePunch:function(b){return e.getPassport().then(function(d){return c.listGroupedByDay(d.user.timeZone,{punch:b,views:["task","project"]},o).then(function(c){var d=c.groups[0];_.each(a.days,function(a){a.entries=_.filter(a.entries,function(a){return a.punch.uuid!=b})}),_.each(a.days,function(a){a.day.getTime()==d.day.getTime()&&(a.entries=a.entries.concat(d.entries),a.entries=_.sortBy(a.entries,"time").reverse())})},function(){a.reload()})})},removePunch:function(b){a.reload()},update:function(){e.getPassport().then(function(b){return c.listGroupedByDay(b.user.timeZone,{user:n,project:m,views:["task","project"]},o).then(function(b){var c=0;_.each(b.groups,function(b){a.days[c].day.toString()==b.day.toString()?a.days[c]=b:a.days.unshift(b),c++}),k(b.groups)})})}}),b.$on("punchUpdate",_.bind(a.update,a)),a.$watch("timelineUser",i),a.$on("entryUpdated",function(b,c){a.updatePunch(c.punch.uuid)}),a.$on("entryDeleted",function(b,c){c.punch.uuid!=c.uuid?a.updatePunch(c.punch.uuid):a.removePunch(c.uuid)}),a.$watch("filters",a.reload,!0);var r;a.$on("select",function(a,b){r&&(r.selected=!1,j(r.punch.uuid,!1)),r=b,j(b.punch.uuid,!0)})}]),angular.module("tkApp").controller("timeline.EntryCtrl",["$scope","$attrs","$parse","TimelineService","CommentService","AuthService","MediaLocator",function(a,b,c,d,e,f,g){function h(){!a.comments&&a.commentable&&d.getComments(a.uuid,i).then(function(b){a.comments=b,a.commentCount=a.comments.length})}var i=["TimezoneService","data",function(a,b){_.extend(this,{time:a.toUserTimezone(b.createdOn),user:_.extend({avitarSrc:b.createdBy.profilePicture?g.getMediaLink(b.createdBy.profilePicture,35)+".jpg":null},b.createdBy),text:b.text,uuid:b.uuid,can:{edit:f.hasPermission("COMMENT",b,"EDIT")}})}];_.extend(a,c(b.model)(a)),_.extend(a,{flaggable:["PUNCH_IN","PUNCH_OUT","SWITCH_TASK","BREAK","RESUME_WORK"].indexOf(a.type)>-1,commentable:["PUNCH_IN","PUNCH_OUT","SWITCH_TASK","BREAK","RESUME_WORK"].indexOf(a.type)>-1}),_.extend(a,{getView:function(){if(!a.editing)return"details";switch(a.type){case"PUNCH_OUT":return"editors/entry.out";case"SWITCH_TASK":case"BREAK":case"RESUME_WORK":case"PUNCH_IN":return"editors/entry.segment"}},setSegmentType:function(b){a.segment.segmentType=b,a.type={WORKING:"SWITCH_TASK",BREAK:"BREAK"}[b]},flagForReview:function(){d.setFlagged(a.uuid,!a.flag).then(function(b){b?a.flag={createdBy:b.createdBy}:delete a.flag})},changeType:function(b){a.type=b},isCommentSelected:function(b){return a.selectedComment==b},setCommentSelected:function(b){a.selectedComment=b},editComment:function(a){a.editing=!0},updateComment:function(a,b){return e.update(a.uuid,{text:b}).then(function(b){_.extend(a,b),a.editing=!1})},deleteComment:function(b){return e.remove(b.uuid).then(function(){a.comments=_.without(a.comments,b),a.commentCount--})},addComment:function(b){return d.addComment(a.uuid,b,i).then(function(b){a.comments.push(b),a.commentCount=a.comments.length})},iconClass:function(){return{PUNCH_IN:"fa-arrow-circle-o-right",PUNCH_OUT:"fa-arrow-circle-o-left",SWITCH_TASK:"fa-unsorted",BREAK:"fa-coffee",RESUME_WORK:"fa-clock-o",ATTACH_IMAGE:"fa-camera"}[a.type]},edit:function(){a.editing=!0},cancelEdit:function(b){a.editing=!1},showOnMap:function(){var b=document.createElement("div"),c=document.createElement("div");c.className="map-element",b.className="map-overlay",b.appendChild(c),document.body.appendChild(b);var d=new google.maps.LatLng(a.location.latitude,a.location.longitude),e=new google.maps.Map(c,{center:d,zoom:16,mapTypeControl:!1,zoomControlOptions:{style:google.maps.ZoomControlStyle.SMALL}});new google.maps.Marker({map:e,animation:google.maps.Animation.DROP,position:d}),new google.maps.Circle({map:e,center:d,radius:a.location.accuracy,fillColor:"#AAAAAA",fillOpacity:"0.2",strokeColor:"#AAAAAA",strokeOpacity:"0.3"});var f=document.createElement("div");f.innerHTML="Close Map",_.extend(f.style,{backgroundColor:"#FFF",fontSize:"20px",fontWeight:"bold",lineHeight:"38px",paddingLeft:"12px",paddingRight:"12px",borderRadius:"2px",cursor:"pointer",boxShadow:"rgba(0, 0, 0, 0.3) 0 1px 4px -1px"}),e.controls[google.maps.ControlPosition.TOP_CENTER].push(f),google.maps.event.addDomListener(f,"click",function(){google.maps.event.clearInstanceListeners(f),b.remove()})}}),a.$on("entryUpdated",function(){a.editing=!1}),a.$on("entryDeleted",function(){a.editing=!1}),a.$watch("selected",function(b){b&&h(),a.$emit(b?"select":"deselect",a); })}]).controller("timeline.entry.SegmentEditorCtrl",["$scope","$modal","TimelineService","TaskService",function(a,b,c,d){_.assign(a,{task:a.segment?a.segment.task:null,localTime:a.localTime}),_.extend(a,{commit:function(b){if(b.inDate.$setValidity("future",moment().isAfter(moment(a.localTime.getTime()))),b.inDate.$setValidity("overlap",!0),b.$valid){var d="PUNCH_OUT"===a.type?{timestamp:a.localTime.getTime()}:{task:a.task.uuid,timestamp:a.localTime.getTime(),type:a.segment.segmentType};return c.updateEntry(a.uuid,d).then(function(){a.$emit("entryUpdated",a)},function(){b.inDate.$setValidity("overlap",!1)})}},deleteEntry:function(){return c.deleteEntry(a.uuid).then(function(){a.$emit("entryDeleted",a)})},splitEntry:function(){return c.splitEntry(a.uuid).then(function(){a.$emit("entryUpdated",a)})},selectTask:function(){return b.open({templateUrl:"/views/taskSelectorModal.html",controller:"TaskSelectorModalCtrl"}).result.then(function(b){if(b)return d.getTask(b).then(function(b){a.task=b})})}})}]),angular.module("tkApp").controller("timeline.dialog.CreatePunchCtrl",["$scope","$modalInstance","PunchService","TaskService","UserService","config",function(a,b,c,d,e,f){var g=a.punch={};_.extend(a,f),_.extend(a,{adjustInTime:function(){g.outTime&&(!g.inTime||g.inTime.getTime()>g.outTime.getTime())&&(g.inTime=g.outTime)},adjustOutTime:function(){g.inTime&&(!g.outTime||g.outTime.getTime()-1},b.hasSelections=function(){return j.length>0},b.toggleSelection=function(a){if(b.editing)return void(a!=h&&(h=null));var c=j.indexOf(a.uuid);c>-1?j.splice(c,1):j.push(a.uuid)},b.removeMember=function(a){e.removeMember(b.team.uuid,a.uuid).then(function(){var c=_.find(b.team.tasks,function(b){return _.find(b.workers,function(b){return a==b})});c.workers=_.without(c.workers,a)})},b.getMembers=function(){return _.chain(b.team.tasks).each().pluck("workers").flatten().value()},b.finish=function(){c.open({templateUrl:"views/teams/confirmFinish.html"}).result.then(function(a){a&&e.remove(b.team.uuid).then(function(){b.$emit("teamRemoved",b.team)})})},b.refresh=function(){e.get(b.team.uuid,["members","user","project.tasks"],a).then(function(a){_.merge(b.team,a)})};var k=function(a){_.clone(j),b.team;e[a](b.team.uuid,j).then(function(){b.refresh()})};_.extend(b,{punchInSelected:function(){k("punchIn")},punchOutSelected:function(){k("punchOut")},pauseSelected:function(){k("goOnBreak")},canEdit:!1,canClockIn:!1,canClockOut:!1}),b.hasMembers=function(){return _.find(b.team.tasks,function(a){return a.workers&&a.workers.length})},g()}])}(),angular.module("tkApp").factory("TeamService",["Restangular","$q","AuthService",function(a,b,c){return{list:function(b){return a.all("team").getList({views:[].concat(b.views).join(",")}).then(function(a){return _.map(a,function(a){return b.model?new b.model(a):a})})},get:function(b,c,d){return a.one("team",b).get({views:[].concat(c).join(",")}).then(function(a){return d?new d(a):a})},remove:function(b){return a.one("team",b).remove()},assignToTask:function(b,c,d){return a.one("team",b).one("members",c).patch({task:d})},removeMember:function(b,c){return a.one("team",b).one("members",c).remove()},punchIn:function(a,b){return this.changeMemberStates(a,b,"WORKING")},punchOut:function(a,b){return this.changeMemberStates(a,b,"OUT")},goOnBreak:function(a,b){return this.changeMemberStates(a,b,"BREAK")},changeMemberStates:function(b,c,d){return a.one("team",b).several("members",c).patch({status:d})}}}]),angular.module("tkApp").factory("UserService",["Restangular","FileUploadService","AuthService","MediaLocator","$q","ApiLocatorService",function(a,b,c,d,e,f){return{find:function(b,d,f,g,h){return e(function(e,i){c.getPassport().then(function(c){var j={offset:b,limit:d};f&&(j.filter=f),g&&(j.query=g),h&&(j.views=h),a.all("user").getList(j).then(function(a){e(a)},function(){i()})},function(){i()})})},list:function(a){return this.find(a.offset,a.limit,null,a.query,a.views)},get:function(b,c){var c=c||"basic";return a.one("user",b).get({views:c})},getProfileImage:function(a,b,c){if(a)return d.getMediaLink(a,b,c)+".jpg"},doUpload:function(a){return e(function(d,e){c.getPassport().then(function(c){if(c){var g=a?a:c.user.uuid,h=f.getDataEndpoint()+"/user/"+g+"/upload";b.doUpload(h).then(function(a){d(a)},function(a){e(a)})}else e()})})}}}]),angular.module("tkApp").factory("ReportsService",["AuthService","Restangular",function(a,b){return{hours:function(a){return b.one("report").all("hours").getList({from:moment(a.period.from).valueOf(),to:moment(a.period.to).valueOf(),users:a.users,projects:a.projects,overtimeType:a.overtime.type,overtimeHours:a.overtime.hours})}}}]),angular.module("tkApp").factory("PunchService",["Restangular","AuthService","geolocation","FileUploadService","$q","ApiLocatorService",function(a,b,c,d,e,f){return{getPunches:function(b,c,d,e){e=[].concat(e);var f=a.one("punch").get(_.extend({afterPunchId:b,limit:c,views:e?e.join(","):null},d));return f},getPunch:function(b,c){return a.one("punch",b).get()},createPunch:function(c){return b.getPassport().then(function(b){return a.all("punch").post(_.extend({user:b.user.uuid},c)).then(function(a){return a.uuid})})},update:function(b,c){return a.one("punch",b).patch(c)},deletePunch:function(b){return a.one("punch",b).remove()},updateCurrent:function(d){return b.getPassport().then(function(b){return c.getLocation().then(function(c){return a.one("punch","current").patch(_.extend({user:d.user||b.user.uuid,location:{accuracy:c.coords.accuracy,longitude:c.coords.longitude,latitude:c.coords.latitude}},d))}).catch(function(){return a.one("punch","current").patch(_.extend({user:d.user||b.user.uuid},d))})})},punchIn:function(d){var e=function(c){return b.getPassport().then(function(b){return a.one("punch","current").patch(_.extend({user:d.user||b.user.uuid,location:c},d))})};return c.getLocation().then(function(a){e(a)}).catch(function(){e(null)})},punchOut:function(){var d=function(b,c){return a.one("user",b.user.uuid).one("action").post("punchOut",{location:null!=c?{accuracy:c.coords.accuracy,longitude:c.coords.longitude,latitude:c.coords.latitude}:null})};return b.getPassport().then(function(a){return c.getLocation().then(function(b){return d(a,b)}).catch(function(){return d(a,null)})})},getCurrent:function(c){return c.views=[].concat(c.views||[]),b.getPassport().then(function(b){return a.one("user",b.user.uuid).one("punch").get().then(function(b){return c.views.indexOf("segment")===-1?b:a.one("punch",b.uuid).one("latestSegment").get({views:"task"}).then(function(a){return b.latestSegment=a,b})})})},uploadFile:function(a){return d.doUpload(f.getDataEndpoint()+"/segment/"+a+"/attachments")}}}]),angular.module("tkApp").factory("PayrollService",["$http","$q","ScrollerFactory",function(a,b,c){return{saveProfile:function(c,d){if(c.uuid)return b.when(a.post("api/payprofile/"+c.uuid,c));var e=d?"api/payprofile/company":"api/payprofile";return a.put(e,c)},scroll:function(a,b,d,e){return c.newScroller("payprofile",a,b,d,e)},getEmployeeEnrollments:function(){return b(function(b,c){a.get("api/payprofile/enrollments").then(function(a){b(a.data)},function(){c()})})},enrollEmployee:function(c,d){return b.when(a.post("api/payprofile/enroll/"+d+"/"+c))},getDefaultProfile:function(){return b(function(b,c){a.get("api/payprofile/company").then(function(a){b(a.data)},function(){c()})})}}}]),angular.module("tkApp").factory("TimecardService",["Restangular","$q",function(a,b){return{getOverview:function(b,c,d){return a.one("timecards/overview").get({projectId:b,offset:c,limit:d}).then(function(b){var c=b.items;return a.several("user",_.pluck(c,"user")).getList().then(function(a){var d=_.indexBy(a,"uuid");return _.each(c,function(a){return a.user=d[a.user]}),b})})},getTimeline:function(a,b){}}}]),angular.module("tkApp").factory("AuthService",["Restangular","$location","$timeout","$rootScope","$q","$parse",function(a,b,c,d,e,f){function g(a){if(this.authorized=!!a.uuid,this.user={},_.extend(this.user,a),this.roles={},this.user.roles)for(var b=this.user.roles.length;b--;)this.roles[this.user.roles[b]]=!0;a&&(this.permissions=_(a.permissions).map(function(a){var b=a.split(":");return _.map(b.shift().split(","),function(a){return a+":"+b.join(":")})}).flatten().map(function(a){var b=a.split(":");return _.map(b.pop().split(","),function(a){return b.join(":")+":"+a})}).flatten().groupBy(function(a){return a.split(":")[0]}).value())}return g.prototype={authz:{COMMENT:{EDIT:function(a,b){return b.createdBy.uuid===this.user.uuid}},TIMELINE_ENTRY:{FLAG:function(a,b){return!b.flag||b.flag.createdBy.uuid==this.user.uuid}}},hasRole:function(a){var b=this;return e(function(c,d){b.roles[a]===!0?c(!0):d(!1)})},hasPermission:function(a,b,c){return c||(c=b,b=null),!b&&this.permissions[a]&&this.permissions[a].indexOf(a+":"+c)>-1?e.when(!0):this.permissions[a]&&this.permissions[a].indexOf(a+":*:"+c)>-1?e.when(!0):this.authz[a]&&this.authz[a][c]?e.when(this.authz[a][c].call(this,b.uuid||b,b)):e.when(!1)},hasPermissions:function(a,b,c){var d=a.trim();if(!this.resources[d])return!1;for(var f=b.length,g=f>0;f--;){var h=b[f].trim(),i=this.resources[d][h]||this.resources[d]["*"];if(!i)return!1;g&=i[c]}return e(function(a,b){a(g)})},isAuthenticated:function(){return angular.isDefined(this.user.uuid)}},{authorize:function(){return a.one("session").get({views:"permissions"}).then(function(a){return d.passport=new g(a)},function(){return c(function(){b.path("/login")},0),d.passport=new g({})})},bindPermissions:function(a,b){this.getPassport().then(function(c){_.each(b,function(b,d){"string"==typeof b&&(b=b.split(":")),c.hasPermission.apply(c,b).then(function(b){f(d).assign(a,b)})})})},hasPermission:function(){var a=arguments;return this.getPassport().then(function(b){return b.hasPermission.apply(b,a)})},getPassport:function(){return e.when(d.passport)}}}]),angular.module("tkApp").factory("TaskService",["Restangular","AuthService","$q",function(a,b,c){return{getTask:function(b){return a.one("task",b).get()},getUserRecentTasks:function(){return c(function(c,d){b.getPassport().then(function(b){b?a.all("user/"+b.user.uuid+"/recent/tasks").getList().then(function(a){c(a)},function(){d()}):d()})})},find:function(b,c,d,e){return e=_.extend({views:[],project:void 0},e),a.all("task").getList({query:b,offset:c,limit:d,views:[].concat(e.views),project:e.project})}}}]),angular.module("tkApp").factory("ActivityService",["Restangular","$q","$http","$rootScope","AuthService","TimezoneService",function(a,b,c,d,e,f){function g(a,b,c){var d=_.chain(a).reverse().reduce(function(a,c){var d=f.format(c.date,b,i),e=_.first(a.groups);return(!e||d!==a.day&&"CLOCK_IN"==c.category)&&(e={day:d,activities:[]},a.groups.unshift(e),a.day=d),e.activities.unshift(_.extend({localTime:f.format(c.date,b,j)},c)),a},{day:null,groups:[]}).value().groups,e=_.first(d),g=_.last(c);if(e&&g&&e.day===g.day){var h=d.shift();g.activities=g.activities.concat(h.activities)}return c.concat(d)}function h(a,d,f,h){return b(function(b,i){e.getPassport().then(function(e){var j=h||{items:[],total:0,groups:[],more:!0},k=(j.items,j.groups),l=e.user.timeZone,m=j.total,n=j.more;c.get(a,{params:{views:"project",offset:d,limit:f}}).success(function(a){n=m-1}),l,k),b({total:j.total+a.items.length,groups:k,more:n})}).error(function(){i(h)})})})}var i="dddd, MMM Do",j="h:mm A";return{loadUserActivities:function(a,b,c,d){return h("api/activity/user/"+a.uuid,b,c,d)},loadProjectActivities:function(a,b,c,d){return h("api/activity/project/"+a,b,c,d)}}}]),angular.module("tkApp").factory("FileUploadService",["$rootScope","geolocation","$q","AuthService",function(a,b,c,d){return{doUpload:function(e,f){return c(function(c,g){d.getPassport().then(function(d){if(d){var h=a.fileUploader,i=h.queue[0];i.url=e,i.formData=angular.isArray(f)?f:[],i.onSuccess=function(a,b,d){c(a)},i.onError=function(a,b,c){g(a)},b.getLocation().then(function(a){i.formData.push({accuracy:a.coords.accuracy,latitude:a.coords.latitude,longitude:a.coords.longitude}),h.uploadItem(0)},function(){h.uploadItem(0)})}else g()})})}}}]),angular.module("tkApp").factory("ProjectService",["AuthService","Restangular","ScrollerFactory","$q","$http",function(a,b,c,d,e){return{getFilters:function(){return d(function(a,b){e.get("api/common/filters/project").then(function(b){a(b.data)},function(){b()})})},list:function(a){return b.all("project").getList({query:a.query,offset:a.offset,limit:a.limit})},get:function(a){var a=[].concat(a);return b.many("project",a).getList()},newAttachmentScroller:function(a,b,d,e){return c.newScroller("project/"+a+"/attachment",b,d,e)},createProject:function(a){return e.put("api/project",a)},newScroller:function(a,b,d){return c.newScroller("project",a,b,d)},newResourceScroller:function(a,b,d,e){return c.newImageScroller("project/"+a+"/attachment",b,d,e)},newResourceScroller$:function(a){return c.newImageScroller$(a)},toggleFavorite:function(b){return d(function(c,d){a.getPassport().then(function(a){e.post("api/project/"+b.uuid+"/favorite/"+a.user.uuid).then(function(){b.favorite=!b.favorite,c(b)},function(){d()})},function(){d()})})}}}]),angular.module("tkApp").factory("ScrollerFactory",["AuthService","Restangular","$q","MediaLocator","$http",function(a,b,c,d,e){function f(a,b,c,d,e){this.pageItems=[],this.cumulatedItems=[],this.more=!0,this.currentPage=0,this.perPage=b||15,this.total=0,this.filter=c,this.endPoint=a,this.isLoading=!1,this.query=d,this.meta={},this.params=e||{}}function g(a,b){this.attachmentScroller=a,this.locator=b,this.hasNext=!1,this.hasPrevious=!1,this.futures={},this.loaded={},this.failures={},this.total=0,this.currentIndex=0,this.$current=null}function h(d,e,f,g,h,i){var j={};return e&&(j.filter=e.toUpperCase()),f&&(j.query=f),i&&_.extend(j,i),j.offset=g,j.limit=h,c(function(c,e){a.getPassport().then(function(a){b.all(d).getList(j).then(function(a){c(a)},function(){e()})})})}var i=d;return _.extend(f.prototype,{loadMore:function(a){return!this.more||this.isLoading&&!a?this.more?this.isLoading?c(function(a,b){b(this)}):void 0:c(function(a,b){a(this)}):this.toPage(Math.ceil(this.cumulatedItems.length/this.perPage)+1,a)},toPage:function(a,b){var d=this;return c(function(c,e){d.currentPage=a;var f=(a-1)*d.perPage;if(f+1>d.cumulatedItems.length)!d.isLoading||b?(d.isLoading=!0,h(d.endPoint,d.filter,d.query,d.cumulatedItems.length,d.perPage,d.params).then(function(a){_.extend(d,{meta:a.meta,cumulatedItems:d.cumulatedItems.concat(a),pageItems:a,more:d.cumulatedItems.length+a.length');o.load(function(){e.loaded[a]=o,e.update(a,o),delete e.futures[a],i(o)}),o.error(function(){delete e.futures[a],e.failures[a]=c(function(a,b){b(o)}),e.update(a),j()});for(var p=k.pageItems.length;p--;)!function(b,d){b!==a&&b<=e.total&&(e.loaded[b]||e.futures[b]||(e.futures[b]=c(function(a,f){var g=k.pageItems[d].storageUuid,h=l?l:k.pageItems[d].width,i=m?m:k.pageItems[d].height,j=$('');j.load(function(){delete e.futures[b],e.loaded[b]=j,a(j)}),j.error(function(){delete e.futures[b],e.failures[b]=c(function(a,b){b(j)}),f()})})))}((h-1)*f+p+1,p)},function(){j()})});return e.futures[a]=i,i}return e.failures[a]?e.failures[a]:void 0},getNextAvailableResource:function(a,b,d,e){function f(a,b,c,d,h){g.getResource(a,b,c).then(function(b){g.update(a,b),d(b)},function(){if(Object.keys(g.failures).length===g.total||0===g.total)return void h();var i=e?a-1:(a+1)%g.total;0===i&&(i=g.total),f(i,b,c,d,h)})}var g=this;return c(function(c,e){f(a,b,d,c,e,{})})},next:function(a,b){return this.hasNext?this.getNextAvailableResource(++this.currentIndex,a,b):this.getNextAvailableResource(1,a,b)},previous:function(a,b){return this.hasPrevious?this.getNextAvailableResource(--this.currentIndex,a,b,!0):this.getNextAvailableResource(this.total,a,b,!0)},update:function(a,b){_.extend(this,{currentIndex:a,$current:b,hasNext:a1})},has:function(a){return this.loaded[a]}}),{newScroller:function(a,b,c,d,e){return new f(a,b,c,d,e)},newImageScroller:function(a,b,c,d){return new g(new f(a,b,c,d),i)},newImageScroller$:function(a){return new g(a,i)}}}]),angular.module("tkApp").factory("MediaLocator",["ApiLocatorService","stage",function(a,b){return{getMediaLink:function(b,c,d,e){return[a.getImageEndpoint(),"unsafe",c+"x"+(d>-1?d:0),e?e:"smart",b].join("/")}}}]),angular.module("tkApp").factory("DataUtils",function(){var a=[{key:1,value:"Monday"},{key:2,value:"Tuesday"},{key:3,value:"Wednesday"},{key:4,value:"Thursday"},{key:4,value:"Friday"},{key:4,value:"Saturday"}];return _.forEach(a,Object.freeze),_.forEach(a,Object.seal),Object.freeze(a),{toMap:function(a){for(var b=a.length,c={};b--;)c[a[b].key]=a[b].value;return c},ranks:function(a,b){for(var a=a||1,b=b||15,c=[],d=a;d20)?e="st":2===f&&(g<10||g>20)?e="nd":3===f&&(g<10||g>20)&&(e="rd"),function(a,b){c.push({key:a,value:b})}(d,d+e)}return c},days:function(){return a}}}),angular.module("tkApp").factory("ApiLocatorService",["stage",function(a){var b=window.location.hostname.replace(/www\./,"");return{getDataEndpoint:function(){return"localhost"===b?"http://localhost:8080":"http://api."+b},getImageEndpoint:function(){return"localhost"===b?"http://localhost:8080/attachments":"http://images."+b}}}]),angular.module("tkApp").factory("TimezoneService",["AuthService",function(a){return{format:function(a,b,c){return moment.utc(a).tz(b.split(/:/)[0]).format(c)},toTimezone:function(a,b){return moment.utc(a).tz(b.split(/:/)[0])},toUserTimezone:function(b){var c=this;return a.getPassport().then(function(a){return c.toTimezone(b,a.user.timeZone)})}}}]),angular.module("tkApp").factory("TimelineService",["AuthService","Restangular","TimezoneService","ModelService",function(a,b,c,d){return{list:function(a,c){return b.all("timeline").getList(a).then(d.resolvingFactory(c))},listGroupedByDay:function(a,b,e){var f=b?b.start:null,g=!1;return this.list(b).then(function(d){var e=_.chain(d).reverse().reduce(function(d,e){var f=c.toTimezone(e.time,a),g=moment(f).startOf("day"),h=_.first(d.groups);if(h&&(g.isSame(d.day)||"PUNCH_IN"!=e.type)||(h={day:g.toDate(),totals:{working:null,onBreak:null},entries:[]},d.groups.unshift(h),d.day=g),h.entries.unshift(_.extend({localTime:c.toTimezone(e.time,a).toDate(),nextDay:!g.isSame(d.day)},e)),e.duration>0&&(null==b.project||b.project==e.segment.project.uuid)){var i="WORKING"==e.segment.segmentType?"working":"onBreak";h.totals[i]=(h.totals[i]||moment.duration(0)).add(e.duration,"milliseconds")}return d},{day:null,groups:[]}).value().groups;return e.length&&(f=_.last(_.last(e).entries).punch.uuid),g=d.meta.more,e}).then(d.resolvingFactory(e)).then(function(a){return{groups:a,lastPunch:f,hasMore:g}})},addComment:function(a,c,e){return b.one("timeline").one("entries",a).all("comments").post(c).then(d.resolvingFactory(e))},getComments:function(a,c){return b.one("timeline").one("entries",a).all("comments").getList().then(d.resolvingFactory(c))},setFlagged:function(a,c){return b.one("timeline").one("entries",a).one("flag")[c?"put":"remove"]()},updateEntry:function(a,c){return b.one("timeline").one("entries",a).patch(c)},deleteEntry:function(a){return b.one("timeline").one("entries",a).remove()},splitEntry:function(a){return b.all("timeline").one("entries",a).all("actions").post({action:"SPLIT"})}}}]),angular.module("tkApp").factory("ModelService",["$injector","$q",function(a,b){function c(a){var b=[];_.forOwn(a,function(d,e){d&&(angular.isFunction(d.then)?b.push(d.then(function(b){a[e]=b})):b=angular.isArray(d)?b.concat(_.chain(d).map(c).flatten().value()):b.concat(c(d)))})}return{factory:function(b){return b?function(c){function d(c){return a.instantiate(b,{data:c})}return angular.isArray(c)?_.map(c,d):d(c)}:_.identity},resolvingFactory:function(a){var d=this.factory(a);return function(a){var e=d.call(window,a);return b.all(c(e)).then(function(){return e})}}}}]),angular.module("tkApp").factory("CommentService",["Restangular",function(a){return{remove:function(b){return a.one("comments",b).remove()},update:function(b,c){return a.one("comments",b).patch(c)}}}]),angular.module("tkApp").controller("ReportsHoursCtrl",["$scope","ReportsService","ApiLocatorService",function(a,b,c){a.filters={period:{from:moment().subtract(2,"weeks"),to:moment()},overtime:{hours:40,type:"WEEK"},projects:[],users:[]},a.download=function(b){switch(b){case"excel":a.reportGrid.saveAsExcel();break;case"pdf":a.reportGrid.saveAsPDF()}},a.reportGridConfig={excel:{fileName:"Timekeeper Hours.xlsx",filterable:!0},dataSource:{transport:{read:function(c){b.hours(a.filters).then(function(a){function b(a){return Math.round(a/36)/100}c.success(_.map(a,function(a){return{project:a.project.name,worked:b(a.worked),hours:b(a.normal),overtime:b(a.overtime),task:a.task.name,date:new Date(a.day),week:moment(new Date(a.day)).startOf("week").toDate(),firstName:a.user.firstName,lastName:a.user.lastName}}))})}},group:[{field:"week",aggregates:[{field:"hours",aggregate:"sum"},{field:"overtime",aggregate:"sum"},{field:"worked",aggregate:"sum"}]}],sort:[{field:"date",dir:"desc"}],aggregate:[{field:"hours",aggregate:"sum"},{field:"overtime",aggregate:"sum"},{field:"worked",aggregate:"sum"}]},height:500,sortable:!0,groupable:!0,columnMenu:!0,columns:[{field:"firstName",title:"First Name",width:"150px"},{field:"lastName",title:"Last Name",width:"150px"},{field:"hours",title:"Hours",width:"90px",aggregates:["sum"],footerTemplate:"#=sum.toFixed(2)#",groupFooterTemplate:"#=sum.toFixed(2)#",format:"{0: 0.00}"},{field:"overtime",title:"Overtime",width:"90px",aggregates:["sum"],footerTemplate:"#=sum.toFixed(2)#",groupFooterTemplate:"#=sum.toFixed(2)#",template:'#if(overtime > 0) {# #=overtime.toFixed(2)# # } else { # 0.00 # } #'},{field:"worked",title:"Total Hours",width:"90px",format:"{0: 0.00}",hidden:!1,aggregates:["sum"],footerTemplate:"#=sum.toFixed(2)#",groupFooterTemplate:"#=sum.toFixed(2)#"},{field:"project",title:"Project",width:"150px"},{field:"task",title:"Task",width:"200px"},{field:"date",title:"Day",width:"200px",format:"{0: MM/dd/yyyy}"},{field:"week",title:"Week",hidden:!0,format:"{0: MM/dd/yyyy}",groupHeaderTemplate:"#=moment(value).format('MM/DD/YYYY')#"}]},a.$watch("filters",function(b){a.reportGrid&&a.reportGrid.dataSource.read()},!0)}]),angular.module("tkApp").controller("ProjectCtrl",["$scope","$http","$stateParams","ActivityService","MediaLocator","ProjectService","AuthService",function(a,b,c,d,e,f,g){function h(){a.$on("availableImagesCountChange",function(b,c){a.availableImagesCount=c}),b.get("api/project/"+c.uuid).then(function(b){_.extend(a,b.data),a.project=b.data}),b.get("api/project/"+c.uuid+"/attachment",{params:{offset:0,limit:15}}).then(function(b){a.availableImagesCount=b.data.total})}var i={items:[],total:0,groups:[],more:!0},j=3;_.extend(a,{loadMoreActivity:function(){i.more&&d.loadProjectActivities(c.uuid,i.total,15,i).then(function(b){i=b,a.activityGroups=i.groups})},hasActivity:function(){return i.total>0},toggleArchived:function(){var d=!a.archived;b.post("api/project/"+c.uuid,{archived:d}).then(function(){a.archived=d})},getMediaLink:function(a,b,c,d){var b=b||200,c=c||200;return e.getMediaLink(a,b,c,d)},imageScroller:f.newResourceScroller(c.uuid,j),uuid:c.uuid,availableImagesCount:0}),h()}]),angular.module("tkApp").controller("ProjectTimecardsCardListCtrl",["$scope","$stateParams","UserService",function(a,b,c){a.userId=b.userId,a.projectId=b.uuid,c.get(a.userId).then(function(b){a.user=b})}]),angular.module("tkApp").controller("ProjectTaskListCtrl",["$scope","$modal","Restangular","AuthService",function(a,b,c,d){function e(){a.$watch("project",function(b){b&&(f(),d.getPassport().then(function(a){return a.hasPermission("PROJECT",b.uuid,"MODIFY")}).then(function(b){a.isEditable=b}))}),a.taskList={dropped:function(b){var d=b.dest.nodesScope.$parent.$modelValue,e=d?d.uuid:a.rootTask.uuid,f=b.source.nodeScope.$modelValue.uuid;c.one("task",f).post("",{parent:e,index:b.dest.index})}}}function f(){ return c.one("task",a.project.rootTask).get({views:"children"}).then(function(b){a.rootTask=b,a.subTasks=a.rootTask.children})}function g(a,c){b.open({controller:"CreateTaskModalCtrl",templateUrl:"views/projects/tasks/createTaskModal.html",resolve:{parent:function(){return a},task:function(){return c}}}).result.then(function(b){b&&(c.uuid=b,a.children.push(c))})}function h(a,b){b.children=b.children?b.children:[];for(var c=b.children.length,d=c;d--;)if(b.children[d]===a)return{parent:b,item:a,index:d};d=c;for(var e;d--;)if(e=h(a,b.children[d]))return e}_.extend(a,{newTask:function(){g(a.rootTask,{})},newSubTask:function(a){g(a,{})},removeTask:function(b,d){var e=h(b,a.rootTask);if(e){var f=e.parent.children.splice(e.index,1)[0];c.one("task",b.uuid).remove().then(function(){},function(){e.parent.children.splice(e.index,0,f)[0]})}},saveTask:function(a){return c.one("task",a.uuid).post("",{name:a.name})},isEditable:!1,taskList:{}}),e()}]),angular.module("tkApp").controller("ProjectGalleryCtrl",["$scope","Restangular","$stateParams","$q","$timeout","ApiLocatorService","FileUploadService","ProjectService",function(a,b,c,d,e,f,g,h){function i(b){var d=Math.max(Math.ceil(b/l),1);a.photos.length=0,a.attachmentScroller=h.newAttachmentScroller(c.uuid,l,null,a.query),m=a.attachmentScroller,a.resourceScroller=h.newResourceScroller$(m),a.attachmentScroller.toPage(d).then(function(){a.photos=a.photos.concat(m.cumulatedItems),k=m.more})}function j(){b.all("project/"+c.uuid+"/attachment").getList({offset:0,limit:0}).then(function(b){a.$emit("availableImagesCountChange",b.meta.total)})}var k=!0,l=10;a.photos=[],a.attachmentScroller=h.newAttachmentScroller(c.uuid,l,null,a.query),a.resourceScroller=h.newResourceScroller$(a.attachmentScroller);var m=a.attachmentScroller;_.extend(a,{loadMore:function(){k&&m.loadMore().then(function(){for(var b=0;b8?(a-8)/b:0,standard:a>8?8/b:a/b,relativeTotal:a/b,total:a>0?a:""}})}),a.cards=b.items})}]),angular.module("tkApp").controller("CreateProjectModalCtrl",["$scope","$modalInstance","$http",function(a,b,c){a.project={},a.ok=function(){b.close({name:a.project.name,description:a.project.description})},a.cancel=function(){b.dismiss("cancel")}}]),angular.module("tkApp").controller("CreateTaskModalCtrl",["$scope","$modalInstance","$http","task","parent",function(a,b,c,d,e){a.task=d,a.ok=function(){return c.put("api/task",{name:d.name,parent:e.uuid}).success(function(a){b.close(a)})},a.cancel=function(){b.close(!1)}}]),angular.module("tkApp").controller("CreateImageModalCtrl",["$scope","$modalInstance",function(a,b){a.image={},a.ok=function(){b.close()},a.cancel=function(){b.dismiss("cancel")}}]),angular.module("tkApp").controller("CreateTeamModalCtrl",["$scope","$modalInstance","$http",function(a,b,c){a.data={},a.ok=function(d){var e=a.data;d.$valid&&c.post("api/team",{project:e.project,name:e.name}).success(function(a){b.close(a)})},a.cancel=function(){b.close()}}]),angular.module("tkApp").controller("SelectUserModalCtrl",["$scope","$modalInstance","$http","exclude",function(a,b,c,d){var e=!1,f=0;a.search="",a.$watch("search",function(){a.listMore(!0)}),a.users=[],a.listMore=function(b){e||(e=!0,b&&(f=0),c.get("api/user?limit=20&offset="+f+"&query="+a.search).then(function(c){var g=c.data.items;g=_.filter(g,function(a){return d.indexOf(a.uuid)==-1}),a.users=b?g:a.users.concat(g),f+=20,e=!1}))};var g=[];a.toggleSelected=function(a){var b=g.indexOf(a);b>-1?g.splice(b,1):g.push(a)},a.isSelected=function(a){return g.indexOf(a)>-1},a.hasSelections=function(){return g.length>0},a.ok=function(){a.data,a.createTeamForm;c.put("api/team/"+a.team.uuid+"/members",_.pluck(g,"uuid")).success(function(a){b.close(g)})},a.cancel=function(){b.close()}}]),angular.module("tkApp").controller("PeopleCtrl",["$scope","$http","MediaLocator","UserService","DataUtils",function(a,b,c,d,e){function f(){g(),h(),a.itemsPerPage=i,a.$watch("page",function(){h()}),a.$watch("filter",function(){h()})}function g(){b.get("api/common/filters/user").success(function(b){a.filters=e.toMap(b)})}function h(){a.isLoading=!0,d.find(((a.page||1)-1)*a.itemsPerPage,a.itemsPerPage,a.filter,a.query,"punch").then(function(b){a.users=b,a.total=b.meta.total,a.isLoading=!1},function(){a.isLoading=!1})}var i=12;_.extend(a,{itemsPerPage:i,isLoading:!0,users:[],search:function(){h()},isFiltered:function(){return angular.isDefined(a.filter)},clearFilter:function(){delete a.filter},filterBy:function(b){a.filter=b,delete a.query},getMediaLink:function(a){return c.getMediaLink(a,90)+".jpg"},isAvailable:function(a){return angular.isDefined(a)&&null!==a}}),f()}]),angular.module("tkApp").controller("updatePasswordCtrl",["$scope","$http","$stateParams","$q",function(a,b,c,d){var e={message:"Password mismatch!",title:"Error",type:"danger"},f={title:"Password updated!",message:"",type:"info"},g={title:"Error!",message:"Server failure.",type:"danger"};_.extend(a,c),a.update=function(){return delete a.message,!!a.passwordUpdate.$valid&&(a.password!==a.passwordConfirmal?void(a.message=e):b.put("api/user/"+a.userId+"/password",a.password).then(function(){a.message=f},function(){a.message=g}))}}]),angular.module("tkApp").controller("FrameCtrl",["$scope","$http","$location","$rootScope","AuthService",function(a,b,c,d,e){a.logout=function(){b.delete("api/session").then(function(){d.passport=e.authorize(),c.path("/login")})}}]),angular.module("tkApp").controller("confirmalModalController",["$scope","$modalInstance","model",function(a,b,c){a.model=c,a.cancel=function(){b.close(!1)},a.confirm=function(){b.close(!0)}}]),angular.module("tkApp").controller("ProfileCtrl",["$scope","$stateParams","$q","Restangular","UserService","DataUtils","AuthService","$http",function(a,b,c,d,e,f,g,h){function i(){e.get(l,"full").then(function(b){a.model=b,a.phones=b.phoneNumbers.slice(0);var c=a.getProfileImage(128);c&&(a.profileImage=a.getProfileImage(128))}),g.getPassport().then(function(a){return a.hasPermission("USER",l,"MODIFY")}).then(function(b){a.isEditable=b}),j(),k()}function j(){return 0===a.states.length?d.all("common/states").getList().then(function(b){a.states=f.toMap(b)}):a.states}function k(){return 0===a.phoneTypes.length?d.all("common/phonetypes").getList().then(function(b){a.phoneTypes=f.toMap(b)}):a.phoneTypes}var l=b.userId;a.userId=l,a.phones=[],a.states=[],a.phoneTypes=[],a.model={},_.extend(a,{loadStates:j,loadPhoneTypes:k,onFormAfterSave:function(){return a.model.phoneNumbers=a.phones,c(function(b,c){a.model.post().then(function(){b()},function(){c()})})},onFormCancel:function(){a.phones=a.beforeEditPhones},removePhone:function(b){a.phones.splice(b,1)},addPhone:function(){a.phones.push({})},onFormShow:function(){a.beforeEditPhones=angular.copy(a.phones)},onPrimaryCheckBoxChange:function(b){for(var c=a.phones.length;c--;)c!==b&&(a.phones[c].primary=!1);a.model.primaryPhone=a.phones[b].number},displayValueOf:function(a,b){return b[a]||a},validatePhoneType:function(a,b){if(!b)return"Please specify a phone type."},isEditable:!1,onProfilePictureChange:function(){return c(function(b,c){return e.doUpload(l).then(function(c){a.model.profilePicture=c,a.profileImage=a.getProfileImage(128),b(c)},function(){c()})})},getProfileImage:function(b){return e.getProfileImage(a.model.profilePicture,b,b)},toggleActive:function(){return g.getPassport().then(function(a){return a.hasPermission("USER",l,"ACTIVATE")}).then(function(b){return c(function(c,d){b?h.put("api/user/"+l+"/active",!a.model.enabled+"").then(function(){a.model.enabled=!a.model.enabled,c()},function(){d()}):d(!0)})})},isAvailable:function(a){return angular.isDefined(a)}}),i()}]),angular.module("tkApp").controller("projects.timecards.PunchEntryCtrl",["$scope",function(a){a.segmentOrder={dropped:function(b){var c=a.punch.segments,d=a.punch.in.getTime();_.chain(c).clone().reverse().each(function(a){a.start=moment(d).milliseconds(0).toDate(),a.stop=moment(d+a.duration).milliseconds(0).toDate(),d+=a.duration})}},_.extend(a,{normalize:function(b,c){var d=a.punch.segments;"START"===c&&b.start>b.stop&&(b.stop=b.start),"STOP"===c&&b.stop-1;f--)d[f].start=d[f+1].stop,d[f].start>d[f].stop&&(d[f].stop=d[f].start);_(d).each(function(a){a.duration=a.stop.getTime()-a.start.getTime()}),a.punch.in=_.last(d).start,a.punch.out=_.first(d).stop}});var b=function(){var b=a.punch,c=_.chain(b.segments).clone().reverse().reduce(function(a,b){return a[b.segmentType]+=b.duration,a.total+=b.duration,a},{WORKING:0,BREAK:0,total:0}).value();b.workDuration=c.WORKING,b.breakDuration=c.BREAK};a.$watch("punch.segments",b,!0)}]),angular.module("tkApp").controller("PayrollMainController",["$scope","$stateParams","$http","$location","PayrollService",function(a,b,c,d,e){function f(){a.isLoading=!0,a.isPayrollConfigured=!1,a.msg=g,e.getDefaultProfile().then(function(b){a.isLoading=!1,a.isPayrollConfigured=!0,a.defaultId=b.uuid},function(){a.isLoading=!1})}var g={disabledFeature:"This feature is disabled. Please fix the configuration to enable it.",missingConfiguration:"The Payroll functionality is not configured yet. Click here to configure your organization' default payment profile.",validConfiguration:"The Payroll module is correctly configured. Click here in order to update your organization' default payment profile ."};_.extend(a,{toConfiguration:function(){var b={isDefault:!0};a.defaultId&&(b.id=a.defaultId),d.path("/payroll/configuration").search(b)},toProfiles:function(){a.isPayrollConfigured&&d.path("/payroll/list")},toEnrollments:function(){a.isPayrollConfigured&&d.path("/payroll/enrollment/employees")}}),f()}]),angular.module("tkApp").controller("PayrollGridController",["$scope","$stateParams","$http","PayrollService","DataUtils",function(a,b,c,d,e){function f(){g(1),a.$watch("pageIndexModel",function(a){a&&a>0&&g(a)}),a.profileTypes=i}function g(b){h=!0,a.scroller.toPage(b).then(function(b){a.items=b.pageItems,h=!1})}var h,i={};a.scroller=d.scroll(null,null,null,{views:"details"}),c.get("api/common/payprofiles").then(function(a){i=_.extend(i,e.toMap(a.data))}),f()}]),angular.module("tkApp").controller("PayrollFormController",["$q","$scope","$stateParams","$http","$location","PayrollService","DataUtils",function(a,b,c,d,e,f,g){function h(){var a={};return angular.copy(b.model,a),i(a,!0),c.id&&(l===a.period.type?a.period.uuid=m:delete a.period.uuid),a}function i(a,b){_.forIn(a,function(c,d){q[d]?a[d]=b?c?parseInt(c.getTime()):null:c?new Date(c):null:c instanceof Object&&i(c,b)})}function j(){d.get("api/common/overtimerules").then(function(a){b.overtimePeriods=a.data}),c.id?(n=!0,d.get("api/payprofile/"+c.id,{params:{views:"details"}}).then(function(a){i(a.data),m=a.data.period.uuid,b.model=angular.copy(a.data),l=b.model.period.type,n=!1},function(){n=!1,o=!0})):b.model={name:p?"Default Company Profile":"New Profile",period:{type:"REPEAT_EACH_N_WEEKS",repeatPeriod:2,startDate:new Date,activeFrom:new Date,overtimePeriod:"DAY",overtimeThreshold:8}},b.$watch("model.period.type",function(a){a&&(k&&_(r[k]).forEach(function(a){delete b.model.period[a]}),k=a)})}b.payrollFormHolder={};var k,l,m,n=!1,o=!1,p=angular.isDefined(c.isDefault),q={activeFrom:!0,activeTo:!0,startDate:!0,endDate:!0},r={WEEKLY:["day"],SEMI_MONTHLY:["first","last"],REPEAT_EACH_N_WEEKS:["repeatPeriod","startDate"],REPEAT_EACH_N_DAYS:["repeatPeriod","startDate"],MONTHLY_ON_DAY_OF_WEEK:["dayIndex","dayRank"],MONTHLY_ON_DAY_OF_MONTH:["dayIndex"],USER_DEFINED:["startDate","endDate"],QUARTERLY:[]},s={singleRequired:"This field is required.",multiRequired:"Those fields are required."};_.extend(b,{model:{},validationMessages:s,save:function(){return n=!0,a(function(a,c){b.payrollFormHolder.payprofileform.$valid?f.saveProfile(h(),p).then(function(){n=!1,p?e.path("/payroll").search({}):e.path("/payroll/list").search({})},function(){n=!1,o=!0,c()}):(c(),n=!1)})},cancel:function(){e.path("/payroll/list")},isLoading:n,isError:o,monthDays:g.ranks(1,29),weekDayRankInMonth:g.ranks(1,5),firstSemiMonthDays:g.ranks(1,16),lastSemiMonthDays:g.ranks(16,29),days:g.days(),isNew:function(){return c.id}}),j()}]),angular.module("tkApp").controller("PayrollProfileEmployeeEnrollment",["$scope","PayrollService",function(a,b){function c(){b.getEmployeeEnrollments().then(function(b){a.enrollmentData=_.sortBy(b,function(a){return a.default?0:1}),d=_.indexBy(a.enrollmentData,function(a){return a.profile.uuid})})}var d={};_.extend(a,{removeProfile:function(){},treeConfig:{accept:function(a,b,c){var d=b.$element.attr("data-type"),e=a.$element.attr("data-type");return e===d},dropped:function(a){var c=a.source.nodeScope.$modelValue,e=a.source.nodesScope.$parent.$modelValue.profile,f=a.dest.nodesScope.$parent.$modelValue.profile;e.uuid!==f.uuid&&b.enrollEmployee(c.uuid,f.uuid).then(function(){},function(){_.remove(d[f.uuid].employees,function(a){return a.uuid===c.uuid}),d[e.uuid].employees.push(c)})}},enrollmentData:{}}),c()}]),angular.module("tkApp").controller("people.TimelineCtrl",["$scope","$stateParams",function(a,b){}]);