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.

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