You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
3.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. var nextRowId=1;
  2. function getNextRowId() {
  3. return nextRowId;
  4. }
  5. function renumberTableRows(){
  6. var row_no=1;
  7. var table = document.getElementById("tabbody");
  8. for (var i = 0, row; row = table.rows[i]; i++) {
  9. // row.cells[0].innerHTML=row_no++;
  10. }
  11. }
  12. function deleteTableRow(rowId){
  13. alert (rowId);
  14. var target = document.getElementById("upload-target"+rowId);
  15. var children = target.children;
  16. // delete all uploaded elements
  17. for (var i = 0; i < children.length; i++) {
  18. var tmp = children[i].getAttribute("data-id");
  19. $K.ajax.post({
  20. url: 'delete.php',
  21. data: 'id='+tmp,
  22. before: function(xhr) {},
  23. success: function(response) {},
  24. error: function(response) {}
  25. });
  26. }
  27. // delete the row from table
  28. var element = document.getElementById("trow"+rowId);
  29. element.parentNode.removeChild(element);
  30. renumberTableRows();
  31. // alert(rowId);
  32. }
  33. function addTableRow(){
  34. var $node = $K.dom('#tabbody');
  35. // create a new table row with id
  36. var element = document.createElement('tr');
  37. element.setAttribute("id", "trow"+nextRowId);
  38. var a_type = document.getElementById("a_type").value;
  39. var a_date = document.getElementById("a_date").value;
  40. var a_description = document.getElementById("a_description").value;
  41. var a_amount = document.getElementById("a_amount").value;
  42. var a_currency = document.getElementById("a_currency").value;
  43. /* a_type = "Hello";*/
  44. var e="";
  45. // add column for position no
  46. e += `<td>${a_type}</td>`;
  47. // add coluemn for a_type (Auslagenart)
  48. // e += `<td><textarea name="desc[${nextRowId}]" rows="2"></textarea> </td>`;
  49. e += `<td>${a_date}</td>`;
  50. // add column for date
  51. // e += `<td><input name="date[${nextRowId}]" type="date"/></td>`;
  52. e += `<td>${a_description}</td>`;
  53. // add column for num
  54. e += `<td>${a_amount}</td>`;
  55. // add column for file upload
  56. /* e+= `
  57. <td data-kube="">
  58. <div class="form-item">
  59. <div class="upload"
  60. data-kube="upload"
  61. data-type="file" data-multiple="true"
  62. data-target="#upload-target${nextRowId}"
  63. data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
  64. data-progress="true">
  65. </div>
  66. <div id="upload-target${nextRowId}" class="upload-target"></div>
  67. </div>
  68. </td>
  69. */
  70. e += `<td>${a_currency}</td>`;
  71. // `;
  72. // add delete bnutton
  73. e +=
  74. `<td><span
  75. onclick="deleteTableRow(${nextRowId})"
  76. class="close is-large">
  77. </span></td>`;
  78. $node.append(element);
  79. element.innerHTML=(e);
  80. renumberTableRows();
  81. nextRowId++;
  82. }
  83. function setUploadField()
  84. {
  85. var e = $K.dom('#uploadfield');
  86. var uf =`<div class="upload"
  87. data-kube="upload"
  88. data-type="file" data-multiple="true"
  89. data-target="#upload-target${nextRowId}"
  90. data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
  91. data-progress="true">Beleg hochladen
  92. </div>
  93. <div id="upload-target${nextRowId}" class="upload-target small"></div>
  94. </div>
  95. `;
  96. document.getElementById("uploadfield").innerHTML=uf;
  97. }
  98. $K.add('module', 'kaform', {
  99. init: function(app, context)
  100. {
  101. this.app = app;
  102. },
  103. // catch event
  104. onmessage: {
  105. tabs: {
  106. opened: function(sender)
  107. {
  108. console.log('Tab box is ',sender.getActiveBox());
  109. }
  110. }
  111. },
  112. });
  113. $K.init({
  114. observer: true
  115. });
  116. // startup is here
  117. // on startup clear session on server
  118. $K.ajax.get({
  119. url: 'clear.php',
  120. data: '', // or key=value object
  121. before: function(xhr) {},
  122. success: function(response) {},
  123. error: function(response) {}
  124. });
  125. setUploadField();
  126. // add on table row
  127. //addTableRow();