I'm experiencing quire a nasty problem. Here it goes:
My script uploads file(s) and responds back with a JSON encoded object, which contains file ID numbers that need additional information.
Now, the problem. I'd like to display a dialog (a form) and wait for user to fill it, send it via AJAX back to server, and then repeat the same process for the second ID number, and so on.
I tried to do this using $.each, but unsuccessfully. I read $.each can be terminated by returning false in callback function, but I did not find anything mentioning how to wait for an event (let's say submit button in my form to be clicked) and then continuing the loop.
Nice day
Solution:
coll_id = 0; // collection pointer
collection = [
{
id : 4,
fileName : 'somefile.mp3'
},
{
id : 6,
fileName : 'anotherFile.mp3'
}
];
function openDialog(){
$('#browser-add-files-id3').bind('dialogclose', function(){
if(coll_id >= collection.length-1){
try{
closeDialog(collection[coll_id].id);
}
catch(err){
}
coll_id++;
}
else {
closeDialog(collection[coll_id].id);
coll_id++;
openDialog();
}
});
$('#id3-file').text(collection[coll_id].fileName);
$('#browser-add-files-id3').dialog('open');
}
function closeDialog(mid){
// $.post to /url/param/mid
// cleanup the input fileds in dialog
}