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.

399 lines
8.0 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 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 ( !isFloat(v) ){ // Amount
  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. }
  95. function countRows(){
  96. return renumberTableRows();
  97. }
  98. function showAlert(text) {
  99. $K.app.message.show( { message: `${text}`, position: 'centered', type: 'is-error' });
  100. }
  101. function setTableRow(id)
  102. {
  103. var $node = $K.dom('#tabbody');
  104. var element = document.createElement('tr');
  105. element.setAttribute("id", "trow"+id);
  106. var e
  107. e = `<td>${a_date}
  108. <input type="hidden" name="date[${currentRowId}]" value="${a_date}" /></td>`;
  109. $node.append(element);
  110. element.innerHTML=(e);
  111. }
  112. function getUploadField(rid)
  113. {
  114. var e = $K.dom('#uploadfield');
  115. var uf =`<div class="upload"
  116. data-kube="upload"
  117. data-type="file"
  118. data-multiple="true"
  119. data-target="#upload-target${rid}"
  120. data-url="upload.php?row=${rid}" data-url-remove="delete.php"
  121. data-progress="true"
  122. data-size="40"
  123. data-placeholder="drag!">
  124. </div>
  125. <div id="upload-target${rid}" class="upload-target small"></div>
  126. </div>
  127. `;
  128. return uf;
  129. }
  130. function getRow(rid,num) {
  131. return ""
  132. + "<td>"
  133. + `${num}`
  134. +"</td>"
  135. + "<td>"
  136. + `<input name="date[${rid}]" value="" type="date" placeholder="Datum*"/>`
  137. + "</td>"
  138. + "<td>"
  139. + `<input name="desc[${rid}]" type="text" placeholder="Beschreibung"/>`
  140. + "</td>"
  141. + "<td>"
  142. + `<input name="amount[${rid}] type="text" placeholder="0.00"/>`
  143. + "</td>"
  144. + "<td>"
  145. +
  146. `<select name="currency[${rid}]" >
  147. <option value="EUR">EUR</option>
  148. <option value="USD">USD</option>
  149. <option value="CHF">CHF</option>
  150. <option value="XBT">XBT</option>
  151. </select>`
  152. + "</td>"
  153. + "<td>"
  154. + getUploadField(rid)
  155. + "</td>"
  156. +
  157. `<td><span
  158. onclick="deleteTableRow(${rid})"
  159. class="close is-large">
  160. </span></td>`;
  161. }
  162. var nextRid = 1
  163. function addRow() {
  164. var $node = $K.dom('#tabbody');
  165. var e = getRow(nextRid,1);
  166. var element = document.createElement('tr');
  167. element.setAttribute("id", "trow"+nextRid);
  168. $node.append(element);
  169. element.innerHTML=(e);
  170. renumberTableRows();
  171. nextRid++;
  172. }
  173. $K.add('module', 'kaform', {
  174. init: function(app, context)
  175. {
  176. this.app = app;
  177. this.message = app.message;
  178. },
  179. // catch event
  180. onmessage: {
  181. tabs: {
  182. opened: function(sender)
  183. {
  184. console.log('Tab box is ',sender.getActiveBox().nodes[0]);
  185. banktype = sender.getActiveBox().nodes[0].attributes.id.value;
  186. console.log(banktype);
  187. // console.log(sender);
  188. // this.message.show({ message: 'My message' });
  189. }
  190. }
  191. },
  192. });
  193. $K.init({
  194. observer: true
  195. });
  196. // startup is here
  197. // on startup clear session on server
  198. $K.ajax.get({
  199. url: 'clear.php',
  200. data: '', // or key=value object
  201. before: function(xhr) {},
  202. success: function(response) {},
  203. error: function(response) {}
  204. });
  205. function check_field(fieldid,message){
  206. var f = document.getElementById(fieldid).value;
  207. if (! f.trim().length ) {
  208. document.getElementById(fieldid).focus();
  209. showAlert(message)
  210. return false;
  211. }
  212. return true;
  213. }
  214. // add on table row
  215. //addTableRow();
  216. //
  217. //
  218. //
  219. //
  220. function downloadDocument2(){
  221. downloadDocument(true);
  222. }
  223. function downloadDocument1(){
  224. downloadDocument(false);
  225. }
  226. function downloadDocument(mail)
  227. {
  228. if (!checkAllRows())
  229. return;
  230. if (!check_field("projectid", "Bitte gib einen Projektnamen/Zweck der Reise an!"))
  231. return;
  232. if (!check_field("realname", "Bitte gib deinen Realnamen an!"))
  233. return;
  234. if (!check_field("email", "Bitte gib deinen E-Mail-Adresse an!"))
  235. return;
  236. if (banktype == "bank-eu"){
  237. iban = document.getElementById('iban');
  238. if (!IBAN.isValid(iban.value)){
  239. document.getElementById("iban").focus();
  240. showAlert("Bitte gib eine korrekte IBAN ein!");
  241. return;
  242. }
  243. /* if (!document.getElementById('bic').value.trim().length){
  244. document.getElementById("bic").focus();
  245. showAlert("Bitte gib einen korrekte BIC an!");
  246. return;
  247. }
  248. */
  249. }
  250. if (banktype == "bank-paypal"){
  251. ii = document.getElementById('paypal');
  252. if (!document.getElementById('paypal').value.trim().length){
  253. document.getElementById("paypal").focus();
  254. showAlert("Bitte gib einen PayPal Account an!");
  255. return;
  256. }
  257. }
  258. if (countRows()==0){
  259. document.getElementById("add_issue").focus();
  260. showAlert("Bitte f&uuml;ge mind. eine Auslage hinzu!");
  261. return;
  262. }
  263. if (!document.getElementById("agree").checked){
  264. document.getElementById("agree").focus();
  265. showAlert("Bitte best&auml;tige, dass du alle Angaben nach bestem Wissen und Gewissen gemacht hast!");
  266. return;
  267. };
  268. if (mail){
  269. if (!isMailable()){
  270. showAlert("Um den Antrag elektronisch direkt an WMDE zu schicken, muss jeder Position ein Beleg beigef&uuml;gt sein.");
  271. return;
  272. }
  273. document.getElementById('sendmail').value="yes";
  274. }
  275. else{
  276. document.getElementById('sendmail').value="no";
  277. }
  278. document.getElementById('banktype').value=banktype;
  279. document.getElementById("theform").submit();
  280. }
  281. /*
  282. function checkIban()
  283. {
  284. iban = document.getElementById('iban');
  285. if(IBAN.isValid(iban.value))
  286. if( document.getElementById('eu').checked ) {
  287. if(IBAN.isValid(iban.value))
  288. {
  289. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  290. iban.classList.add('valid');
  291. }
  292. else {
  293. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  294. iban.classList.add('invalid');
  295. }
  296. } else {
  297. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  298. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  299. }
  300. }
  301. */