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.

406 lines
8.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
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 isFloat(val) {
  12. var floatRegex = /^-?\d+(?:[.,]\d*?)?$/;
  13. if (!floatRegex.test(val))
  14. return false;
  15. val = parseFloat(val);
  16. if (isNaN(val))
  17. return false;
  18. return true;
  19. }
  20. function disableCurrency()
  21. {
  22. if (countRows()>0){
  23. document.getElementById("a_currency").disabled=true;
  24. }
  25. else {
  26. document.getElementById("a_currency").disabled=true;
  27. }
  28. }
  29. function deleteTableRow(rowId){
  30. var target = document.getElementById("upload-target"+rowId);
  31. // this.message = app.message;
  32. // var children = target.children;
  33. // delete all uploaded elements
  34. /* for (var i = 0; i < children.length; i++) {
  35. var tmp = children[i].getAttribute("data-id");
  36. alert ("DEL");
  37. alert (tmp);
  38. $K.ajax.post({
  39. url: 'delete.php',
  40. data: 'id='+tmp,
  41. before: function(xhr) {},
  42. success: function(response) {},
  43. error: function(response) {}
  44. });
  45. }
  46. */
  47. // delete the row from table
  48. var element = document.getElementById("trow"+rowId);
  49. element.parentNode.removeChild(element);
  50. disableCurrency();
  51. renumberTableRows();
  52. // alert(rowId);
  53. }
  54. function countRows(){
  55. var ctr=0;
  56. for (i=0; i<currentRowId; i++){
  57. var element = document.getElementById("trow"+i);
  58. if (element)
  59. ctr++
  60. }
  61. return ctr;
  62. }
  63. function showAlert(text) {
  64. $K.app.message.show( { message: `${text}`, position: 'centered', type: 'is-error' });
  65. return;
  66. }
  67. function reset2()
  68. {
  69. // document.getElementById("a_type").value="";
  70. document.getElementById("a_description").value="";
  71. document.getElementById("a_amount").value="";
  72. setUploadField();
  73. }
  74. function addTableRow(){
  75. var $node = $K.dom('#tabbody');
  76. // create a new table row with id
  77. var element = document.createElement('tr');
  78. element.setAttribute("id", "trow"+currentRowId);
  79. /* var a_type = document.getElementById("a_type").value;
  80. if (!a_type.trim().length ) {
  81. document.getElementById("a_type").focus();
  82. showAlert("Bitte gib eine Auslagenart an!");
  83. return;
  84. }
  85. */
  86. var a_date = document.getElementById("a_date").value;
  87. if (!a_date.trim().length){
  88. document.getElementById("a_date").focus();
  89. showAlert("Bitte gib ein g&uuml;ltiges Datum an!");
  90. return;
  91. }
  92. var a_description = document.getElementById("a_description").value;
  93. if (!a_description.trim().length){
  94. document.getElementById("a_description").focus();
  95. showAlert("Bitte gib eine Beschreibung ein!");
  96. return;
  97. }
  98. var a_amount = document.getElementById("a_amount").value;
  99. if (!isFloat(a_amount)){
  100. document.getElementById("a_amount").focus();
  101. showAlert("Bitte gib einen g&uuml;ltigen Betrag ein!");
  102. return;
  103. }
  104. a_amount = parseFloat(a_amount).toFixed(2);
  105. var a_currency = document.getElementById("a_currency").value;
  106. /* if (!a_currency.trim().length){
  107. document.getElementById("a_currency").focus();
  108. showAlert("Bitte gib eine W&auml;hrung an!");
  109. return;
  110. }
  111. */
  112. var target = document.getElementById("upload-target"+currentRowId);
  113. var children = target.children;
  114. if (!children.length){
  115. // showAlert("Bitte lade mindestens einen Beleg hoch!");
  116. // return;
  117. }
  118. /* a_type = "Hello";*/
  119. var e="<td></td>";
  120. // add column for position no
  121. // e += `<td>${a_type}
  122. // <input type="hidden" name="type[${currentRowId}]" value="${a_type}" /></td>`;
  123. // add coluemn for a_type (Auslagenart)
  124. // e += `<td><textarea name="desc[${nextRowId}]" rows="2"></textarea> </td>`;
  125. e += `<td>${a_date}
  126. <input type="hidden" name="date[${currentRowId}]" value="${a_date}" /></td>`;
  127. // add column for date
  128. // e += `<td><input name="date[${nextRowId}]" type="date"/></td>`;
  129. e += `<td>${a_description}
  130. <input type="hidden" name="description[${currentRowId}]" value="${a_description}" /></td>`;
  131. // add column for num
  132. e += `<td>${a_amount} EUR
  133. <input type="hidden" name="amount[${currentRowId}]" value="${a_amount}" /></td>`;
  134. // add column for file upload
  135. /* e+= `
  136. <td data-kube="">
  137. <div class="form-item">
  138. <div class="upload"
  139. data-kube="upload"
  140. data-type="file" data-multiple="true"
  141. data-target="#upload-target${nextRowId}"
  142. data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
  143. data-progress="true">
  144. </div>
  145. <div id="upload-target${nextRowId}" class="upload-target"></div>
  146. </div>
  147. </td>
  148. */
  149. var ulfiles = children.length;
  150. e += `<td>${ulfiles}
  151. <input type="hidden" name="currency[${currentRowId}]" value="${a_currency}" /></td>
  152. </td>`;
  153. // `;
  154. // add delete bnutton
  155. e +=
  156. `<td><span
  157. onclick="deleteTableRow(${currentRowId})"
  158. class="close is-large">
  159. </span></td>`;
  160. $node.append(element);
  161. element.innerHTML=(e);
  162. renumberTableRows();
  163. currentRowId++;
  164. reset2();
  165. disableCurrency();
  166. }
  167. function setUploadField()
  168. {
  169. var e = $K.dom('#uploadfield');
  170. var uf =`<div class="upload"
  171. data-kube="upload"
  172. data-type="file" data-multiple="true"
  173. data-target="#upload-target${currentRowId}"
  174. data-url="upload.php?row=${currentRowId}" data-url-remove="delete.php"
  175. data-progress="true">Beleg hochladen
  176. </div>
  177. <div id="upload-target${currentRowId}" class="upload-target small"></div>
  178. </div>
  179. `;
  180. document.getElementById("uploadfield").innerHTML=uf;
  181. }
  182. $K.add('module', 'kaform', {
  183. init: function(app, context)
  184. {
  185. this.app = app;
  186. this.message = app.message;
  187. },
  188. // catch event
  189. onmessage: {
  190. tabs: {
  191. opened: function(sender)
  192. {
  193. console.log('Tab box is ',sender.getActiveBox().nodes[0]);
  194. banktype = sender.getActiveBox().nodes[0].attributes.id.value;
  195. console.log(banktype);
  196. // console.log(sender);
  197. // this.message.show({ message: 'My message' });
  198. }
  199. }
  200. },
  201. });
  202. $K.init({
  203. observer: true
  204. });
  205. // startup is here
  206. // on startup clear session on server
  207. $K.ajax.get({
  208. url: 'clear.php',
  209. data: '', // or key=value object
  210. before: function(xhr) {},
  211. success: function(response) {},
  212. error: function(response) {}
  213. });
  214. setUploadField();
  215. function check_field(fieldid,message){
  216. var f = document.getElementById(fieldid).value;
  217. if (! f.trim().length ) {
  218. document.getElementById(fieldid).focus();
  219. showAlert(message)
  220. return false;
  221. }
  222. return true;
  223. }
  224. // add on table row
  225. //addTableRow();
  226. //
  227. //
  228. //
  229. //
  230. function downloadDocument2(){
  231. downloadDocument(true);
  232. }
  233. function downloadDocument1(){
  234. downloadDocument(false);
  235. }
  236. function downloadDocument(mail)
  237. {
  238. /* if (!check_field("nickname", "Bitte gib deinen Nicknamen an!"))
  239. return;
  240. */ if (!check_field("realname", "Bitte gib deinen Realnamen an!"))
  241. return;
  242. if (!check_field("email", "Bitte gib deinen E-Mail-Adresse an!"))
  243. return;
  244. if (!check_field("projectid", "Bitte gib idie Projekt-ID an!"))
  245. return;
  246. if (countRows()==0){
  247. document.getElementById("a_description").focus();
  248. showAlert("Bitte f&uuml;ge mind. eine Auslage hinzu!");
  249. return;
  250. }
  251. if (banktype == "bank-eu"){
  252. iban = document.getElementById('iban');
  253. if (!IBAN.isValid(iban.value)){
  254. document.getElementById("iban").focus();
  255. showAlert("Bitte gib eine korrekte IBAN ein!");
  256. return;
  257. }
  258. /* if (!document.getElementById('bic').value.trim().length){
  259. document.getElementById("bic").focus();
  260. showAlert("Bitte gib einen korrekte BIC an!");
  261. return;
  262. }
  263. */
  264. }
  265. if (banktype == "bank-paypal"){
  266. ii = document.getElementById('paypal');
  267. if (!document.getElementById('paypal').value.trim().length){
  268. document.getElementById("paypal").focus();
  269. showAlert("Bitte gib einen PayPal Account an!");
  270. return;
  271. }
  272. }
  273. if (!document.getElementById("agree").checked){
  274. document.getElementById("agree").focus();
  275. showAlert("Bitte best&auml;tige, dass du alle Angaben nach bestem Wissen und Gewissen gemacht hast!");
  276. return;
  277. };
  278. if (mail){
  279. document.getElementById('sendmail').value="yes";
  280. }
  281. else{
  282. document.getElementById('sendmail').value="no";
  283. }
  284. document.getElementById('banktype').value=banktype;
  285. document.getElementById("theform").submit();
  286. }
  287. /*
  288. function checkIban()
  289. {
  290. iban = document.getElementById('iban');
  291. if(IBAN.isValid(iban.value))
  292. if( document.getElementById('eu').checked ) {
  293. if(IBAN.isValid(iban.value))
  294. {
  295. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  296. iban.classList.add('valid');
  297. }
  298. else {
  299. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  300. iban.classList.add('invalid');
  301. }
  302. } else {
  303. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  304. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  305. }
  306. }
  307. */