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.

391 lines
8.1 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="Datei">
  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 data-label=\"Pos\">"
  124. + `${num}`
  125. +"</td>"
  126. + "<td data-label=\"Datum\">"
  127. + `<input class="tab_input" name="date[${rid}]" value="" type="date" placeholder="Datum*"/>`
  128. + "</td>"
  129. + "<td data-label=\"Beschr.\">"
  130. + `<input class="tab_input" name="desc[${rid}]" type="text" placeholder="Beschreibung"/>`
  131. + "</td>"
  132. + "<td data-label=\"Betrag\">"
  133. + `<input class="tab_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>
  153. </td>`;
  154. }
  155. var nextRid = 1
  156. function addRow() {
  157. var $node = $K.dom('#tabbody');
  158. var e = getRow(nextRid,1);
  159. var element = document.createElement('tr');
  160. element.setAttribute("id", "trow"+nextRid);
  161. $node.append(element);
  162. element.innerHTML=(e);
  163. renumberTableRows();
  164. nextRid++;
  165. }
  166. $K.add('module', 'kaform', {
  167. init: function(app, context)
  168. {
  169. this.app = app;
  170. this.message = app.message;
  171. },
  172. // catch event
  173. onmessage: {
  174. tabs: {
  175. opened: function(sender)
  176. {
  177. console.log('Tab box is ',sender.getActiveBox().nodes[0]);
  178. banktype = sender.getActiveBox().nodes[0].attributes.id.value;
  179. console.log(banktype);
  180. // console.log(sender);
  181. // this.message.show({ message: 'My message' });
  182. }
  183. }
  184. },
  185. });
  186. $K.init({
  187. observer: true
  188. });
  189. // startup is here
  190. // on startup clear session on server
  191. $K.ajax.get({
  192. url: 'clear.php',
  193. data: '', // or key=value object
  194. before: function(xhr) {},
  195. success: function(response) {},
  196. error: function(response) {}
  197. });
  198. function check_field(fieldid,message){
  199. var f = document.getElementById(fieldid).value;
  200. if (! f.trim().length ) {
  201. document.getElementById(fieldid).focus();
  202. showAlert(message)
  203. return false;
  204. }
  205. return true;
  206. }
  207. // add on table row
  208. //addTableRow();
  209. //
  210. //
  211. //
  212. //
  213. function downloadDocument2(){
  214. downloadDocument(true);
  215. }
  216. function downloadDocument1(){
  217. downloadDocument(false);
  218. }
  219. function downloadDocument(mail)
  220. {
  221. if (!checkAllRows())
  222. return;
  223. if (!check_field("projectid", "Bitte gib einen Projektnamen/Zweck der Reise an!"))
  224. return;
  225. if (!check_field("realname", "Bitte gib deinen Realnamen an!"))
  226. return;
  227. if (!check_field("email", "Bitte gib deinen E-Mail-Adresse an!"))
  228. return;
  229. if (banktype == "bank-eu"){
  230. iban = document.getElementById('iban');
  231. if (!IBAN.isValid(iban.value)){
  232. document.getElementById("iban").focus();
  233. showAlert("Bitte gib eine korrekte IBAN ein!");
  234. return;
  235. }
  236. /* if (!document.getElementById('bic').value.trim().length){
  237. document.getElementById("bic").focus();
  238. showAlert("Bitte gib einen korrekte BIC an!");
  239. return;
  240. }
  241. */
  242. }
  243. if (banktype == "bank-paypal"){
  244. ii = document.getElementById('paypal');
  245. if (!document.getElementById('paypal').value.trim().length){
  246. document.getElementById("paypal").focus();
  247. showAlert("Bitte gib einen PayPal Account an!");
  248. return;
  249. }
  250. }
  251. if (countRows()==0){
  252. document.getElementById("add_issue").focus();
  253. showAlert("Bitte f&uuml;ge mind. eine Auslage hinzu!");
  254. return;
  255. }
  256. if (!document.getElementById("agree").checked){
  257. document.getElementById("agree").focus();
  258. showAlert("Bitte best&auml;tige, dass du alle Angaben nach bestem Wissen und Gewissen gemacht hast!");
  259. return;
  260. };
  261. if (mail){
  262. if (!isMailable()){
  263. showAlert("Um den Antrag elektronisch direkt an WMDE zu schicken, muss jeder Position ein Beleg beigef&uuml;gt sein.");
  264. return;
  265. }
  266. document.getElementById('sendmail').value="yes";
  267. }
  268. else{
  269. document.getElementById('sendmail').value="no";
  270. }
  271. document.getElementById('banktype').value=banktype;
  272. document.getElementById("theform").submit();
  273. }
  274. /*
  275. function checkIban()
  276. {
  277. iban = document.getElementById('iban');
  278. if(IBAN.isValid(iban.value))
  279. if( document.getElementById('eu').checked ) {
  280. if(IBAN.isValid(iban.value))
  281. {
  282. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  283. iban.classList.add('valid');
  284. }
  285. else {
  286. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  287. iban.classList.add('invalid');
  288. }
  289. } else {
  290. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  291. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  292. }
  293. }
  294. */