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.

287 lines
6.1 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 countRows(){
  43. var ctr=0;
  44. for (i=0; i<currentRowId; i++){
  45. var element = document.getElementById("trow"+i);
  46. if (element)
  47. ctr++
  48. }
  49. return ctr;
  50. }
  51. function showAlert(text) {
  52. $K.app.message.show( { message: `${text}`, position: 'centered', type: 'is-error' });
  53. return;
  54. }
  55. function reset2()
  56. {
  57. document.getElementById("a_type").value="";
  58. document.getElementById("a_description").value="";
  59. document.getElementById("a_amount").value="";
  60. setUploadField();
  61. }
  62. function addTableRow(){
  63. var $node = $K.dom('#tabbody');
  64. // create a new table row with id
  65. var element = document.createElement('tr');
  66. element.setAttribute("id", "trow"+currentRowId);
  67. var a_type = document.getElementById("a_type").value;
  68. if (!a_type.trim().length ) {
  69. document.getElementById("a_type").focus();
  70. showAlert("Bitte gib eine Auslagenart an!");
  71. return;
  72. }
  73. var a_date = document.getElementById("a_date").value;
  74. if (!a_date.trim().length){
  75. document.getElementById("a_date").focus();
  76. showAlert("Bitte gib ein g&uuml;ltiges Datum an!");
  77. return;
  78. }
  79. var a_description = document.getElementById("a_description").value;
  80. if (!a_description.trim().length){
  81. document.getElementById("a_description").focus();
  82. showAlert("Bitte gib eine Beschreibung ein!");
  83. return;
  84. }
  85. var a_amount = document.getElementById("a_amount").value;
  86. if (!isFloat(a_amount)){
  87. document.getElementById("a_amount").focus();
  88. showAlert("Bitte gib einen g&uuml;ltigen Betrag ein!");
  89. return;
  90. }
  91. var a_currency = document.getElementById("a_currency").value;
  92. if (!a_currency.trim().length){
  93. document.getElementById("a_currency").focus();
  94. showAlert("Bitte gib eine W&auml;hrung an!");
  95. return;
  96. }
  97. var target = document.getElementById("upload-target"+currentRowId);
  98. var children = target.children;
  99. if (!children.length){
  100. showAlert("Bitte lade mindestens einen Beleg hoch!");
  101. return;
  102. }
  103. /* a_type = "Hello";*/
  104. var e="";
  105. // add column for position no
  106. e += `<td>${a_type}</td>`;
  107. // add coluemn for a_type (Auslagenart)
  108. // e += `<td><textarea name="desc[${nextRowId}]" rows="2"></textarea> </td>`;
  109. e += `<td>${a_date}</td>`;
  110. // add column for date
  111. // e += `<td><input name="date[${nextRowId}]" type="date"/></td>`;
  112. e += `<td>${a_description}</td>`;
  113. // add column for num
  114. e += `<td>${a_amount}</td>`;
  115. // add column for file upload
  116. /* e+= `
  117. <td data-kube="">
  118. <div class="form-item">
  119. <div class="upload"
  120. data-kube="upload"
  121. data-type="file" data-multiple="true"
  122. data-target="#upload-target${nextRowId}"
  123. data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
  124. data-progress="true">
  125. </div>
  126. <div id="upload-target${nextRowId}" class="upload-target"></div>
  127. </div>
  128. </td>
  129. */
  130. e += `<td>${a_currency}</td>`;
  131. // `;
  132. // add delete bnutton
  133. e +=
  134. `<td><span
  135. onclick="deleteTableRow(${currentRowId})"
  136. class="close is-large">
  137. </span></td>`;
  138. $node.append(element);
  139. element.innerHTML=(e);
  140. // renumberTableRows();
  141. currentRowId++;
  142. reset2();
  143. }
  144. function setUploadField()
  145. {
  146. var e = $K.dom('#uploadfield');
  147. var uf =`<div class="upload"
  148. data-kube="upload"
  149. data-type="file" data-multiple="true"
  150. data-target="#upload-target${currentRowId}"
  151. data-url="upload.php?row=${currentRowId}" data-url-remove="delete.php"
  152. data-progress="true">Beleg hochladen
  153. </div>
  154. <div id="upload-target${currentRowId}" class="upload-target small"></div>
  155. </div>
  156. `;
  157. document.getElementById("uploadfield").innerHTML=uf;
  158. }
  159. $K.add('module', 'kaform', {
  160. init: function(app, context)
  161. {
  162. this.app = app;
  163. this.message = app.message;
  164. },
  165. // catch event
  166. onmessage: {
  167. tabs: {
  168. opened: function(sender)
  169. {
  170. console.log('Tab box is ',sender.getActiveBox());
  171. // this.message.show({ message: 'My message' });
  172. }
  173. }
  174. },
  175. });
  176. $K.init({
  177. observer: true
  178. });
  179. // startup is here
  180. // on startup clear session on server
  181. $K.ajax.get({
  182. url: 'clear.php',
  183. data: '', // or key=value object
  184. before: function(xhr) {},
  185. success: function(response) {},
  186. error: function(response) {}
  187. });
  188. setUploadField();
  189. function check_field(fieldid,message){
  190. var f = document.getElementById(fieldid).value;
  191. if (! f.trim().length ) {
  192. document.getElementById(fieldid).focus();
  193. showAlert(message)
  194. return false;
  195. }
  196. return true;
  197. }
  198. // add on table row
  199. //addTableRow();
  200. //
  201. //
  202. //
  203. function downloadDocument()
  204. {
  205. if (!check_field("nickname", "Bitte gib deinen Nicknamen an!"))
  206. return;
  207. if (!check_field("realname", "Bitte gib deinen Realnamen an!"))
  208. return;
  209. if (!check_field("email", "Bitte gib deinen E-Mail-Adresse an!"))
  210. return;
  211. if (!check_field("projectid", "Bitte gib idie Projekt-ID an!"))
  212. return;
  213. if (countRows()==0){
  214. document.getElementById("a_type").focus();
  215. showAlert("Bitte f&uuml;ge mind. eine Auslage hinzu!");
  216. return;
  217. }
  218. document.getElementById("theform").submit();
  219. }