Bug 133883 No error msg when user tries to do replication when offline - provide notification and disable button when appropriate. r=neil.parkwaycc.co.uk,sr=bienvenu.

This commit is contained in:
bugzilla%standard8.demon.co.uk 2005-12-29 16:53:43 +00:00
parent e7b173262f
commit 6ae244fb31
6 changed files with 67 additions and 9 deletions

View File

@ -132,6 +132,8 @@ invalidName=Please enter a valid Name.
invalidHostname=Please enter a valid Hostname.
invalidPortNumber=Please enter a valid Port Number.
invalidResults=Please enter a valid number in the results field.
abReplicationOfflineWarning=You must be online to perform LDAP replication.
abReplicationSaveSettings=Settings must be saved before a directory may be downloaded.
# For importing / exporting
ExportAddressBookTitle=Export Address Book

View File

@ -70,7 +70,6 @@
<!ENTITY offlineText.label "You can download a local copy of this directory so that it is available for use when you are working offline.">
<!ENTITY downloadNowButton.label "Download Now">
<!ENTITY downloadNowButton.accesskey "D">
<!ENTITY downloadDisabledMsg.label "Settings must be saved before a directory may be downloaded.">
<!-- Localization note: this is here because the width of the dialog
is determined by the width of the base DN box; and that is likely
to vary somewhat with the language.

View File

@ -8,8 +8,20 @@ const kDefaultLDAPPort = 389;
const kDefaultSecureLDAPPort = 636;
const kLDAPDirectory = 0; // defined in nsDirPrefs.h
var ldapOfflineObserver = {
observe: function(subject, topic, state)
{
// sanity checks
if (topic != "network:offline-status-changed") return;
setDownloadOfflineOnlineState(state == "offline");
}
}
function Startup()
{
gPrefInt = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
if ( "arguments" in window && window.arguments[0] ) {
gCurrentDirectory = window.arguments[0].selectedDirectory;
gCurrentDirectoryString = window.arguments[0].selectedDirectoryString;
@ -19,8 +31,38 @@ function Startup()
dump("pref-directory-add.js:Startup(): fillSettings() exception: "
+ ex + "\n");
}
// Only set up the download button for online/offline status toggling
// if the pref isn't locked to disable the button.
if (!gPrefInt.prefIsLocked(gCurrentDirectoryString + ".disable_button_download")) {
// Now connect to the offline/online observer
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(ldapOfflineObserver,
"network:offline-status-changed", false);
// Now set the initial offline/online state.
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
// And update the state
setDownloadOfflineOnlineState(ioService.offline);
}
} else {
fillDefaultSettings();
// Don't add observer here as it doesn't make any sense.
}
}
function onUnload()
{
if ("arguments" in window &&
window.arguments[0] &&
!gPrefInt.prefIsLocked(gCurrentDirectoryString + ".disable_button_download")) {
// Remove the observer that we put in on dialog startup
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(ldapOfflineObserver,
"network:offline-status-changed");
}
}
@ -36,9 +78,6 @@ function DownloadNow()
//
function fillSettings()
{
gPrefInt = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var ldapUrl = Components.classes["@mozilla.org/network/ldap-url;1"];
ldapUrl = ldapUrl.createInstance().
QueryInterface(Components.interfaces.nsILDAPURL);
@ -135,7 +174,10 @@ function fillDefaultSettings()
// Disable the download button and add some text indicating why.
document.getElementById("download").disabled = true;
document.getElementById("downloadDisabledMsg").hidden = false;
document.getElementById("downloadWarningMsg").hidden = false;
document.getElementById("downloadWarningMsg").textContent = document.
getElementById("bundle_addressBook").
getString("abReplicationSaveSettings");
}
function hasOnlyWhitespaces(string)
@ -280,3 +322,18 @@ function doHelpButton()
{
openHelp("mail-ldap-properties");
}
// Sets the download button state for offline or online.
// This function should only be called for ldap edit dialogs.
function setDownloadOfflineOnlineState(isOffline)
{
if (isOffline)
{
// Disable the download button and add some text indicating why.
document.getElementById("downloadWarningMsg").textContent = document.
getElementById("bundle_addressBook").
getString("abReplicationOfflineWarning");
}
document.getElementById("downloadWarningMsg").hidden = !isOffline;
document.getElementById("download").disabled = isOffline;
}

View File

@ -48,6 +48,7 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="&newDirectoryTitle.label;"
onload="Startup();"
onunload="onUnload();"
buttons="accept,cancel,help"
ondialogaccept="return onAccept();"
ondialogcancel="return onCancel();"
@ -129,9 +130,7 @@
oncommand="DownloadNow();"/>
<spacer flex="1"/>
</hbox>
<description id="downloadDisabledMsg"
hidden="true"
class="error">&downloadDisabledMsg.label;</description>
<description id="downloadWarningMsg" hidden="true" class="error"/>
</vbox>
<grid>
<columns>

View File

@ -70,7 +70,6 @@
<!ENTITY offlineText.label "You can download a local copy of this directory so that it is available for use when you are working offline.">
<!ENTITY downloadNowButton.label "Download Now">
<!ENTITY downloadNowButton.accesskey "D">
<!ENTITY downloadDisabledMsg.label "Settings must be saved before a directory may be downloaded.">
<!-- Localization note: this is here because the width of the dialog
is determined by the width of the base DN box; and that is likely
to vary somewhat with the language.

View File

@ -133,6 +133,8 @@ invalidName=Please enter a valid Name.
invalidHostname=Please enter a valid Hostname.
invalidPortNumber=Please enter a valid Port Number.
invalidResults=Please enter a valid number in the results field.
abReplicationOfflineWarning=You must be online to perform LDAP replication.
abReplicationSaveSettings=Settings must be saved before a directory may be downloaded.
# For importing / exporting
ExportAddressBookTitle=Export Address Book