Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. function nuevo_elemento()
  2. {
  3. var display = $('input[name="eldi_display"]').val();
  4. var key = $('input[name="eldi_key"]').val();
  5. key = key.split(" ").join("_").toLowerCase();
  6.  
  7. swal({
  8. title: 'Añadir elemento',
  9. text: "¿Quieres añadir este elemento?",
  10. type: 'warning',
  11. showCancelButton: true,
  12. confirmButtonColor: '#3085d6',
  13. cancelButtonColor: '#d33',
  14. confirmButtonText: 'Sí',
  15. cancelButtonText: 'No'
  16. }).then((result) => {
  17. if (result.value) {
  18. $.ajax({
  19. type: "POST",
  20. /* dataType: "json", */
  21. url: $("#base_url").attr("valor") + "diccionarios/nuevo_elemento_diccionario",
  22. data: $("#formNuevoElementoDiccionario").serialize(),
  23.  
  24. success: function(data) {
  25. //Desaparece el modal
  26. $('#Modal_Add').modal('hide');
  27.  
  28. //Vaciado del form
  29. $("#formNuevoElementoDiccionario").trigger("reset");
  30.  
  31. //Añadido del nuevo elemento a la tabla
  32. var html =
  33. '<tr>'+
  34. '<td>' + key + '</td>' +
  35. '<td>'+ display +'</td>'+
  36. '<td>'+
  37. '<span class="btn btn-default editar_elemento" key=' + key + ' value="' + key + '">' +
  38. '<a href="'+$("#base_url").attr("valor") + "diccionarios/elemento_diccionario/"+key+'" title="Editar">' +
  39. '<i class="material-icons">edit</i>' +
  40. '</a>' +
  41. '</span>' +
  42. '</td>' +
  43. '<td>' +
  44. '<span class="btn btn-default borrar_elemento" id="'+ key +'" value="'+ key +'">'+
  45. '<i class="material-icons">delete_outline</i>'+
  46. '</span>'+
  47. '</td>'+
  48. '</tr>'
  49.  
  50. $('#tabla-diccionarios').append(html);
  51.  
  52. //Confirmación Swal
  53. swal("Añadido", "Elemento añadido correctamente", "success");
  54.  
  55. $(".borrar_elemento").off();
  56. $(".editar_elemento").off();
  57. evento_editar_elemento();
  58. evento_borrar_elemento();
  59. },
  60. error: function(XMLHttpRequest, textStatus, errorThrown) {
  61. console.log("Error: " + textStatus);
  62. }
  63. });
  64. }
  65. })
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement