Confirm before making the change

-1

When I change the event in the calendar, before changing ask to confirm: the code:

function edit(event){
            start = event.start.format('YYYY-MM-DD HH:mm:ss');
            if(event.end){
                end = event.end.format('YYYY-MM-DD HH:mm:ss');
            }else{
                end = start;
            }

            id =  event.id;

            Event = [];
            Event[0] = id;
            Event[1] = start;
            Event[2] = end;

            $.ajax({
             url: './updatehoradataeventoLar',
             type: "POST",
             data: {Event:Event},
             success: function(rep) {
                    if(rep == 'OK'){
                        alert('Atividade Guardada correctamente');
                    }else{
                        alert('Tente novamente!'); 
                    }
                }
            });
        }

In this way, just alert that the activity has been saved correctly, but before this alert appears, I want it to appear asking if you want to change the event, otherwise, if it changes, it is not.

The answers to this question did not help me solve my question, because in my case, when I make the change it is by dragging the already marked event and I have no button or link to add the onclick and intended to do the same within sucess of ajax

    
asked by anonymous 10.09.2018 / 12:55

1 answer

2

Use the confirm(mensagem) function to see if the user has confirmed the edit action:

function edit(event){
    if(confirm('Confirma a alteração dos dados?')) {
        start = event.start.format('YYYY-MM-DD HH:mm:ss');
        if(event.end){
            end = event.end.format('YYYY-MM-DD HH:mm:ss');
        }else{
            end = start;
        }

        id =  event.id;

        Event = [];
        Event[0] = id;
        Event[1] = start;
        Event[2] = end;

        $.ajax({
         url: './updatehoradataeventoLar',
         type: "POST",
         data: {Event:Event},
         success: function(rep) {
                if(rep == 'OK'){
                    alert('Atividade Guardada correctamente');
                }else{
                    alert('Tente novamente!'); 
                }
            }
        });
  }
}
    
10.09.2018 / 13:38