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.

350 lines
7.9 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. var a_date = document.getElementById("a_date").value;
  75. if (!a_date.trim().length){
  76. document.getElementById("a_date").focus();
  77. showAlert("Bitte gib ein g&uuml;ltiges Datum an!");
  78. return;
  79. }
  80. var a_description = document.getElementById("a_description").value;
  81. if (!a_description.trim().length){
  82. document.getElementById("a_description").focus();
  83. showAlert("Bitte gib eine Beschreibung ein!");
  84. return;
  85. }
  86. var a_amount = document.getElementById("a_amount").value;
  87. if (!isFloat(a_amount)){
  88. document.getElementById("a_amount").focus();
  89. showAlert("Bitte gib einen g&uuml;ltigen Betrag ein!");
  90. return;
  91. }
  92. var a_currency = document.getElementById("a_currency").value;
  93. if (!a_currency.trim().length){
  94. document.getElementById("a_currency").focus();
  95. showAlert("Bitte gib eine W&auml;hrung an!");
  96. return;
  97. }
  98. var target = document.getElementById("upload-target"+currentRowId);
  99. var children = target.children;
  100. if (!children.length){
  101. showAlert("Bitte lade mindestens einen Beleg hoch!");
  102. return;
  103. }
  104. /* a_type = "Hello";*/
  105. var e="";
  106. // add column for position no
  107. e += `<td>${a_type}
  108. <input type="hidden" name="type[${currentRowId}]" value="${a_type}" /></td>`;
  109. // add coluemn for a_type (Auslagenart)
  110. // e += `<td><textarea name="desc[${nextRowId}]" rows="2"></textarea> </td>`;
  111. e += `<td>${a_date}
  112. <input type="hidden" name="date[${currentRowId}]" value="${a_date}" /></td>`;
  113. // add column for date
  114. // e += `<td><input name="date[${nextRowId}]" type="date"/></td>`;
  115. e += `<td>${a_description}
  116. <input type="hidden" name="description[${currentRowId}]" value="${a_description}" /></td>`;
  117. // add column for num
  118. e += `<td>${a_amount}
  119. <input type="hidden" name="amount[${currentRowId}]" value="${a_amount}" /></td>`;
  120. // add column for file upload
  121. /* e+= `
  122. <td data-kube="">
  123. <div class="form-item">
  124. <div class="upload"
  125. data-kube="upload"
  126. data-type="file" data-multiple="true"
  127. data-target="#upload-target${nextRowId}"
  128. data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
  129. data-progress="true">
  130. </div>
  131. <div id="upload-target${nextRowId}" class="upload-target"></div>
  132. </div>
  133. </td>
  134. */
  135. e += `<td>${a_currency}</td>`;
  136. // `;
  137. // add delete bnutton
  138. e +=
  139. `<td><span
  140. onclick="deleteTableRow(${currentRowId})"
  141. class="close is-large">
  142. </span></td>`;
  143. $node.append(element);
  144. element.innerHTML=(e);
  145. // renumberTableRows();
  146. currentRowId++;
  147. reset2();
  148. }
  149. function setUploadField()
  150. {
  151. var e = $K.dom('#uploadfield');
  152. var uf =`<div class="upload"
  153. data-kube="upload"
  154. data-type="file" data-multiple="true"
  155. data-target="#upload-target${currentRowId}"
  156. data-url="upload.php?row=${currentRowId}" data-url-remove="delete.php"
  157. data-progress="true">Beleg hochladen
  158. </div>
  159. <div id="upload-target${currentRowId}" class="upload-target small"></div>
  160. </div>
  161. `;
  162. document.getElementById("uploadfield").innerHTML=uf;
  163. }
  164. $K.add('module', 'kaform', {
  165. init: function(app, context)
  166. {
  167. this.app = app;
  168. this.message = app.message;
  169. },
  170. // catch event
  171. onmessage: {
  172. tabs: {
  173. opened: function(sender)
  174. {
  175. console.log('Tab box is ',sender.getActiveBox().nodes[0]);
  176. banktype = sender.getActiveBox().nodes[0].attributes.id.value;
  177. console.log(banktype);
  178. // console.log(sender);
  179. // this.message.show({ message: 'My message' });
  180. }
  181. }
  182. },
  183. });
  184. $K.init({
  185. observer: true
  186. });
  187. // startup is here
  188. // on startup clear session on server
  189. $K.ajax.get({
  190. url: 'clear.php',
  191. data: '', // or key=value object
  192. before: function(xhr) {},
  193. success: function(response) {},
  194. error: function(response) {}
  195. });
  196. setUploadField();
  197. function check_field(fieldid,message){
  198. var f = document.getElementById(fieldid).value;
  199. if (! f.trim().length ) {
  200. document.getElementById(fieldid).focus();
  201. showAlert(message)
  202. return false;
  203. }
  204. return true;
  205. }
  206. // add on table row
  207. //addTableRow();
  208. //
  209. //
  210. //
  211. function downloadDocument()
  212. {
  213. if (!check_field("nickname", "Bitte gib deinen Nicknamen an!"))
  214. return;
  215. if (!check_field("realname", "Bitte gib deinen Realnamen an!"))
  216. return;
  217. if (!check_field("email", "Bitte gib deinen E-Mail-Adresse an!"))
  218. return;
  219. if (!check_field("projectid", "Bitte gib idie Projekt-ID an!"))
  220. return;
  221. if (countRows()==0){
  222. document.getElementById("a_type").focus();
  223. showAlert("Bitte f&uuml;ge mind. eine Auslage hinzu!");
  224. return;
  225. }
  226. if (banktype == "bank-eu"){
  227. iban = document.getElementById('iban');
  228. if (!IBAN.isValid(iban.value)){
  229. document.getElementById("iban").focus();
  230. showAlert("Bitte igib eine korrekte IBAN ein!");
  231. return;
  232. }
  233. }
  234. if (banktype == "bank-paypal"){
  235. ii = document.getElementById('paypal');
  236. if (!document.getElementById('paypal').value.trim().length){
  237. document.getElementById("paypal").focus();
  238. showAlert("Bitte gib einen PayPal Account an!");
  239. return;
  240. }
  241. }
  242. document.getElementById('banktype').value=banktype;
  243. document.getElementById("theform").submit();
  244. }
  245. /*
  246. function checkIban()
  247. {
  248. iban = document.getElementById('iban');
  249. if(IBAN.isValid(iban.value))
  250. if( document.getElementById('eu').checked ) {
  251. if(IBAN.isValid(iban.value))
  252. {
  253. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  254. iban.classList.add('valid');
  255. }
  256. else {
  257. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  258. iban.classList.add('invalid');
  259. }
  260. } else {
  261. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  262. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  263. }
  264. }
  265. */