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.

357 lines
8.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
  1. var currentRowId=1;
  2. var banktype = "bank-eu";
  3. function renumberTableRows(){
  4. var row_no=1;
  5. var table = document.getElementById("tabbody");
  6. for (var i = 0, row; row = table.rows[i]; i++) {
  7. // row.cells[0].innerHTML=row_no++;
  8. }
  9. }
  10. function isFloat(val) {
  11. var floatRegex = /^-?\d+(?:[.,]\d*?)?$/;
  12. if (!floatRegex.test(val))
  13. return false;
  14. val = parseFloat(val);
  15. if (isNaN(val))
  16. return false;
  17. return true;
  18. }
  19. function deleteTableRow(rowId){
  20. var target = document.getElementById("upload-target"+rowId);
  21. // this.message = app.message;
  22. // var children = target.children;
  23. // delete all uploaded elements
  24. /* for (var i = 0; i < children.length; i++) {
  25. var tmp = children[i].getAttribute("data-id");
  26. alert ("DEL");
  27. alert (tmp);
  28. $K.ajax.post({
  29. url: 'delete.php',
  30. data: 'id='+tmp,
  31. before: function(xhr) {},
  32. success: function(response) {},
  33. error: function(response) {}
  34. });
  35. }
  36. */
  37. // delete the row from table
  38. var element = document.getElementById("trow"+rowId);
  39. element.parentNode.removeChild(element);
  40. renumberTableRows();
  41. // alert(rowId);
  42. }
  43. function countRows(){
  44. var ctr=0;
  45. for (i=0; i<currentRowId; i++){
  46. var element = document.getElementById("trow"+i);
  47. if (element)
  48. ctr++
  49. }
  50. return ctr;
  51. }
  52. function showAlert(text) {
  53. $K.app.message.show( { message: `${text}`, position: 'centered', type: 'is-error' });
  54. return;
  55. }
  56. function reset2()
  57. {
  58. // document.getElementById("a_type").value="";
  59. document.getElementById("a_description").value="";
  60. document.getElementById("a_amount").value="";
  61. setUploadField();
  62. }
  63. function addTableRow(){
  64. var $node = $K.dom('#tabbody');
  65. // create a new table row with id
  66. var element = document.createElement('tr');
  67. element.setAttribute("id", "trow"+currentRowId);
  68. /* var a_type = document.getElementById("a_type").value;
  69. if (!a_type.trim().length ) {
  70. document.getElementById("a_type").focus();
  71. showAlert("Bitte gib eine Auslagenart an!");
  72. return;
  73. }
  74. */
  75. var a_date = document.getElementById("a_date").value;
  76. if (!a_date.trim().length){
  77. document.getElementById("a_date").focus();
  78. showAlert("Bitte gib ein g&uuml;ltiges Datum an!");
  79. return;
  80. }
  81. var a_description = document.getElementById("a_description").value;
  82. if (!a_description.trim().length){
  83. document.getElementById("a_description").focus();
  84. showAlert("Bitte gib eine Beschreibung ein!");
  85. return;
  86. }
  87. var a_amount = document.getElementById("a_amount").value;
  88. if (!isFloat(a_amount)){
  89. document.getElementById("a_amount").focus();
  90. showAlert("Bitte gib einen g&uuml;ltigen Betrag ein!");
  91. return;
  92. }
  93. var a_currency = document.getElementById("a_currency").value;
  94. if (!a_currency.trim().length){
  95. document.getElementById("a_currency").focus();
  96. showAlert("Bitte gib eine W&auml;hrung an!");
  97. return;
  98. }
  99. var target = document.getElementById("upload-target"+currentRowId);
  100. var children = target.children;
  101. if (!children.length){
  102. showAlert("Bitte lade mindestens einen Beleg hoch!");
  103. return;
  104. }
  105. /* a_type = "Hello";*/
  106. var e="";
  107. // add column for position no
  108. // e += `<td>${a_type}
  109. // <input type="hidden" name="type[${currentRowId}]" value="${a_type}" /></td>`;
  110. // add coluemn for a_type (Auslagenart)
  111. // e += `<td><textarea name="desc[${nextRowId}]" rows="2"></textarea> </td>`;
  112. e += `<td>${a_date}
  113. <input type="hidden" name="date[${currentRowId}]" value="${a_date}" /></td>`;
  114. // add column for date
  115. // e += `<td><input name="date[${nextRowId}]" type="date"/></td>`;
  116. e += `<td>${a_description}
  117. <input type="hidden" name="description[${currentRowId}]" value="${a_description}" /></td>`;
  118. // add column for num
  119. e += `<td>${a_amount}
  120. <input type="hidden" name="amount[${currentRowId}]" value="${a_amount}" /></td>`;
  121. // add column for file upload
  122. /* e+= `
  123. <td data-kube="">
  124. <div class="form-item">
  125. <div class="upload"
  126. data-kube="upload"
  127. data-type="file" data-multiple="true"
  128. data-target="#upload-target${nextRowId}"
  129. data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
  130. data-progress="true">
  131. </div>
  132. <div id="upload-target${nextRowId}" class="upload-target"></div>
  133. </div>
  134. </td>
  135. */
  136. e += `<td>${a_currency}</td>`;
  137. // `;
  138. // add delete bnutton
  139. e +=
  140. `<td><span
  141. onclick="deleteTableRow(${currentRowId})"
  142. class="close is-large">
  143. </span></td>`;
  144. $node.append(element);
  145. element.innerHTML=(e);
  146. // renumberTableRows();
  147. currentRowId++;
  148. reset2();
  149. }
  150. function setUploadField()
  151. {
  152. var e = $K.dom('#uploadfield');
  153. var uf =`<div class="upload"
  154. data-kube="upload"
  155. data-type="file" data-multiple="true"
  156. data-target="#upload-target${currentRowId}"
  157. data-url="upload.php?row=${currentRowId}" data-url-remove="delete.php"
  158. data-progress="true">Beleg hochladen
  159. </div>
  160. <div id="upload-target${currentRowId}" class="upload-target small"></div>
  161. </div>
  162. `;
  163. document.getElementById("uploadfield").innerHTML=uf;
  164. }
  165. $K.add('module', 'kaform', {
  166. init: function(app, context)
  167. {
  168. this.app = app;
  169. this.message = app.message;
  170. },
  171. // catch event
  172. onmessage: {
  173. tabs: {
  174. opened: function(sender)
  175. {
  176. console.log('Tab box is ',sender.getActiveBox().nodes[0]);
  177. banktype = sender.getActiveBox().nodes[0].attributes.id.value;
  178. console.log(banktype);
  179. // console.log(sender);
  180. // this.message.show({ message: 'My message' });
  181. }
  182. }
  183. },
  184. });
  185. $K.init({
  186. observer: true
  187. });
  188. // startup is here
  189. // on startup clear session on server
  190. $K.ajax.get({
  191. url: 'clear.php',
  192. data: '', // or key=value object
  193. before: function(xhr) {},
  194. success: function(response) {},
  195. error: function(response) {}
  196. });
  197. setUploadField();
  198. function check_field(fieldid,message){
  199. var f = document.getElementById(fieldid).value;
  200. if (! f.trim().length ) {
  201. document.getElementById(fieldid).focus();
  202. showAlert(message)
  203. return false;
  204. }
  205. return true;
  206. }
  207. // add on table row
  208. //addTableRow();
  209. //
  210. //
  211. //
  212. function downloadDocument()
  213. {
  214. /* if (!check_field("nickname", "Bitte gib deinen Nicknamen an!"))
  215. return;
  216. */ if (!check_field("realname", "Bitte gib deinen Realnamen an!"))
  217. return;
  218. if (!check_field("email", "Bitte gib deinen E-Mail-Adresse an!"))
  219. return;
  220. if (!check_field("projectid", "Bitte gib idie Projekt-ID an!"))
  221. return;
  222. if (countRows()==0){
  223. document.getElementById("a_type").focus();
  224. showAlert("Bitte f&uuml;ge mind. eine Auslage hinzu!");
  225. return;
  226. }
  227. if (banktype == "bank-eu"){
  228. iban = document.getElementById('iban');
  229. if (!IBAN.isValid(iban.value)){
  230. document.getElementById("iban").focus();
  231. showAlert("Bitte gib eine korrekte IBAN ein!");
  232. return;
  233. }
  234. if (!document.getElementById('bic').value.trim().length){
  235. document.getElementById("bic").focus();
  236. showAlert("Bitte gib einen koreekte BIC an!");
  237. return;
  238. }
  239. }
  240. if (banktype == "bank-paypal"){
  241. ii = document.getElementById('paypal');
  242. if (!document.getElementById('paypal').value.trim().length){
  243. document.getElementById("paypal").focus();
  244. showAlert("Bitte gib einen PayPal Account an!");
  245. return;
  246. }
  247. }
  248. document.getElementById('banktype').value=banktype;
  249. document.getElementById("theform").submit();
  250. }
  251. /*
  252. function checkIban()
  253. {
  254. iban = document.getElementById('iban');
  255. if(IBAN.isValid(iban.value))
  256. if( document.getElementById('eu').checked ) {
  257. if(IBAN.isValid(iban.value))
  258. {
  259. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  260. iban.classList.add('valid');
  261. }
  262. else {
  263. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  264. iban.classList.add('invalid');
  265. }
  266. } else {
  267. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  268. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  269. }
  270. }
  271. */