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.

295 lines
6.4 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}
  107. <input type="hidden" name="type[${currentRowId}]" value="${a_type}" /></td>`;
  108. // add coluemn for a_type (Auslagenart)
  109. // e += `<td><textarea name="desc[${nextRowId}]" rows="2"></textarea> </td>`;
  110. e += `<td>${a_date}
  111. <input type="hidden" name="date[${currentRowId}]" value="${a_date}" /></td>`;
  112. // add column for date
  113. // e += `<td><input name="date[${nextRowId}]" type="date"/></td>`;
  114. e += `<td>${a_description}
  115. <input type="hidden" name="description[${currentRowId}]" value="${a_description}" /></td>`;
  116. // add column for num
  117. e += `<td>${a_amount}
  118. <input type="hidden" name="amount[${currentRowId}]" value="${a_amount}" /></td>`;
  119. // add column for file upload
  120. /* e+= `
  121. <td data-kube="">
  122. <div class="form-item">
  123. <div class="upload"
  124. data-kube="upload"
  125. data-type="file" data-multiple="true"
  126. data-target="#upload-target${nextRowId}"
  127. data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
  128. data-progress="true">
  129. </div>
  130. <div id="upload-target${nextRowId}" class="upload-target"></div>
  131. </div>
  132. </td>
  133. */
  134. e += `<td>${a_currency}</td>`;
  135. // `;
  136. // add delete bnutton
  137. e +=
  138. `<td><span
  139. onclick="deleteTableRow(${currentRowId})"
  140. class="close is-large">
  141. </span></td>`;
  142. $node.append(element);
  143. element.innerHTML=(e);
  144. // renumberTableRows();
  145. currentRowId++;
  146. reset2();
  147. }
  148. function setUploadField()
  149. {
  150. var e = $K.dom('#uploadfield');
  151. var uf =`<div class="upload"
  152. data-kube="upload"
  153. data-type="file" data-multiple="true"
  154. data-target="#upload-target${currentRowId}"
  155. data-url="upload.php?row=${currentRowId}" data-url-remove="delete.php"
  156. data-progress="true">Beleg hochladen
  157. </div>
  158. <div id="upload-target${currentRowId}" class="upload-target small"></div>
  159. </div>
  160. `;
  161. document.getElementById("uploadfield").innerHTML=uf;
  162. }
  163. $K.add('module', 'kaform', {
  164. init: function(app, context)
  165. {
  166. this.app = app;
  167. this.message = app.message;
  168. },
  169. // catch event
  170. onmessage: {
  171. tabs: {
  172. opened: function(sender)
  173. {
  174. console.log('Tab box is ',sender.getActiveBox());
  175. // this.message.show({ message: 'My message' });
  176. }
  177. }
  178. },
  179. });
  180. $K.init({
  181. observer: true
  182. });
  183. // startup is here
  184. // on startup clear session on server
  185. $K.ajax.get({
  186. url: 'clear.php',
  187. data: '', // or key=value object
  188. before: function(xhr) {},
  189. success: function(response) {},
  190. error: function(response) {}
  191. });
  192. setUploadField();
  193. function check_field(fieldid,message){
  194. var f = document.getElementById(fieldid).value;
  195. if (! f.trim().length ) {
  196. document.getElementById(fieldid).focus();
  197. showAlert(message)
  198. return false;
  199. }
  200. return true;
  201. }
  202. // add on table row
  203. //addTableRow();
  204. //
  205. //
  206. //
  207. function downloadDocument()
  208. {
  209. if (!check_field("nickname", "Bitte gib deinen Nicknamen an!"))
  210. return;
  211. if (!check_field("realname", "Bitte gib deinen Realnamen an!"))
  212. return;
  213. if (!check_field("email", "Bitte gib deinen E-Mail-Adresse an!"))
  214. return;
  215. if (!check_field("projectid", "Bitte gib idie Projekt-ID an!"))
  216. return;
  217. if (countRows()==0){
  218. document.getElementById("a_type").focus();
  219. showAlert("Bitte f&uuml;ge mind. eine Auslage hinzu!");
  220. return;
  221. }
  222. document.getElementById("theform").submit();
  223. }