aboutsummaryrefslogtreecommitdiff
path: root/chrome/content/code/editRedirect.xul.js
diff options
context:
space:
mode:
authorEinar Egilsson2009-09-15 21:41:06 +0000
committerEinar Egilsson2009-09-15 21:41:06 +0000
commit96966ca83f96ed1babcd2bd23aa68feb63fbb7a7 (patch)
treef2483b413192a279753cb02d2d8fcff9f0ad9b03 /chrome/content/code/editRedirect.xul.js
parentd32cd776748e45abeaa6c2284b96210952c79717 (diff)
Total restructuring of files.
Unescape matches fully working Export of redirects working. git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@249 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome/content/code/editRedirect.xul.js')
-rw-r--r--chrome/content/code/editRedirect.xul.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/chrome/content/code/editRedirect.xul.js b/chrome/content/code/editRedirect.xul.js
new file mode 100644
index 0000000..6e981d2
--- /dev/null
+++ b/chrome/content/code/editRedirect.xul.js
@@ -0,0 +1,86 @@
+//// $Id$
+
+const kRedirectorWildcard = 'W';
+const kRedirectorRegex= 'R';
+var Redirector = Components.classes["@einaregilsson.com/redirector;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
+
+function $(id) {
+ return document.getElementById(id);
+}
+
+var EditRedirect = {
+
+ onLoad : function() {
+ var item = window.arguments[0];
+ item.saved = false;
+ $('txtExampleUrl').value = item.exampleUrl;
+ $('txtPattern').value = item.pattern;
+ $('txtRedirectUrl').value = item.redirectUrl || '';
+ $('txtExcludePattern').value = item.excludePattern || '';
+ $('chkUnescapeMatches').setAttribute('checked', !!item.unescapeMatches);
+
+ $('txtPattern').focus();
+ this.strings = document.getElementById("redirector-strings");
+
+ if (item.patternType == kRedirectorRegex) {
+ $('rdoRegex').setAttribute('selected', true);
+ $('rdoWildcard').setAttribute('selected', false);
+ }
+ },
+
+ onAccept : function() {
+ var item = window.arguments[0];
+
+ item.pattern = $('txtPattern').value;
+ if ($('rdoRegex').selected) {
+ item.patternType = kRedirectorRegex;
+ } else {
+ item.patternType = kRedirectorWildcard;
+ }
+ item.exampleUrl = $('txtExampleUrl').value;
+ item.redirectUrl = $('txtRedirectUrl').value;
+ item.excludePattern = $('txtExcludePattern').value;
+ item.unescapeMatches = $('chkUnescapeMatches').hasAttribute('checked') && $('chkUnescapeMatches').getAttribute('checked');
+ item.saved = true;
+
+ return true;
+ },
+
+ msgBox : function(title, text) {
+ Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Components.interfaces.nsIPromptService)
+ .alert(window, title, text);
+ },
+
+ testPattern : function() {
+ var redirectUrl, pattern, excludePattern, example, extName, isExcluded, unescapeMatches;
+ redirectUrl = $('txtRedirectUrl').value;
+ pattern = $('txtPattern').value;
+ excludePattern = $('txtExcludePattern').value;
+ example = $('txtExampleUrl').value;
+ unescapeMatches = $('chkUnescapeMatches').checked;
+
+ extName = this.strings.getString('extensionName');
+
+ if ($('rdoRegex').selected) {
+ redirectUrl = Redirector.regexMatch(pattern, example, redirectUrl, unescapeMatches);
+ if (excludePattern) {
+ isExcluded = Redirector.regexMatch(excludePattern, example, 'exclude');
+ }
+ } else {
+ redirectUrl = Redirector.wildcardMatch(pattern, example, redirectUrl, unescapeMatches);
+ if (excludePattern) {
+ isExcluded = Redirector.wildcardMatch(excludePattern, example, 'exclude');
+ }
+ }
+
+ var isRedirectMatch = redirectUrl || (redirectUrl === '' && $('txtRedirectUrl').value === '');
+ if (isRedirectMatch && !isExcluded) {
+ this.msgBox(extName, this.strings.getFormattedString('testPatternSuccess', [pattern, example, redirectUrl]));
+ } else if (isExcluded) {
+ this.msgBox(extName, this.strings.getFormattedString('testPatternExclude', [example, excludePattern]));
+ } else {
+ this.msgBox(extName, this.strings.getFormattedString('testPatternFailure', [pattern, example]));
+ }
+ }
+}; \ No newline at end of file