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.

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