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.

359 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}
  137. <input type="hidden" name="currency[${currentRowId}]" value="${a_currency}" /></td>
  138. </td>`;
  139. // `;
  140. // add delete bnutton
  141. e +=
  142. `<td><span
  143. onclick="deleteTableRow(${currentRowId})"
  144. class="close is-large">
  145. </span></td>`;
  146. $node.append(element);
  147. element.innerHTML=(e);
  148. // renumberTableRows();
  149. currentRowId++;
  150. reset2();
  151. }
  152. function setUploadField()
  153. {
  154. var e = $K.dom('#uploadfield');
  155. var uf =`<div class="upload"
  156. data-kube="upload"
  157. data-type="file" data-multiple="true"
  158. data-target="#upload-target${currentRowId}"
  159. data-url="upload.php?row=${currentRowId}" data-url-remove="delete.php"
  160. data-progress="true">Beleg hochladen
  161. </div>
  162. <div id="upload-target${currentRowId}" class="upload-target small"></div>
  163. </div>
  164. `;
  165. document.getElementById("uploadfield").innerHTML=uf;
  166. }
  167. $K.add('module', 'kaform', {
  168. init: function(app, context)
  169. {
  170. this.app = app;
  171. this.message = app.message;
  172. },
  173. // catch event
  174. onmessage: {
  175. tabs: {
  176. opened: function(sender)
  177. {
  178. console.log('Tab box is ',sender.getActiveBox().nodes[0]);
  179. banktype = sender.getActiveBox().nodes[0].attributes.id.value;
  180. console.log(banktype);
  181. // console.log(sender);
  182. // this.message.show({ message: 'My message' });
  183. }
  184. }
  185. },
  186. });
  187. $K.init({
  188. observer: true
  189. });
  190. // startup is here
  191. // on startup clear session on server
  192. $K.ajax.get({
  193. url: 'clear.php',
  194. data: '', // or key=value object
  195. before: function(xhr) {},
  196. success: function(response) {},
  197. error: function(response) {}
  198. });
  199. setUploadField();
  200. function check_field(fieldid,message){
  201. var f = document.getElementById(fieldid).value;
  202. if (! f.trim().length ) {
  203. document.getElementById(fieldid).focus();
  204. showAlert(message)
  205. return false;
  206. }
  207. return true;
  208. }
  209. // add on table row
  210. //addTableRow();
  211. //
  212. //
  213. //
  214. function downloadDocument()
  215. {
  216. /* if (!check_field("nickname", "Bitte gib deinen Nicknamen an!"))
  217. return;
  218. */ if (!check_field("realname", "Bitte gib deinen Realnamen an!"))
  219. return;
  220. if (!check_field("email", "Bitte gib deinen E-Mail-Adresse an!"))
  221. return;
  222. if (!check_field("projectid", "Bitte gib idie Projekt-ID an!"))
  223. return;
  224. if (countRows()==0){
  225. document.getElementById("a_description").focus();
  226. showAlert("Bitte f&uuml;ge mind. eine Auslage hinzu!");
  227. return;
  228. }
  229. if (banktype == "bank-eu"){
  230. iban = document.getElementById('iban');
  231. if (!IBAN.isValid(iban.value)){
  232. document.getElementById("iban").focus();
  233. showAlert("Bitte gib eine korrekte IBAN ein!");
  234. return;
  235. }
  236. if (!document.getElementById('bic').value.trim().length){
  237. document.getElementById("bic").focus();
  238. showAlert("Bitte gib einen koreekte BIC an!");
  239. return;
  240. }
  241. }
  242. if (banktype == "bank-paypal"){
  243. ii = document.getElementById('paypal');
  244. if (!document.getElementById('paypal').value.trim().length){
  245. document.getElementById("paypal").focus();
  246. showAlert("Bitte gib einen PayPal Account an!");
  247. return;
  248. }
  249. }
  250. document.getElementById('banktype').value=banktype;
  251. document.getElementById("theform").submit();
  252. }
  253. /*
  254. function checkIban()
  255. {
  256. iban = document.getElementById('iban');
  257. if(IBAN.isValid(iban.value))
  258. if( document.getElementById('eu').checked ) {
  259. if(IBAN.isValid(iban.value))
  260. {
  261. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  262. iban.classList.add('valid');
  263. }
  264. else {
  265. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  266. iban.classList.add('invalid');
  267. }
  268. } else {
  269. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  270. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  271. }
  272. }
  273. */