Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getData() {
  2.  
  3.     serverRequest("https://api.luukwuijster.io", function (response) {
  4.         json = JSON.parse(response);
  5.  
  6.         var object = {
  7.             "id": '',
  8.             "naam": '',
  9.             "brouwer": '',
  10.             "type": '',
  11.             "gisting": '',
  12.             "perc": '',
  13.             "inkoop_prijs": ''
  14.         };
  15.  
  16.         for (var key in json) {
  17.             makeRow(json[key].id -1);
  18.  
  19.             makeField(json[key].id);
  20.             makeNameField(json[key].naam);
  21.             makeToolField('info');
  22.             if(auth == true){
  23.                 makeToolField('edit');
  24.                 makeToolField('delete');
  25.             }
  26.  
  27.             object.id = json[key].id;
  28.             object.naam = json[key].naam;
  29.             object.brouwer = json[key].brouwer;
  30.             object.type = json[key].type;
  31.             object.gisting = json[key].gisting;
  32.             object.perc = (Math.round(json[key].perc * 100 * 100) / 100);
  33.             object.inkoop_prijs = json[key].inkoop_prijs;
  34.  
  35.             $(tr).data(object);
  36.  
  37.             table.appendChild(tr);
  38.         }
  39.  
  40.         $("#loading-overlay").remove();
  41.  
  42.         function makeField(text) {
  43.             var td = document.createElement('td');
  44.             td.setAttribute('class', 'field');
  45.             var text2 = document.createTextNode(text);
  46.             td.appendChild(text2);
  47.             tr.appendChild(td);
  48.         }
  49.         //Ja, Dit kan beter, maar dit werk ook.
  50.         function makeNameField(text) {
  51.             var td = document.createElement('td');
  52.             td.setAttribute('class', 'field naam');
  53.             var text2 = document.createTextNode(text);
  54.             td.appendChild(text2);
  55.             tr.appendChild(td);
  56.         }
  57.  
  58.         function makeRow(id) {
  59.             tr = document.createElement('tr');
  60.             tr.setAttribute('id', "r" + id);
  61.             tr.setAttribute('class', "row");
  62.         }
  63.  
  64.         function makeToolField(tool) {
  65.  
  66.             var dialog;
  67.             var fillfunction;
  68.             var fontawesome;
  69.  
  70.             switch (tool) {
  71.                 case "info":
  72.                     dialog = "infoDialog";
  73.                     fillfunction = "infoDialogFill(this)";
  74.                     fontawesome = "fa fa-info fa-lg";
  75.                     break;
  76.                 case "edit":
  77.                     dialog = "editDialog";
  78.                     fillfunction = "editDialogFill(this)";
  79.                     fontawesome = "fa fa-pencil fa-lg";
  80.                     break;
  81.                 case "delete":
  82.                     dialog = "deleteDialog";
  83.                     fillfunction = "deleteDialogFill(this)";
  84.                     fontawesome = "fa fa-trash fa-lg";
  85.                     break;
  86.             }
  87.  
  88.             var td = document.createElement('td');
  89.             td.setAttribute('class', 'field');
  90.             var div = document.createElement('div');
  91.             div.setAttribute('class', 'cursor center dialog-open');
  92.             div.setAttribute('data-target', dialog);
  93.             div.setAttribute('onclick', fillfunction);
  94.             var i = document.createElement('i');
  95.             i.setAttribute('class', fontawesome);
  96.  
  97.             div.appendChild(i);
  98.             td.appendChild(div);
  99.             tr.appendChild(td);
  100.         }
  101.     });
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement