From 756a6c22bbed654423bb4976e95968cff4fee49d Mon Sep 17 00:00:00 2001
From: Einar Egilsson
Date: Wed, 7 Oct 2009 12:54:34 +0000
Subject: Prompt before delete, disable edit and delete buttons properly. Use
checkboxes for setting enabled/disabled status of redirects.
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@255 119bf307-c92d-0410-89bd-8f53e6181181
---
chrome/content/code/redirectList.xul.js | 49 +++++++++++++++++--------------
chrome/content/ui/editRedirect.xul | 5 +++-
chrome/content/ui/redirectList.xul | 11 ++++---
chrome/locale/en-US/redirectList.xul.dtd | 1 +
chrome/locale/en-US/redirector.properties | 4 +--
5 files changed, 41 insertions(+), 29 deletions(-)
diff --git a/chrome/content/code/redirectList.xul.js b/chrome/content/code/redirectList.xul.js
index c7ebcd7..81dd4a4 100644
--- a/chrome/content/code/redirectList.xul.js
+++ b/chrome/content/code/redirectList.xul.js
@@ -9,7 +9,6 @@ var RedirectList = {
lstRedirects: null,
btnDelete : null,
btnEdit : null,
- btnDisable : null,
addItemsToListBox : function(items) {
@@ -21,10 +20,24 @@ var RedirectList = {
newItem.getElementsByAttribute('name', 'dscrIncludePattern')[0].setAttribute('value', item.includePattern);
newItem.getElementsByAttribute('name', 'dscrExcludePattern')[0].setAttribute('value', item.excludePattern);
newItem.getElementsByAttribute('name', 'dscrRedirectTo')[0].setAttribute('value', item.redirectUrl);
+ var checkEnabled = newItem.getElementsByAttribute('name', 'chkEnabled')[0];
+ checkEnabled.setAttribute('checked', !item.disabled);
newItem.item = item;
this.lstRedirects.appendChild(newItem);
newItem.setAttribute('selected', false);
}
+
+ //Enable, disable functionality
+ this.lstRedirects.addEventListener('click', function(ev) {
+ if (ev.originalTarget && ev.originalTarget.tagName == 'checkbox') {
+ var parent = ev.originalTarget.parentNode;
+ while (!parent.item) {
+ parent = parent.parentNode;
+ }
+ parent.item.disabled = !ev.originalTarget.hasAttribute('checked');
+ Redirector.save();
+ }
+ },false);
},
onLoad : function() {
@@ -35,7 +48,6 @@ var RedirectList = {
this.lstRedirects.removeChild(this.template);
this.btnDelete = document.getElementById('btnDelete');
this.btnEdit = document.getElementById('btnEdit');
- this.btnDisable = document.getElementById('btnDisable');
this.addItemsToListBox(Redirector.list);
this.strings = document.getElementById('redirector-strings');
} catch(e) {
@@ -102,19 +114,12 @@ var RedirectList = {
}
},
- toggleDisabled : function() {
- var listItem = this.lstRedirects.selectedItem;
- if (!listItem) {
- return;
- }
- var redirect = listItem.item;
- redirect.disabled = !redirect.disabled;
- Redirector.save();
- this.btnDisable.setAttribute('label', this.strings.getString(redirect.disabled ? 'enable' : 'disable'));
- },
-
editRedirect : function() {
+ if (this.lstRedirects.selectedIndex == -1) {
+ return;
+ }
+ //.selectedItem is still there after it has been removed, that's why we have the .selectedIndex check above as well
var listItem = this.lstRedirects.selectedItem;
if (!listItem) {
return;
@@ -136,10 +141,18 @@ var RedirectList = {
if (index == -1) {
return;
}
-
+
+ var text = this.strings.getString("deleteConfirmationText");
+ var title = this.strings.getString("deleteConfirmationTitle");
+ var reallyDelete = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService).confirm(null, title, text);
+ if (!reallyDelete) {
+ return;
+ }
+
try {
this.lstRedirects.removeChild(this.lstRedirects.children[index]);
Redirector.deleteAt(index);
+ this.selectionChange();
} catch(e) {
alert(e);
}
@@ -150,14 +163,6 @@ var RedirectList = {
this.btnEdit.disabled = (index == -1);
this.btnDelete.disabled = (index == -1);
- this.btnDisable.disabled = (index == -1);
- var redirect = this.lstRedirects.selectedItem.item;
- try {
- if (index != -1) {
- this.btnDisable.setAttribute('label', this.strings.getString(redirect.disabled ? 'enable' : 'disable'));
- this.lstRedirects.selectedItem.setAttribute('disabled', true);
- }
- }catch(e){alert(e);}
},
importExport : function(mode, captionKey, func) {
diff --git a/chrome/content/ui/editRedirect.xul b/chrome/content/ui/editRedirect.xul
index 103d1b5..22d4a8d 100644
--- a/chrome/content/ui/editRedirect.xul
+++ b/chrome/content/ui/editRedirect.xul
@@ -47,7 +47,10 @@
-
+
+
+
+
diff --git a/chrome/content/ui/redirectList.xul b/chrome/content/ui/redirectList.xul
index 643a699..8317b15 100644
--- a/chrome/content/ui/redirectList.xul
+++ b/chrome/content/ui/redirectList.xul
@@ -6,8 +6,8 @@
orient="vertical"
onload="RedirectList.onLoad();"
buttons="accept"
- width="600px"
- height="400px"
+ width="650px"
+ height="500px"
windowtype="redirectorSettings"
xmlns:nc="http://home.netscape.com/NC-rdf#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
@@ -19,7 +19,7 @@
-
+
@@ -37,6 +37,10 @@
+
+
+
+
@@ -45,7 +49,6 @@
-
diff --git a/chrome/locale/en-US/redirectList.xul.dtd b/chrome/locale/en-US/redirectList.xul.dtd
index 5379647..c8892cc 100644
--- a/chrome/locale/en-US/redirectList.xul.dtd
+++ b/chrome/locale/en-US/redirectList.xul.dtd
@@ -3,6 +3,7 @@
+
diff --git a/chrome/locale/en-US/redirector.properties b/chrome/locale/en-US/redirector.properties
index 6b4ecf7..b57025b 100644
--- a/chrome/locale/en-US/redirector.properties
+++ b/chrome/locale/en-US/redirector.properties
@@ -15,5 +15,5 @@ xpathDeprecated=XPath patterns are no longer supported as of version 1.5.1, plea
redirectorFiles=Redirector files (*.rdx)
exportCaption=Export redirects...
importCaption=Import redirects...
-disable=Disable
-enable=Enable
\ No newline at end of file
+deleteConfirmationText=Are you sure you want to permanently delete this redirect?
+deleteConfirmationTitle=Delete redirect?
--
cgit v1.2.3-70-g09d2