Soft Edit
Soft Edit
Hi,
Is there an example somewhere of soft editing (as opposed to soft delete)?
I want to send the new data, check if it matches the data already in MySQL, and if it doesn't, ask "Do you want to change --old value-- to --newvalue--"?
I'm using postSubmit, but the data returned is already the new edited data, so it doesn't work.
Here's some code I wrote, but it doesn't work since it's comparing the newly entered data to itself.
editor.on('postSubmit',function(a,dataReturned,dataSent,editorAction,xhr){
console.log("Just submitted editor. Should compare now if you created or edited.");
console.log(a,dataReturned,dataSent,editorAction,xhr);
if(editorAction === "edit" || editorAction === "create") {
consumerInfo = Object.values(dataSent.data)[0].consumers;
var sortObject = function(unordered) {
var ordered = {};
Object.keys(unordered).sort().forEach(function(key) {
ordered[key] = unordered[key];
});
return ordered;
}
var orderSent = sortObject(Object.values(dataSent.data)[0].consumers);
var orderReturned = sortObject(Object.values(dataReturned.data[0])[2]);
console.log("comparing consumer info.");
Object.keys(orderSent).forEach(key => {
// keys don't match. Should we keep the new key or put the old key back?
if(!confirm("Do you want to change the value of " + key + " from '" + orderReturned[key] + "' to '" + orderSent[key] + "'?")) {
consumerInfo[key] = orderReturned[key];
}
})
}
});
This question has an accepted answers - jump to answer
Answers
Ask and you shall receive - yes, here is a soft delete example.
Allan
Sorry - I might have got the wrong end of the stick reading over this again!
preSubmit
is the way to do this - have it make an Ajax request to the server with the data that will be written and return aPromise
from the event handler. That will cause Editor to pause its execution until the promise has been resolved. Once it had, you can either cancel the submission or allow it to continue.The other way to do a soft edit is with an append only database, which might be of some interest?
Regards,
Allan