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

View File

@ -18,35 +18,72 @@
var data;
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() {
// Set initial dialog field contents.
dialog.location.setAttribute( "value", data.location.getAttribute( "value" ) );
dialog.contentType.setAttribute( "value", data.contentType.getAttribute( "value" ) );
dialog.fileName.setAttribute( "value", data.fileName.getAttribute( "value" ) );
}
function onLoad() {
// Set global variables.
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");
dialog = new Object;
dialog.location = document.getElementById("dialog.location");
dialog.contentType = document.getElementById("dialog.contentType");
dialog.fileName = document.getElementById("dialog.fileName");
// Init data.
initData();
// Init dialog.
initDialog();
// Fill dialog.
loadDialog();
}
function ok() {
// Proceed with download into target filename.
data.execute.setAttribute("filename", dialog.fileName.value );
data.execute.setAttribute("command","ok");
}
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>
@ -74,14 +111,14 @@
Enter file name:
</html:td>
<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:tr>
<html:tr>
<html:td align="center" colspan="2">
<html:button onclick="ok()">Ok</html:button>
<html:button onclick="cancel()">Cancel</html:button>
<html:button id="dialog.ok" onclick="ok()" disabled>OK</html:button>
<html:button onclick="cancel()" disabled>Cancel</html:button>
</html:td>
</html:tr>
</html:table>