I'm sorry, I'm a bit unclear.
Just like you have stickywin.confirm I have dialog.confirm. My dialog
class is a more simple stickywin variant I am already using. I don't
use native object or method names that cause problems.
My question is if I can have one callback function that is passed into
dialog.confirm with arguments and that one of those arguments change
depending on the button that is clicked in the dialog.
I tried some ways, didn't succeed and now I have both callbackOk and
callbackCancel arguments in my dialog.confirm method. callbackOk is
called when the 'confirm' event fires, callbackCancel when the 'close'
event fires.
I need callback functionality on both buttons because I have to
continue with my queue; maybe there are more confirms waiting in line
to be processed.
Similar like your stickywin.confirm I call my dialog.confirm like this
(where options are title, message, etc.):
dialog.confirm = function(options, callbackOk, callbackCancel) {
return new dialog(options).addEvents({
confirm: callbackOk,
cancel: callbackCancel
});
}
In my fileManager class I could request one like this for example:
var options = {
title: 'Delete file'
message: 'Are you sure...'
delay: 400,
...
}
dialog.confirm(options, this.deleteFileConfirmCallback.pass([true,
file], this), this.deleteFileConfirmCallback.pass([false, file],
this));
My deleteFileConfirmCallback method deletes the file or not (depending
on the dialog.confirm result) and then tells the queue to do the next
one in line (of there is one):
deleteFileConfirmCallback: function(confirmDelete, file) {
if(!$defined(confirmDelete)) confirmDelete = false;
if($defined(file) && confirmDelete) this.deleteFile(file);
this.queue.nextInLinePlease(); //This is one executed always
}
If I look at my code I think: can't I use just one callback and
(depending on the event firing of "confirm" or "close") return the 1st
argument true or false including the passed file argument?
Follow me? I would then just pass in the file element argument into
the dialog.confirm callback function call. The dialog.confirm calls my
callback with the original argument passed in, including a true/false
depending on the confirm/close firing.
I could then also create an extra "apply to all coming confirm.dialogs
waiting in the queue" checkbox in the dialog.confirm and return an
"applyToAll true/false" value in the callback as well.
Summarized: can you pass in argument(s) in a callback function, and
then execute the callback with those original arguments and on top of
that some extra arguments.
Something like:
dialog.confirm = function(options, callback) {
return new dialog(options).addEvents({
confirm: callback.pass(originalArgument, andMore, andOneMore),
cancel: callback.pass(originalArguments, andHereisOneExtra)
});
}
Pff, excusez more for all this text.