Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.        static FromJSON(json){
  2.             let ctrl = new ScheduleControl2();
  3.             let j = JSON.parse(json);
  4.             for(let client of j.Data){
  5.                 let cC = ctrl.AddClientFromModel(client);
  6.                 ctrl._selectedClient = cC.dataset.id;
  7.                  for(let i = 0; i < 7; i++){
  8.                      for(let j = 0; j < 48; j++){
  9.                          let val = client.availability.data[i][j];
  10.                          if(val == 0){
  11.                             continue;
  12.                          }  
  13.                          ctrl._addClientToShift(ctrl._selectedClient,i,j);
  14.                      }
  15.                  }
  16.             }
  17.             return ctrl;
  18.        }
  19.        ToJSON(){
  20.          let data = {Data:[]};
  21.          let clients = [];
  22.          for(let client of this.ClientsElm.childNodes){
  23.              client = client.childNodes[0];
  24.              let c = {};
  25.              c.name = client.dataset.name;
  26.              c.address = client.dataset.address;
  27.              c.shifts = parseInt(client.dataset.shifts);
  28.              c.color = client.dataset.color;
  29.              c.availability = {data:[[],[],[],[],[],[],[]]};
  30.              for(let i = 0; i < 7; i++){
  31.                  for(let j = 0; j < 48; j++){
  32.                      c.availability.data[i][j] = 0;
  33.                  }
  34.              }
  35.              c._id = client.dataset.id;
  36.              let shifts = this.Grid.querySelectorAll(`[data-id='${c._id}']`);
  37.              for(let shift of shifts){
  38.                  c.availability.data[shift.dataset.day][shift.dataset.shift] = 1;
  39.              }
  40.              clients.push(c);
  41.          }
  42.          data.Data = clients;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement