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
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
  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(error_alert_date);
  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(error_alert_description);
  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(error_alert_sum);
  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="` + expenses_table_file_placeholder + `">
  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="` + expenses_table_description_placeholder + `"/>`
  131. + "</td>"
  132. + "<td data-label=\"Betrag\">"
  133. + `<input class="tab_input" name="amount[${rid}] type="text" placeholder="0.00"/>`
  134. + "</td>"
  135. + "<td data-label=\"W&auml;hrung\" 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. lang: 'en'
  189. });
  190. // startup is here
  191. // on startup clear session on server
  192. $K.ajax.get({
  193. url: 'clear.php',
  194. data: '', // or key=value object
  195. before: function(xhr) {},
  196. success: function(response) {},
  197. error: function(response) {}
  198. });
  199. function check_field(fieldid,message){
  200. var f = document.getElementById(fieldid).value;
  201. if (! f.trim().length ) {
  202. document.getElementById(fieldid).focus();
  203. showAlert(message)
  204. return false;
  205. }
  206. return true;
  207. }
  208. // add on table row
  209. //addTableRow();
  210. //
  211. //
  212. //
  213. //
  214. function downloadDocument2(){
  215. downloadDocument(true);
  216. }
  217. function downloadDocument1(){
  218. downloadDocument(false);
  219. }
  220. function downloadDocument(mail)
  221. {
  222. if (!checkAllRows())
  223. return;
  224. if (!check_field("projectid", error_alert_projectid))
  225. return;
  226. if (!check_field("realname", error_alert_realname))
  227. return;
  228. if (!check_field("email", error_alert_email))
  229. return;
  230. if (banktype == "bank-eu"){
  231. iban = document.getElementById('iban');
  232. if (!IBAN.isValid(iban.value)){
  233. document.getElementById("iban").focus();
  234. showAlert(error_alert_iban);
  235. return;
  236. }
  237. /* if (!document.getElementById('bic').value.trim().length){
  238. document.getElementById("bic").focus();
  239. showAlert(error_alert_bic);
  240. return;
  241. }
  242. */
  243. }
  244. if (banktype == "bank-paypal"){
  245. ii = document.getElementById('paypal');
  246. if (!document.getElementById('paypal').value.trim().length){
  247. document.getElementById("paypal").focus();
  248. showAlert(error_alert_paypal);
  249. return;
  250. }
  251. }
  252. if (countRows()==0){
  253. document.getElementById("add_issue").focus();
  254. showAlert(error_alert_expenses);
  255. return;
  256. }
  257. if (!document.getElementById("agree").checked){
  258. document.getElementById("agree").focus();
  259. showAlert(error_alert_agreement);
  260. return;
  261. };
  262. if (mail){
  263. if (!isMailable()){
  264. showAlert(error_alert_ismailable);
  265. return;
  266. }
  267. document.getElementById('sendmail').value="yes";
  268. }
  269. else{
  270. document.getElementById('sendmail').value="no";
  271. }
  272. document.getElementById('banktype').value=banktype;
  273. document.getElementById("theform").submit();
  274. }
  275. /*
  276. function checkIban()
  277. {
  278. iban = document.getElementById('iban');
  279. if(IBAN.isValid(iban.value))
  280. if( document.getElementById('eu').checked ) {
  281. if(IBAN.isValid(iban.value))
  282. {
  283. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  284. iban.classList.add('valid');
  285. }
  286. else {
  287. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  288. iban.classList.add('invalid');
  289. }
  290. } else {
  291. if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
  292. if(iban.classList.contains('valid')) iban.classList.remove('valid');
  293. }
  294. }
  295. */