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.

245 lines
5.2 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
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 currentRowId=1;
  2. function renumberTableRows(){
  3. var row_no=1;
  4. var table = document.getElementById("tabbody");
  5. for (var i = 0, row; row = table.rows[i]; i++) {
  6. // row.cells[0].innerHTML=row_no++;
  7. }
  8. }
  9. function isFloat(val) {
  10. var floatRegex = /^-?\d+(?:[.,]\d*?)?$/;
  11. if (!floatRegex.test(val))
  12. return false;
  13. val = parseFloat(val);
  14. if (isNaN(val))
  15. return false;
  16. return true;
  17. }
  18. function deleteTableRow(rowId){
  19. var target = document.getElementById("upload-target"+rowId);
  20. // this.message = app.message;
  21. var children = target.children;
  22. // delete all uploaded elements
  23. /* for (var i = 0; i < children.length; i++) {
  24. var tmp = children[i].getAttribute("data-id");
  25. alert ("DEL");
  26. alert (tmp);
  27. $K.ajax.post({
  28. url: 'delete.php',
  29. data: 'id='+tmp,
  30. before: function(xhr) {},
  31. success: function(response) {},
  32. error: function(response) {}
  33. });
  34. }
  35. */
  36. // delete the row from table
  37. var element = document.getElementById("trow"+rowId);
  38. element.parentNode.removeChild(element);
  39. renumberTableRows();
  40. // alert(rowId);
  41. }
  42. function showAlert(text) {
  43. $K.app.message.show( { message: `${text}`, position: 'centered', type: 'is-error' });
  44. return;
  45. }
  46. function reset2()
  47. {
  48. document.getElementById("a_type").value="";
  49. document.getElementById("a_description").value="";
  50. document.getElementById("a_amount").value="";
  51. setUploadField();
  52. }
  53. function addTableRow(){
  54. var $node = $K.dom('#tabbody');
  55. // create a new table row with id
  56. var element = document.createElement('tr');
  57. element.setAttribute("id", "trow"+currentRowId);
  58. var a_type = document.getElementById("a_type").value;
  59. if (!a_type.trim().length ) {
  60. document.getElementById("a_type").focus();
  61. showAlert("Bitte gib eine Auslagenart an!");
  62. return;
  63. }
  64. var a_date = document.getElementById("a_date").value;
  65. if (!a_date.trim().length){
  66. document.getElementById("a_date").focus();
  67. showAlert("Bitte gib ein g&uuml;ltiges Datum an!");
  68. return;
  69. }
  70. var a_description = document.getElementById("a_description").value;
  71. if (!a_description.trim().length){
  72. document.getElementById("a_description").focus();
  73. showAlert("Bitte gib eine Beschreibung ein!");
  74. return;
  75. }
  76. var a_amount = document.getElementById("a_amount").value;
  77. if (!isFloat(a_amount)){
  78. document.getElementById("a_amount").focus();
  79. showAlert("Bitte gib einen g&uuml;ltigen Betrag ein!");
  80. return;
  81. }
  82. var a_currency = document.getElementById("a_currency").value;
  83. if (!a_currency.trim().length){
  84. document.getElementById("a_currency").focus();
  85. showAlert("Bitte gib eine W&auml;hrung an!");
  86. return;
  87. }
  88. var target = document.getElementById("upload-target"+currentRowId);
  89. var children = target.children;
  90. if (!children.length){
  91. showAlert("Bitte lade mindestens einen Beleg hoch!");
  92. return;
  93. }
  94. /* a_type = "Hello";*/
  95. var e="";
  96. // add column for position no
  97. e += `<td>${a_type}</td>`;
  98. // add coluemn for a_type (Auslagenart)
  99. // e += `<td><textarea name="desc[${nextRowId}]" rows="2"></textarea> </td>`;
  100. e += `<td>${a_date}</td>`;
  101. // add column for date
  102. // e += `<td><input name="date[${nextRowId}]" type="date"/></td>`;
  103. e += `<td>${a_description}</td>`;
  104. // add column for num
  105. e += `<td>${a_amount}</td>`;
  106. // add column for file upload
  107. /* e+= `
  108. <td data-kube="">
  109. <div class="form-item">
  110. <div class="upload"
  111. data-kube="upload"
  112. data-type="file" data-multiple="true"
  113. data-target="#upload-target${nextRowId}"
  114. data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
  115. data-progress="true">
  116. </div>
  117. <div id="upload-target${nextRowId}" class="upload-target"></div>
  118. </div>
  119. </td>
  120. */
  121. e += `<td>${a_currency}</td>`;
  122. // `;
  123. // add delete bnutton
  124. e +=
  125. `<td><span
  126. onclick="deleteTableRow(${currentRowId})"
  127. class="close is-large">
  128. </span></td>`;
  129. $node.append(element);
  130. element.innerHTML=(e);
  131. // renumberTableRows();
  132. currentRowId++;
  133. reset2();
  134. }
  135. function setUploadField()
  136. {
  137. var e = $K.dom('#uploadfield');
  138. var uf =`<div class="upload"
  139. data-kube="upload"
  140. data-type="file" data-multiple="true"
  141. data-target="#upload-target${currentRowId}"
  142. data-url="upload.php?row=${currentRowId}" data-url-remove="delete.php"
  143. data-progress="true">Beleg hochladen
  144. </div>
  145. <div id="upload-target${currentRowId}" class="upload-target small"></div>
  146. </div>
  147. `;
  148. document.getElementById("uploadfield").innerHTML=uf;
  149. }
  150. $K.add('module', 'kaform', {
  151. init: function(app, context)
  152. {
  153. this.app = app;
  154. this.message = app.message;
  155. },
  156. // catch event
  157. onmessage: {
  158. tabs: {
  159. opened: function(sender)
  160. {
  161. console.log('Tab box is ',sender.getActiveBox());
  162. this.message.show({ message: 'My message' });
  163. }
  164. }
  165. },
  166. });
  167. $K.init({
  168. observer: true
  169. });
  170. // startup is here
  171. // on startup clear session on server
  172. $K.ajax.get({
  173. url: 'clear.php',
  174. data: '', // or key=value object
  175. before: function(xhr) {},
  176. success: function(response) {},
  177. error: function(response) {}
  178. });
  179. setUploadField();
  180. // add on table row
  181. //addTableRow();