From 23e51f409297604df31ebd1d72792707bae0abbc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 24 Jan 2009 08:25:21 +0100 Subject: [PATCH] prefs: some async work (4) --- prefs.js | 154 ++++++++++++++++++++++++++----------------------------- 1 file changed, 72 insertions(+), 82 deletions(-) diff --git a/prefs.js b/prefs.js index 27367d712..a499d9ffa 100644 --- a/prefs.js +++ b/prefs.js @@ -53,12 +53,6 @@ function replace_pubkey_callback() { } } -function feedlist_callback() { - if (xmlhttp.readyState == 4) { - return feedlist_callback2(xmlhttp); - } -} - function feedlist_callback2(transport) { try { @@ -102,13 +96,6 @@ function filterlist_callback2(transport) { remove_splash(); } - -function filterlist_callback() { - if (xmlhttp.readyState == 4) { - filterlist_callback2(xmlhttp); - } -} - function labellist_callback2(transport) { try { @@ -566,27 +553,32 @@ function removeSelectedUsers() { function removeSelectedFilters() { - if (!xmlhttp_ready(xmlhttp)) { - printLockingError(); - return - } - - var sel_rows = getSelectedFilters(); - - if (sel_rows.length > 0) { - - var ok = confirm(__("Remove selected filters?")); + try { - if (ok) { - notify_progress("Removing selected filters..."); + var sel_rows = getSelectedFilters(); - xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+ - param_escape(sel_rows.toString()), true); - xmlhttp.onreadystatechange=filterlist_callback; - xmlhttp.send(null); + if (sel_rows.length > 0) { + + var ok = confirm(__("Remove selected filters?")); + + if (ok) { + notify_progress("Removing selected filters..."); + + var query = "backend.php?op=pref-filters&subop=remove&ids="+ + param_escape(sel_rows.toString()); + + new Ajax.Request(query, { + onComplete: function(transport) { + filterlist_callback2(transport); + } }); + + } + } else { + alert(__("No filters are selected.")); } - } else { - alert(__("No filters are selected.")); + + } catch (e) { + exception_error("removeSelectedFilters", e); } return false; @@ -831,31 +823,24 @@ function userEditSave() { function filterEditSave() { - if (!xmlhttp_ready(xmlhttp)) { - printLockingError(); - return - } + try { -/* if (!is_opera()) { - var reg_exp = document.forms["filter_edit_form"].reg_exp.value; + notify_progress("Saving filter..."); - if (reg_exp.length == 0) { - alert("Filter expression field cannot be blank."); - return; - } - } */ - - notify_progress("Saving filter..."); - - var query = Form.serialize("filter_edit_form"); - - closeInfoBox(); + var query = "backend.php?" + Form.serialize("filter_edit_form"); + + closeInfoBox(); + + document.getElementById("create_filter_btn").disabled = false; - document.getElementById("create_filter_btn").disabled = false; + new Ajax.Request(query, { + onComplete: function(transport) { + filterlist_callback2(transport); + } }); - xmlhttp.open("GET", "backend.php?" + query, true); - xmlhttp.onreadystatechange=filterlist_callback; - xmlhttp.send(null); + } catch (e) { + exception_error("filterEditSave", e); + } return false; } @@ -1031,21 +1016,24 @@ function validateOpmlImport() { } function updateFilterList(sort_key) { + try { - if (!xmlhttp_ready(xmlhttp)) { - printLockingError(); - return - } + var filter_search = document.getElementById("filter_search"); + var search = ""; + if (filter_search) { search = filter_search.value; } + + var query = "backend.php?op=pref-filters&sort=" + + param_escape(sort_key) + + "&search=" + param_escape(search); - var filter_search = document.getElementById("filter_search"); - var search = ""; - if (filter_search) { search = filter_search.value; } + new Ajax.Request(query, { + onComplete: function(transport) { + filterlist_callback2(transport); + } }); - xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" + - param_escape(sort_key) + - "&search=" + param_escape(search), true); - xmlhttp.onreadystatechange=filterlist_callback; - xmlhttp.send(null); + } catch (e) { + exception_error("updateFilterList", e); + } } @@ -1951,30 +1939,32 @@ function removeFilter(id, title) { function unsubscribeFeed(id, title) { - if (!xmlhttp_ready(xmlhttp)) { - printLockingError(); - return - } - - var msg = __("Unsubscribe from %s?").replace("%s", title); - - var ok = confirm(msg); - - if (ok) { - closeInfoBox(); + try { - notify_progress("Removing feed..."); + var msg = __("Unsubscribe from %s?").replace("%s", title); - xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+ - param_escape(id), true); - xmlhttp.onreadystatechange=filterlist_callback; - xmlhttp.send(null); + var ok = confirm(msg); + + if (ok) { + closeInfoBox(); + + notify_progress("Removing feed..."); + + var query = "backend.php?op=pref-feeds&subop=remove&ids="+ + param_escape(id); + + new Ajax.Request(query, { + onComplete: function(transport) { + feedlist_callback2(transport); + } }); + } + + } catch (e) { + exception_error("unsubscribeFeed", e); } return false; - return false; - } function feedsEditSave() {