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.

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