Guest User

Untitled

a guest
Nov 20th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. @RequestMapping(value = "/fisicHost/{id}/credentials", method = RequestMethod.GET, produces = APPLICATION_JSON_UTF8_VALUE)
  2. public List<Credential> credentialsByFisicHost(@PathVariable(value = "id") final Long fisicHostId, ModelMap modelMap){
  3. FisicHost optionalFisicHost = fisicHostDao.findById(fisicHostId);
  4.  
  5. if (optionalFisicHost == null) {
  6. // Responder con 404
  7. }
  8. FisicHost fisicHost = optionalFisicHost;
  9. return fisicHost.getCredentials();
  10. }
  11.  
  12. <!-- Modal -->
  13. <div class="modal fade" id="credentialsModal" tabindex="-1" role="dialog" aria-hidden="true">
  14. <div class="modal-dialog modal-dialog-centered" role="document">
  15. <div class="modal-content">
  16. <div class="modal-header">
  17. <h5 class="modal-title" id="modal-title">Credenciales</h5>
  18. </div>
  19. <div class="modal-body">
  20. <table id="credentialsTable">
  21. <tr class="row">
  22. <th id="modal-user">Usuario</th>
  23. <th id="modal-pass">Clave</th>
  24. <th id="modal-notes">Notas</th>
  25. </tr>
  26. </table>
  27. </div>
  28. <div class="modal-footer">
  29. <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34.  
  35. $(".credentialsButton").click(function(){
  36.  
  37. var fisicHostId = $(this).data('fisic-host-id');
  38. $.get( "/fisicHost/" + fisicHostId + "/credentials", data => {
  39. console.log(data);
  40.  
  41. $('#credentialsTable').empty();
  42.  
  43. // var user = document.createElement('th');
  44. // user.textContent = "USUARIO";
  45.  
  46. for (i = 0; i < data.length; ++i) {
  47. var fisicHost = data[i];
  48.  
  49. var new_row = document.createElement('tr');
  50. new_row.className = "row fisichost";
  51.  
  52. var userCol = document.createElement('td');
  53. userCol.textContent = fisicHost["user"];
  54. new_row.append(userCol);
  55.  
  56. var passwordCol = document.createElement('td');
  57. passwordCol.textContent = fisicHost["password"];
  58. new_row.append(passwordCol);
  59.  
  60. var notesCol = document.createElement('td');
  61. notesCol.textContent = fisicHost["notes"];
  62. new_row.append(notesCol);
  63.  
  64. var editButton = document.createElement('button');
  65. editButton.textContent = "EDITAR"
  66. new_row.append(editButton);
  67.  
  68. var deleteButton = document.createElement('button');
  69. deleteButton.id = buttonId;
  70. deleteButton.textContent = "BORRAR"
  71. new_row.append(deleteButton);
  72.  
  73. $("#credentialsTable").append(new_row);
  74.  
  75. // ACA ESTA EL TEMA
  76.  
  77. $(deleteButton).on('click', () => {
  78. var credentialId = fisicHost["id"];
  79. console.log(credentialId);
  80. // $.post( "/fisicHost/" + credentialId + "/credentials", data => {});
  81. });
  82. }
  83.  
  84. $('#credentialsModal').modal('show');
  85.  
  86. }).fail(function(xhr, status, error) {
  87. console.error(error);
  88. alert('No se pudieron cargar las credenciales.');
  89. });
  90. });
  91.  
  92. $('#credentialsModal').bind('hide', function () {
  93. $('#credentialsModal tr.fisichost').remove();
  94. });
  95.  
  96. […]
  97. 0: {…}
  98. id: 2
  99. notes: "notas"
  100. password: "pass"
  101. role: "null"
  102. user: "usuario"
  103. __proto__: Object { … }
  104. 1: {…}
  105. id: 3
  106. notes: "notasssss"
  107. password: "pass"
  108. role: "null"
  109. user: "usuario"
  110. __proto__: Object { … }
  111. length: 2
Add Comment
Please, Sign In to add comment