Recently, I've been exploring this particular function snippet:
function add_cnh(arr_clelem){
var id=arr_clelem.getElementsByClassName("present")[0].id;
var date=arr_clelem.getElementsByClassName("present")[0].getAttribute('date');
var tt_entry= arr_clelem.getElementsByClassName("present")[0].getAttribute('tt_entry');
//new Ajax.Updater('register', '/some_url', { method: 'get' });
new Ajax.Request('/attendances/new',
{
parameters:'id='+id+'&date='+date+'&timetable_entry='+tt_entry+'&subject_id='+subject_id,
asynchronous:true,
evalScripts:true,
method:'get'
/*onSuccess: function(transport) {
var response = transport.responseText || "no response text";
alert("Success! \n\n" + response);
}*/
}
)
var ret=modal_data;
// $$('.MB_close').invoke('observe', 'click', _deinit);
return ret;
}
This unique function works by taking html-elements-object as an argument and ultimately rendering a modal-box. The modal box contains form elements that need to be stored inside an array. Interestingly, the variable modal_data holds the necessary elements and is defined globally in another file.
An issue I'm encountering pertains to the outdated nature of the project. The various JavaScript frameworks and libraries utilized date back to 2006, with even the library responsible for opening the modal box being deprecated as evidenced here.
To address this challenge without delving into server-side solutions, I've resorted to employing a for loop strategy:
for(var i=0; i<arr_of_elements.length, i++)
{
my_arrvar[i]=add_cnh(arr_of_elements[i]);
}
Throughout each iteration, my goal is to close the modal box and store the data within 'my_arrvar'. However, the asynchronous nature of the call has posed obstacles despite attempts using closures and callbacks. Avoiding timer usage, the process revolves around calling the function, retrieving data for each call, and removing the modal box by ID.
Additionally, I am curious if leveraging this technique could offer a solution, and if so, how?