Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nuevo_elemento()
- {
- var display = $('input[name="eldi_display"]').val();
- var key = $('input[name="eldi_key"]').val();
- key = key.split(" ").join("_").toLowerCase();
- swal({
- title: 'Añadir elemento',
- text: "¿Quieres añadir este elemento?",
- type: 'warning',
- showCancelButton: true,
- confirmButtonColor: '#3085d6',
- cancelButtonColor: '#d33',
- confirmButtonText: 'Sí',
- cancelButtonText: 'No'
- }).then((result) => {
- if (result.value) {
- $.ajax({
- type: "POST",
- /* dataType: "json", */
- url: $("#base_url").attr("valor") + "diccionarios/nuevo_elemento_diccionario",
- data: $("#formNuevoElementoDiccionario").serialize(),
- success: function(data) {
- //Desaparece el modal
- $('#Modal_Add').modal('hide');
- //Vaciado del form
- $("#formNuevoElementoDiccionario").trigger("reset");
- //Añadido del nuevo elemento a la tabla
- var html =
- '<tr>'+
- '<td>' + key + '</td>' +
- '<td>'+ display +'</td>'+
- '<td>'+
- '<span class="btn btn-default editar_elemento" key=' + key + ' value="' + key + '">' +
- '<a href="'+$("#base_url").attr("valor") + "diccionarios/elemento_diccionario/"+key+'" title="Editar">' +
- '<i class="material-icons">edit</i>' +
- '</a>' +
- '</span>' +
- '</td>' +
- '<td>' +
- '<span class="btn btn-default borrar_elemento" id="'+ key +'" value="'+ key +'">'+
- '<i class="material-icons">delete_outline</i>'+
- '</span>'+
- '</td>'+
- '</tr>'
- $('#tabla-diccionarios').append(html);
- //Confirmación Swal
- swal("Añadido", "Elemento añadido correctamente", "success");
- $(".borrar_elemento").off();
- $(".editar_elemento").off();
- evento_editar_elemento();
- evento_borrar_elemento();
- },
- error: function(XMLHttpRequest, textStatus, errorThrown) {
- console.log("Error: " + textStatus);
- }
- });
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement