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.

129 lines
2.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. var nextRowId=1;
  2. function renumberTableRows(){
  3. var row_no=1;
  4. var table = document.getElementById("tabbody");
  5. for (var i = 0, row; row = table.rows[i]; i++) {
  6. row.cells[0].innerHTML=row_no++;
  7. }
  8. }
  9. function deleteTableRow(rowId){
  10. var target = document.getElementById("upload-target"+rowId);
  11. var children = target.children;
  12. // delete all uploaded elements
  13. for (var i = 0; i < children.length; i++) {
  14. var tmp = children[i].getAttribute("data-id");
  15. $K.ajax.post({
  16. url: 'delete.php',
  17. data: 'id='+tmp,
  18. before: function(xhr) {},
  19. success: function(response) {},
  20. error: function(response) {}
  21. });
  22. }
  23. // delete the row from table
  24. var element = document.getElementById("trow"+rowId);
  25. element.parentNode.removeChild(element);
  26. renumberTableRows();
  27. // alert(rowId);
  28. }
  29. function addTableRow(){
  30. var $node = $K.dom('#tabbody');
  31. // create a new table row with id
  32. var element = document.createElement('tr');
  33. element.setAttribute("id", "trow"+nextRowId);
  34. var e="";
  35. // add column for position no
  36. e += '<td></td>';
  37. // add coluemn for description
  38. e += `<td><textarea name="desc[${nextRowId}]" rows="2"></textarea> </td>`;
  39. // add column for date
  40. e += `<td><input name="date[${nextRowId}]" type="date"/></td>`;
  41. // add column for num
  42. e += `<td><input name="amount[${nextRowId}]" type="num"/></td>`;
  43. // add column for file upload
  44. e+= `
  45. <td data-kube="">
  46. <div class="form-item">
  47. <div class="upload"
  48. data-kube="upload"
  49. data-type="file" data-multiple="true"
  50. data-target="#upload-target${nextRowId}"
  51. data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
  52. data-progress="true">
  53. </div>
  54. <div id="upload-target${nextRowId}" class="upload-target"></div>
  55. </div>
  56. </td>
  57. `;
  58. // add delete bnutton
  59. e +=
  60. `<td><span
  61. onclick="deleteTableRow(${nextRowId})"
  62. class="close is-large">
  63. </span></td>`;
  64. $node.append(element);
  65. element.innerHTML=(e);
  66. renumberTableRows();
  67. nextRowId++;
  68. }
  69. $K.add('module', 'kaform', {
  70. init: function(app, context)
  71. {
  72. this.app = app;
  73. },
  74. // catch event
  75. onmessage: {
  76. tabs: {
  77. opened: function(sender)
  78. {
  79. console.log('Tab box is ',sender.getActiveBox());
  80. }
  81. }
  82. },
  83. });
  84. $K.init({
  85. observer: true
  86. });
  87. // startup is here
  88. // on startup clear session on server
  89. $K.ajax.get({
  90. url: 'clear.php',
  91. data: '', // or key=value object
  92. before: function(xhr) {},
  93. success: function(response) {},
  94. error: function(response) {}
  95. });
  96. // add on table row
  97. //addTableRow();