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.

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