I have a long, procedural (looping) import, and from what I’ve concluded in various threads here there seems to be no way to use a thermo bar to indicate progress on the web.
To compensate, I have a dialog that appears every specified numbers of lines read from the import text file, showing total lines read and time elapsed. However, it requires a user to manually press the “Continue” button.
To semi-automate the process, I tried a self-closing dialog. I am using the onShow method for the dialog to start a timer process, to automatically dismiss the dialog. However, when I did this, the dialog didn’t appear at all.
function onShow_confirm_dialog(firstShow, event) {
elements.btn_ok.requestFocus();
selfCloseContinue();
}
function selfCloseContinue() {
var startTime = new Date().getTime(); // time in milliseconds
var currTime = new Date().getTime();
var loop_CT = 0;
var abort_B = false;
while (abort_B == false) {
loop_CT += 1;
currTime = new Date().getTime();
if(((currTime - startTime)/1000 > 5) || (loop_CT > 10000)) {
abort_B = true;
}
}
globals.saveDialog_b = true;
application.closeForm();
Is there a way that this can work, so that if the user isn’t there to close the dialog, it will close itself
Can you explain a bit more what you mean? I’m a novice, I haven’t even looked into the headless client. From the wiki, I assume it’s like spawning an independent process?
If this is the case, wouldn’t the callback come only after the operation is complete, as opposed to stopping every few thousand lines of the import, to allow for progress updates and user cancel?
Yes you are right, the callback will fire only when the method in de headless client is finished, but you can show an animated gif or something, its not a progress, but at least it is something
That defeats the purpose of the dialog. If it’s a 40-mb import, it’s going to take too much time – the user will think that the program has frozen, even after, say 3-5 minutes, unless I can provide some progress feedback.
I figured a way around this. It’s not elegant, but so far it seems to work.
In the setup dialog, before the import starts, I give the user the option of having progress dialogs at a specified number of lines read. The default value is 2,000 lines.
When the import routine crosses the 2,000-line threshold, it calculates the fraction complete of the import as (originalText.length-remainingText.length)/originalText.length). It then opens the progress dialog.
The progress dialog now contains 30 small rectangles that can be shown/hidden to simulate a thermo progress bar (based on the fraction complete calculated in #2).
In the onShow, the progress dialog uses the scheduler to set a short timer for automatically closing the dialog, should the user not intervene:
function onShow_confirm_dialog(firstShow, event) {
elements.btn_ok.requestFocus();
// add a job that runs at the given date (8 seconds in the future)
// and repeats that every 50 seconds for 0 times or until the endDate is reached (0 for no repeats = just one call)
var startDate = new Date();
startDate.setTime(startDate.getTime() + (4*1000)); // 4 seconds in future
var endDate = new Date(startDate.getTime() + (100*1000)); // not really using this
plugins.scheduler.addJob('in8seconds', startDate, selfCloseContinue, (50*1000), 0, endDate); // not really using repeat interval (50*1000), one time only
}
After the dialog closes itself, the import resumes. As long as the delay time is relatively short until self-close (maybe 3-5 seconds), it doesn’t impact the overall duration of the import, at least for this type of import.
The interesting thing about this approach is that the progress dialog remains on the screen. Even though it is supposed to go away at each dismissal, it doesn’t get redrawn, and the effect is similar to having an actual progress thermometer on the screen.