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.

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