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.

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