This commit is contained in:
law%netscape.com 1999-04-06 19:34:47 +00:00
parent 1a0321217a
commit 79bade248e
2 changed files with 64 additions and 18 deletions

View File

@ -12,13 +12,14 @@
<broadcaster id="data.location" type="url" value="url"/> <broadcaster id="data.location" type="url" value="url"/>
<broadcaster id="data.contentType" type="string" value="content-type"/> <broadcaster id="data.contentType" type="string" value="content-type"/>
<broadcaster id="data.fileName" type="string" value=""/> <broadcaster id="data.fileName" type="string" value=""/>
<broadcaster id="data.progress" type="progress" value="0" max="0"/> <broadcaster id="data.progress" type="progress" value="0" max="0" completed="false"/>
<broadcaster id="data.status" type="string" value=""/> <broadcaster id="data.status" type="string" value=""/>
<broadcaster id="data.execute" command=""/> <broadcaster id="data.execute" command=""/>
</data> </data>
<dialog> <dialog>
<observes element="data.progress" attribute="value" onchange="onProgress()"/> <observes element="data.progress" attribute="value" onchange="onProgress()"/>
<observes element="data.progress" attribute="completed" onchange="onCompletion()"/>
</dialog> </dialog>
<html:script> <html:script>
@ -47,13 +48,15 @@
dialog.progress = document.getElementById("dialog.progress"); dialog.progress = document.getElementById("dialog.progress");
dialog.progressPercent = document.getElementById("dialog.progressPercent"); dialog.progressPercent = document.getElementById("dialog.progressPercent");
dialog.timeLeft = document.getElementById("dialog.timeLeft"); dialog.timeLeft = document.getElementById("dialog.timeLeft");
dialog.cancel = document.getElementById("dialog.cancel");
// Fill dialog. // Fill dialog.
loadDialog(); loadDialog();
} }
function cancel() { function stop() {
data.execute.setAttribute("command","cancel"); // Stop the download.
data.execute.setAttribute("command","stop");
} }
var started = false; var started = false;
@ -67,6 +70,8 @@
// Initialize download start time. // Initialize download start time.
started = true; started = true;
startTime = ( new Date() ).getTime(); startTime = ( new Date() ).getTime();
// Let the user stop, now.
dialog.cancel.removeAttribute( "disabled" );
} }
// Get stats. // Get stats.
var bytes = data.progress.getAttribute("value"); var bytes = data.progress.getAttribute("value");
@ -130,6 +135,10 @@
dialog.timeLeft.childNodes[0].nodeValue = status; dialog.timeLeft.childNodes[0].nodeValue = status;
} }
} }
function onCompletion() {
dialog.cancel.setAttribute( "disabled", "" );
}
</html:script> </html:script>
<html:table style="width:100%;"> <html:table style="width:100%;">
@ -186,7 +195,7 @@
<html:tr> <html:tr>
<html:td align="center" colspan="2"> <html:td align="center" colspan="2">
<html:button onclick="cancel()">Cancel</html:button> <html:button id="dialog.cancel" onclick="stop()" disabled>Cancel</html:button>
</html:td> </html:td>
</html:tr> </html:tr>

View File

@ -18,35 +18,72 @@
var data; var data;
var dialog; var dialog;
function initData() {
// Create data object and initialize.
data = new Object;
data.location = document.getElementById("data.location");
data.contentType = document.getElementById("data.contentType");
data.fileName = document.getElementById("data.fileName");
data.execute = document.getElementById("data.execute");
}
function initDialog() {
// Create dialog object and initialize.
dialog = new Object;
dialog.location = document.getElementById("dialog.location");
dialog.contentType = document.getElementById("dialog.contentType");
dialog.fileName = document.getElementById("dialog.fileName");
dialog.ok = document.getElementById("dialog.ok");
dialog.enabled = false;
}
function loadDialog() { function loadDialog() {
// Set initial dialog field contents.
dialog.location.setAttribute( "value", data.location.getAttribute( "value" ) ); dialog.location.setAttribute( "value", data.location.getAttribute( "value" ) );
dialog.contentType.setAttribute( "value", data.contentType.getAttribute( "value" ) ); dialog.contentType.setAttribute( "value", data.contentType.getAttribute( "value" ) );
dialog.fileName.setAttribute( "value", data.fileName.getAttribute( "value" ) ); dialog.fileName.setAttribute( "value", data.fileName.getAttribute( "value" ) );
} }
function onLoad() { function onLoad() {
// Set global variables. // Init data.
data = new Object; initData();
data.location = document.getElementById("data.location");
data.contentType = document.getElementById("data.contentType"); // Init dialog.
data.fileName = document.getElementById("data.fileName"); initDialog();
data.execute = document.getElementById("data.execute");
dialog = new Object;
dialog.location = document.getElementById("dialog.location");
dialog.contentType = document.getElementById("dialog.contentType");
dialog.fileName = document.getElementById("dialog.fileName");
// Fill dialog. // Fill dialog.
loadDialog(); loadDialog();
} }
function ok() { function ok() {
// Proceed with download into target filename.
data.execute.setAttribute("filename", dialog.fileName.value ); data.execute.setAttribute("filename", dialog.fileName.value );
data.execute.setAttribute("command","ok"); data.execute.setAttribute("command","ok");
} }
function cancel() { function cancel() {
data.execute.setAttribute("command","cancel"); // Close the window.
data.execute.setAttribute("command","close");
}
function onTyping( key ) {
if ( key == 13 && dialog.enabled ) {
ok();
} else {
if ( dialog.enabled ) {
// Disable OK if they delete all the text.
if ( dialog.fileName.value == "" ) {
dialog.enabled = false;
dialog.ok.setAttribute( "disabled", "" );
}
} else {
// Enable OK once the user types something.
if ( dialog.fileName.value != "" ) {
dialog.enabled = true;
dialog.ok.removeAttribute( "disabled" );
}
}
}
} }
</html:script> </html:script>
@ -74,14 +111,14 @@
Enter file name: Enter file name:
</html:td> </html:td>
<html:td align="left"> <html:td align="left">
<html:input id="dialog.fileName" value="" style="width:300px;"/> <html:input id="dialog.fileName" value="" style="width:300px;" onkeyup="onTyping(event.which)"/>
</html:td> </html:td>
</html:tr> </html:tr>
<html:tr> <html:tr>
<html:td align="center" colspan="2"> <html:td align="center" colspan="2">
<html:button onclick="ok()">Ok</html:button> <html:button id="dialog.ok" onclick="ok()" disabled>OK</html:button>
<html:button onclick="cancel()">Cancel</html:button> <html:button onclick="cancel()" disabled>Cancel</html:button>
</html:td> </html:td>
</html:tr> </html:tr>
</html:table> </html:table>