From 141fb6e3a664319c62e7fd1ffe2a2324b5f556d6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 20 Nov 2010 15:02:20 +0300 Subject: [PATCH] filterEditDlg: add regexp verification; js: code cleanup --- functions.js | 43 +++++++++++++++---- prefs.js | 116 ++++++++++++++------------------------------------- 2 files changed, 66 insertions(+), 93 deletions(-) diff --git a/functions.js b/functions.js index e9a1f70b..946e29a9 100644 --- a/functions.js +++ b/functions.js @@ -1184,18 +1184,43 @@ function quickAddFilter() { style: "width: 600px", execute: function() { if (this.validate()) { - console.log(dojo.objectToQuery(this.attr('value'))); - new Ajax.Request("backend.php", { - parameters: dojo.objectToQuery(this.attr('value')), + + var query = "?op=rpc&subop=verifyRegexp®_exp=" + + param_escape(dialog.attr('value').reg_exp); + + notify_progress("Verifying regular expression..."); + + new Ajax.Request("backend.php", { + parameters: query, onComplete: function(transport) { - this.hide(); - notify_progress("Savind data...", true); - notify_info(transport.responseText); - if (inPreferences()) { - updateFilterList(); + handle_rpc_reply(transport); + var response = transport.responseXML; + + if (response) { + var s = response.getElementsByTagName("status")[0].firstChild.nodeValue; + + notify(''); + + if (s == "INVALID") { + alert("Match regular expression seems to be invalid."); + return; + } else { + notify_progress("Saving data...", true); + + console.log(dojo.objectToQuery(dialog.attr('value'))); + + new Ajax.Request("backend.php", { + parameters: dojo.objectToQuery(dialog.attr('value')), + onComplete: function(transport) { + dialog.hide(); + notify_info(transport.responseText); + if (inPreferences()) { + updateFilterList(); + } + }}) + } } }}); - } }, href: query}); diff --git a/prefs.js b/prefs.js index fdcf28e8..14af5b60 100644 --- a/prefs.js +++ b/prefs.js @@ -301,12 +301,39 @@ function editFilter(id, event) { style: "width: 600px", execute: function() { if (this.validate()) { - this.hide(); - notify_progress("Savind data...", true); - new Ajax.Request("backend.php", { - parameters: dojo.objectToQuery(this.attr('value')), + + var query = "?op=rpc&subop=verifyRegexp®_exp=" + + param_escape(dialog.attr('value').reg_exp); + + notify_progress("Verifying regular expression..."); + + new Ajax.Request("backend.php", { + parameters: query, onComplete: function(transport) { - updateFilterList(); + handle_rpc_reply(transport); + var response = transport.responseXML; + + if (response) { + var s = response.getElementsByTagName("status")[0].firstChild.nodeValue; + + notify(''); + + if (s == "INVALID") { + alert("Match regular expression seems to be invalid."); + return; + } else { + notify_progress("Saving data...", true); + + console.log(dojo.objectToQuery(dialog.attr('value'))); + + new Ajax.Request("backend.php", { + parameters: dojo.objectToQuery(dialog.attr('value')), + onComplete: function(transport) { + dialog.hide(); + updateFilterList(); + }}) + } + } }}); } }, @@ -687,11 +714,6 @@ function userEditCancel() { return false; } -function filterEditCancel() { - closeInfoBox(); - return false; -} - function userEditSave() { try { @@ -724,55 +746,6 @@ function userEditSave() { } -function filterEditSave() { - try { - var reg_exp = document.forms["filter_edit_form"].reg_exp.value; - - var query = "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp); - - notify_progress("Verifying regular expression..."); - - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - handle_rpc_reply(transport); - - var response = transport.responseXML; - - if (response) { - var s = response.getElementsByTagName("status")[0].firstChild.nodeValue; - - notify(''); - - if (s == "INVALID") { - alert("Match regular expression seems to be invalid."); - return; - } else { - - var query = "?" + Form.serialize("filter_edit_form"); - - notify_progress("Saving filter..."); - - Form.disable("filter_edit_form"); - - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - closeInfoBox(); - filterlist_callback2(transport); - } }); - } - } - } }); - - } catch (e) { - exception_error("filterEditSave", e); - } - - return false; -} - - function editSelectedUser() { var rows = getSelectedUsers(); @@ -2002,29 +1975,4 @@ function editLabel(id, event) { } } -function editLabelSave() { - try { - var form = document.forms['label_edit_form']; - - var id = form.id.value; - var caption = form.caption.value; - var fg_color = form.fg_color.value; - var bg_color = form.bg_color.value; - - var query = Form.serialize('label_edit_form'); - dijit.byId('labelTree').setNameById(id, caption); - setLabelColor(id, fg_color, bg_color); - - closeInfoBox(); - updateFilterList(); - - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - } }); - - } catch (e) { - exception_error("editLabelSave", e); - } -} -- 2.39.5