search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to use password for event creation ,resizing and moving

Asked by Vincas
1 year ago.

Hi,
I try to force users to enter password for creating, resizing and moving an event like this:

dp.onEventResize = function (args) {
$.getJSON("ps.php?id=" + args.e.id(), function(data) {
var psw = prompt("Enter password:");
if (psw != data.ps) { args.preventDefault(); }

});
};

or:

dp.onEventResize = function (args) {
$.ajax({
url: "ps.php?id=" + args.e.id(),

}) .done(function( data ) {
var psw = prompt("Enter password:");
if (psw != data.ps) { args.preventDefault(); }
});
};

but it seems that args.preventDefault() doesn't work. Any ideas?

Answer posted by Dan Letecky [DayPilot]
1 year ago.

The preventDefault() method needs to be called in the main context (before the onEventResize handler exits). You are calling it in the callback method which is called later and it has no effect.

The Pro version uses args.async to support asynchronous callbacks:

dp.onEventResize = function(args) {
  args.async = true;
  dp.message("Checking....");

  $.ajax({
      url: "asyncvalidation.txt",
      method: "GET",
      data: {
          dateFrom: args.newStart.toString(),
          dateTo: args.newEnd.toString(),
          id: args.e.id()
      }
  }).done(function (response) {
      var $response = $.parseJSON(response);

      if ($response.error) {
          dp.message($response.message);
          args.preventDefault();
      }
      args.loaded();
  });
};

In the Lite version you need to cancel the default action right away and perform it manually when the condition is met:

dp.onEventResize = function (args) { 
  args.preventDefault();
  $.getJSON("ps.php?id=" + args.e.id(), function(data) { 
    var ok = checkCondition();
    if (ok) {  
      e.start(args.newStart);
      e.end(args.newEnd);
      dp.events.update(args.e);
    }
  }); 
};

I assume the password reading code is just for demonstration purposes because it isn't secure at all.

Comment posted by Vincas
1 year ago.

Thanks, it worked, but another problem appeared - in the Lite version after event creation or deletion page doesn't
refresh properly. It is necessary to manually refresh the page to see the result::

dp.onEventDelete = function (args) {
args.preventDefault();
$.getJSON("ps.php?id=" + args.e.id(), function(data) {
var psw = prompt("Enter password:");

if(psw == data.ps)
{
$.post("mbackend_delete.php",
{
id: args.e.id()
},
function() {
console.log("Deleted.");
});

//window.location.reload(true); ????
//loadEvents(); ???
} else alert("Bad password!");

});

};

Comment posted by Vincas
1 year ago.

I solved my problem adding this code instead of commented code:

var seld = nav.selectionDay;
nav.select(nav.visibleStart());
nav.select(nav.visibleEnd());
nav.select(seld);

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.