Advertisement
Guest User

callbacks

a guest
Feb 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let userID = 0;
  2. let flexBalance = 0;
  3. let childSickDaysLeft = 0;
  4. let userInitials;
  5.  
  6. $(document).ready(function () {
  7.  
  8.     // henter userId
  9.     $.when(getUserIdAPI())
  10.         .then(function (userId) {
  11.             userID = userId
  12.  
  13.             // henter info om user via userId
  14.             $.when(getUserAPI(userID))
  15.                 .then(function (user) {
  16.                     insertUserData(user);
  17.  
  18.                     // henter feridata på user via userId
  19.                     $.when(getVacationDataAPI(userID))
  20.                         .then(function (vacation) {
  21.                             $(".vacation-left").text(vacation.RemainingHours + " dage");
  22.  
  23.                             // henter flexdata via initialer
  24.                             $.when(getUserFlexDataByInitsAPI(userInitials))
  25.                                 .then(function (flexData) {
  26.                                     insertFlexData(flexData);
  27.  
  28.                                     // henter barn sygedage via userId
  29.                                     $.when(getChildSickDaysAPI(userID))
  30.                                         .then(function (sickDayData) {
  31.                                             insertChildSickData(sickDayData);
  32.                                         });
  33.                                 });
  34.                         });
  35.                 });
  36.         });
  37. });
  38.  
  39.  
  40. function insertUserData(user) {
  41.     $(".panel-title").text(user[0].Name);
  42.     $(".name").text(user[0].Name);
  43.     $(".email").append('<a href="' + user[0].Email + '">' + user[0].Email + '</a>');
  44.     let momentStartDate = moment(user[0].StartDate).format('ll');
  45.     userInitials = user[0].Initials;
  46.     $(".start-date").text(momentStartDate);
  47. }
  48.  
  49. function insertFlexData(flexData) {
  50.     flexBalance = flexData[flexData.length - 1].Accumulated;
  51.     $(".flex").text(flexBalance + " timer");
  52. }
  53.  
  54. function insertChildSickData(sickDayData) {
  55.     childSickDaysLeft = sickDayData.HoursRemaining / 7, 40;
  56.     var childSickDaysLeftRounded = Math.round(childSickDaysLeft * 10) / 10;
  57.     $(".sickdays").text(childSickDaysLeftRounded + " dage");
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement