]> git.wh0rd.org - tt-rss.git/blobdiff - functions.js
use css for help overlay, css cleanup
[tt-rss.git] / functions.js
index 362fc9888cc04bfa6c8dd67dc76b84e4bf363cbb..c47070ed3e3e78f2ec3cc52b0f705b8fd90ac5b6 100644 (file)
@@ -1,8 +1,6 @@
-var hotkeys_enabled = true;
 var notify_silent = false;
-var last_progress_point = 0;
+var loading_progress = 0;
 var sanity_check_done = false;
-var dialogs = [];
 
 /* add method to remove element from array */
 
@@ -35,25 +33,55 @@ function exception_error(location, e, ext_info) {
                var content = "<div class=\"fatalError\">" +
                        "<pre>" + msg + "</pre>";
 
+               content += "<form name=\"exceptionForm\" id=\"exceptionForm\" target=\"_blank\" "+
+                 "action=\"http://tt-rss.org/report.php\" method=\"POST\">";
+
+               content += "<textarea style=\"display : none\" name=\"message\">" + msg + "</textarea>";
+               content += "<textarea style=\"display : none\" name=\"params\">N/A</textarea>";
+
                if (ext_info) {
                        content += "<div><b>Additional information:</b></div>" +
-                       "<textarea readonly=\"1\">" + ext_info + "</textarea>";
+                       "<textarea name=\"xinfo\" readonly=\"1\">" + ext_info + "</textarea>";
                }
 
                content += "<div><b>Stack trace:</b></div>" +
-                       "<textarea readonly=\"1\">" + e.stack + "</textarea>";
+                       "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>";
+
+               content += "</form>";
+
+               content += "</div>";
 
-//             content += "<div style='text-align : center'>" +
-//                     "<button onclick=\"closeInfoBox()\">" +
-//                     "Close this window" + "</button></div>";
+               content += "<div class='dlgButtons'>";
 
+               content += "<button dojoType=\"dijit.form.Button\""+
+                               "onclick=\"dijit.byId('exceptionDlg').report()\">" +
+                               __('Report to tt-rss.org') + "</button> ";
+               content += "<button dojoType=\"dijit.form.Button\" "+
+                               "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
+                               __('Close') + "</button>";
                content += "</div>";
 
-               // TODO: add code to automatically report errors to tt-rss.org
+               if (dijit.byId("exceptionDlg"))
+                       dijit.byId("exceptionDlg").destroyRecursive();
 
                var dialog = new dijit.Dialog({
+                       id: "exceptionDlg",
                        title: "Unhandled exception",
                        style: "width: 600px",
+                       report: function() {
+                               if (confirm(__("Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database."))) {
+
+                                       document.forms['exceptionForm'].params.value = $H({
+                                               browserName: navigator.appName,
+                                               browserVersion: navigator.appVersion,
+                                               browserPlatform: navigator.platform,
+                                               browserCookies: navigator.cookieEnabled,
+                                       }).toQueryString();
+
+                                       document.forms['exceptionForm'].submit();
+
+                               }
+                       },
                        content: content});
 
                dialog.show();
@@ -69,8 +97,8 @@ function format_exception_error(location, e) {
 
        if (e.fileName) {
                var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
-       
-               msg = "Exception: " + e.name + ", " + e.message + 
+
+               msg = "Exception: " + e.name + ", " + e.message +
                        "\nFunction: " + location + "()" +
                        "\nLocation: " + base_fname + ":" + e.lineNumber;
 
@@ -85,25 +113,16 @@ function format_exception_error(location, e) {
        return msg;
 }
 
-
-function disableHotkeys() {
-       hotkeys_enabled = false;
-}
-
-function enableHotkeys() {
-       hotkeys_enabled = true;
-}
-
 function param_escape(arg) {
        if (typeof encodeURIComponent != 'undefined')
-               return encodeURIComponent(arg); 
+               return encodeURIComponent(arg);
        else
                return escape(arg);
 }
 
 function param_unescape(arg) {
        if (typeof decodeURIComponent != 'undefined')
-               return decodeURIComponent(arg); 
+               return decodeURIComponent(arg);
        else
                return unescape(arg);
 }
@@ -115,7 +134,7 @@ function hide_notify() {
        if (n) {
                n.style.display = "none";
        }
-} 
+}
 
 function notify_silent_next() {
        notify_silent = true;
@@ -199,16 +218,16 @@ function notify_info(msg, no_hide) {
 }
 
 function setCookie(name, value, lifetime, path, domain, secure) {
-       
+
        var d = false;
-       
+
        if (lifetime) {
                d = new Date();
                d.setTime(d.getTime() + (lifetime * 1000));
        }
 
        console.log("setCookie: " + name + " => " + value + ": " + d);
-       
+
        int_setCookie(name, value, d, path, domain, secure);
 
 }
@@ -229,7 +248,7 @@ function delCookie(name, path, domain) {
                ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
        }
 }
-               
+
 
 function getCookie(name) {
 
@@ -258,8 +277,9 @@ function gotoMain() {
        document.location.href = "tt-rss.php";
 }
 
-function gotoExportOpml() {
-       document.location.href = "opml.php?op=Export";
+function gotoExportOpml(filename, settings) {
+    tmp = settings ? 1 : 0;
+       document.location.href = "opml.php?op=Export&filename=" + filename + "&settings=" + tmp;
 }
 
 
@@ -267,10 +287,10 @@ function gotoExportOpml() {
   * * @author Sundar Dorai-Raj
   * * Email: sdoraira@vt.edu
   * * This program is free software; you can redistribute it and/or
-  * * modify it under the terms of the GNU General Public License 
-  * * as published by the Free Software Foundation; either version 2 
-  * * of the License, or (at your option) any later version, 
-  * * provided that any use properly credits the author. 
+  * * modify it under the terms of the GNU General Public License
+  * * as published by the Free Software Foundation; either version 2
+  * * of the License, or (at your option) any later version,
+  * * provided that any use properly credits the author.
   * * This program is distributed in the hope that it will be useful,
   * * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -307,10 +327,28 @@ function toggleSelectListRow(sender) {
        return toggleSelectRow(sender, row);
 }
 
+/* this is for dijit Checkbox */
+function toggleSelectListRow2(sender) {
+       var row = sender.domNode.parentNode;
+       return toggleSelectRow(sender, row);
+}
+
 function tSR(sender, row) {
        return toggleSelectRow(sender, row);
 }
 
+/* this is for dijit Checkbox */
+function toggleSelectRow2(sender, row) {
+
+       if (!row) row = sender.domNode.parentNode.parentNode;
+
+       if (sender.checked && !row.hasClassName('Selected'))
+               row.addClassName('Selected');
+       else
+               row.removeClassName('Selected');
+}
+
+
 function toggleSelectRow(sender, row) {
 
        if (!row) row = sender.parentNode.parentNode;
@@ -338,29 +376,9 @@ function dropboxSelect(e, v) {
        }
 }
 
-// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
-// bugfixed just a little bit :-)
-function getURLParam(strParamName){
-  var strReturn = "";
-  var strHref = window.location.href;
-
-  if (strHref.indexOf("#") == strHref.length-1) {
-               strHref = strHref.substring(0, strHref.length-1);
-  }
-
-  if ( strHref.indexOf("?") > -1 ){
-    var strQueryString = strHref.substr(strHref.indexOf("?"));
-    var aQueryString = strQueryString.split("&");
-    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
-      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
-        var aParam = aQueryString[iParam].split("=");
-        strReturn = aParam[1];
-        break;
-      }
-    }
-  }
-  return strReturn;
-} 
+function getURLParam(param){
+       return String(window.location.href).parseQuery()[param];
+}
 
 function leading_zero(p) {
        var s = String(p);
@@ -376,26 +394,11 @@ function make_timestamp() {
 }
 
 
-function closeErrorBox() {
-
-       if (Element.visible("errorBoxShadow")) {
-               Element.hide("dialog_overlay");
-               Element.hide("errorBoxShadow");
-
-               enableHotkeys();
-       }
-
-       return false;
-}
-
 function closeInfoBox(cleanup) {
        try {
-               enableHotkeys();
+               dialog = dijit.byId("infoBox");
 
-               var dialog = dialogs.pop();
-
-               if (dialog)
-                       dialog.hide();
+               if (dialog)     dialog.hide();
 
        } catch (e) {
                //exception_error("closeInfoBox", e);
@@ -421,23 +424,13 @@ function displayDlg(id, param, callback) {
        return false;
 }
 
-function infobox_submit_callback2(transport) {
-       closeInfoBox();
-
-       try {
-               // called from prefs, reload tab
-               if (typeof active_tab != 'undefined' && active_tab) {
-                       selectTab(active_tab, false);
-               }
-       } catch (e) { }
-
-       if (transport.responseText) {
-               notify_info(transport.responseText);
-       }
-}
-
 function infobox_callback2(transport) {
        try {
+               var dialog = false;
+
+               if (dijit.byId("infoBox")) {
+                       dialog = dijit.byId("infoBox");
+               }
 
                //console.log("infobox_callback2");
                notify('');
@@ -445,209 +438,44 @@ function infobox_callback2(transport) {
                var content;
                var dtitle = "Dialog";
 
-               if (transport.responseXML) {
-                       var dlg = transport.responseXML.getElementsByTagName("dlg")[0];
-
-                       var title = transport.responseXML.getElementsByTagName("title")[0];
-                       if (title)
-                               title = title.firstChild.nodeValue;
-
-                       var content = transport.responseXML.getElementsByTagName("content")[0];
-                       
-                       content = content.firstChild.nodeValue;
-
+               var dlg = transport.responseXML.getElementsByTagName("dlg")[0];
+
+               var title = transport.responseXML.getElementsByTagName("title")[0];
+               if (title)
+                       title = title.firstChild.nodeValue;
+
+               var content = transport.responseXML.getElementsByTagName("content")[0];
+
+               content = content.firstChild.nodeValue;
+
+               if (!dialog) {
+                       dialog = new dijit.Dialog({
+                               title: title,
+                               id: 'infoBox',
+                               style: "width: 600px",
+                               onCancel: function() {
+                                       return true;
+                               },
+                               onExecute: function() {
+                                       return true;
+                               },
+                               onClose: function() {
+                                       return true;
+                                       },
+                               content: content});
                } else {
-                       content = transport.responseText;
+                       dialog.attr('title', title);
+                       dialog.attr('content', content);
                }
 
-               var dialog = new dijit.Dialog({
-                       title: title,
-                       style: "width: 600px",
-                       onCancel: function() {
-                               dialogs.remove(this);
-                               return true;
-                       },
-                       onExecute: function() {
-                               dialogs.remove(this);
-                               return true;
-                       },
-                       onClose: function() {
-                               dialogs.remove(this);
-                               return true;
-                       },
-                       content: content});
-
                dialog.show();
 
-               dialogs.push(dialog);
-
                notify("");
        } catch (e) {
                exception_error("infobox_callback2", e);
        }
 }
 
-function createFilter() {
-
-       try {
-
-               var form = document.forms['filter_add_form'];
-               var reg_exp = form.reg_exp.value;
-       
-               if (reg_exp == "") {
-                       alert(__("Can't add filter: nothing to match on."));
-                       return false;
-               }
-
-               var query = "?op=rpc&subop=verifyRegexp&reg_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_add_form");
-                                               
-                                                       // we can be called from some other tab in Prefs                
-                                                       if (typeof active_tab != 'undefined' && active_tab) {
-                                                               active_tab = "filterConfig";
-                                                       }
-                                               
-                                                       new Ajax.Request("backend.php?" + query, {
-                                                               onComplete: function (transport) {
-                                                                       infobox_submit_callback2(transport);
-                                                               } });
-                                                       
-                                                       return true;
-                                               }
-                                       }
-
-                       } });
-
-       } catch (e) {
-               exception_error("createFilter", e);
-       }
-}
-
-function isValidURL(s) {
-       return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
-}
-
-function subscribeToFeed() {
-
-       try {
-
-       var form = document.forms['feed_add_form'];
-       var feed_url = form.feed_url.value;
-
-       if (feed_url == "") {
-               alert(__("Can't subscribe: no feed URL given."));
-               return false;
-       }
-
-       notify_progress(__("Subscribing to feed..."), true);
-
-       var query = Form.serialize("feed_add_form");
-       
-       console.log("subscribe q: " + query);
-
-       Form.disable("feed_add_form");
-
-       new Ajax.Request("backend.php", {
-               parameters: query,
-               onComplete: function(transport) { 
-                       //dlg_frefresh_callback(transport); 
-
-                       try {
-
-                               if (!transport.responseXML) {
-                                       console.log(transport.responseText);
-                                       alert(__("Server error while trying to subscribe to specified feed."));
-                                       return;
-                               }
-
-                               var result = transport.responseXML.getElementsByTagName('result')[0];
-                               var rc = parseInt(result.getAttribute('code'));
-       
-                               Form.enable("feed_add_form");
-       
-                               notify('');
-       
-                               switch (rc) {
-                               case 1:
-                                       closeInfoBox();
-                                       notify_info(__("Subscribed to %s").replace("%s", feed_url));
-       
-                                       if (inPreferences()) {
-                                               updateFeedList();
-                                       } else {
-                                               setTimeout('updateFeedList(false, false)', 50);
-                                       }
-                                       break;
-                               case 2:
-                                       alert(__("Specified URL seems to be invalid."));
-                                       break;
-                               case 3:
-                                       alert(__("Specified URL doesn't seem to contain any feeds."));
-                                       break;
-                               case 4:
-                                       new Ajax.Request("backend.php", {
-                                               parameters: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url),
-                                               onComplete: function(transport) {
-                                                       var result = transport.responseXML.getElementsByTagName('urls')[0];
-                                                       var feeds = JSON.parse(result.firstChild.nodeValue);
-                                                       var select = document.getElementById("faad_feeds_container_select");
-       
-                                                       while (select.hasChildNodes()) {
-                                                               select.removeChild(elem.firstChild);
-                                                       }
-                                                       var count = 0;
-                                                       for (var feedUrl in feeds) {
-                                                               select.insert(new Option(feeds[feedUrl], feedUrl, false));
-                                                               count++;
-                                                       }
-                                                       if (count > 5) count = 5;
-                                                       select.size = count;
-       
-                                                       Effect.Appear('fadd_feeds_container', {duration : 0.5});
-                                               }
-                                       });
-                                       break;
-                               case 5:
-                                       alert(__("Couldn't download the specified URL."));
-                                       break;
-                               case 0:
-                                       alert(__("You are already subscribed to this feed."));
-                                       break;
-                               }
-
-                       } catch (e) {
-                               exception_error("subscribeToFeed", e);
-                       }
-
-               } });
-
-       } catch (e) {
-               exception_error("subscribeToFeed", e);
-       }
-
-       return false;
-}
-
 function filterCR(e, f)
 {
      var key;
@@ -678,40 +506,46 @@ function setInitParam(key, value) {
 }
 
 function fatalError(code, msg, ext_info) {
-       try {   
-
-               if (!ext_info) ext_info = "N/A";
+       try {
 
                if (code == 6) {
-                       window.location.href = "tt-rss.php";                    
+                       window.location.href = "tt-rss.php";
                } else if (code == 5) {
                        window.location.href = "db-updater.php";
                } else {
-       
+
                        if (msg == "") msg = "Unknown error";
 
-                       var ebc = $("xebContent");
-       
-                       if (ebc) {
-       
-                               Element.show("dialog_overlay");
-                               Element.show("errorBoxShadow");
-                               Element.hide("xebBtn");
-
-                               if (ext_info) {
-                                       if (ext_info.responseText) {
-                                               ext_info = ext_info.responseText;
-                                       }
+                       if (ext_info) {
+                               if (ext_info.responseText) {
+                                       ext_info = ext_info.responseText;
                                }
-       
-                               ebc.innerHTML = 
-                                       "<div><b>Error message:</b></div>" +
-                                       "<pre>" + msg + "</pre>" +
-                                       "<div><b>Additional information:</b></div>" +
-                                       "<textarea readonly=\"1\">" + ext_info + "</textarea>";
                        }
+
+                       if (ERRORS && ERRORS[code] && !msg) {
+                               msg = ERRORS[code];
+                       }
+
+                       var content = "<div><b>Error code:</b> " + code + "</div>" +
+                               "<p>" + msg + "</p>";
+
+                       if (ext_info) {
+                               content = content + "<div><b>Additional information:</b></div>" +
+                                       "<textarea style='width: 100%' readonly=\"1\">" +
+                                       ext_info + "</textarea>";
+                       }
+
+                       var dialog = new dijit.Dialog({
+                               title: "Fatal error",
+                               style: "width: 600px",
+                               content: content});
+
+                       dialog.show();
+
                }
 
+               return false;
+
        } catch (e) {
                exception_error("fatalError", e);
        }
@@ -721,26 +555,15 @@ function filterDlgCheckType(sender) {
 
        try {
 
-               var ftype = sender[sender.selectedIndex].value;
-
-               var form = document.forms["filter_add_form"];
-       
-               if (!form) {
-                       form = document.forms["filter_edit_form"];
-               }
-
-               if (!form) {
-                       console.log("filterDlgCheckType: can't find form!");
-                       return;
-               }
+               var ftype = sender.value;
 
                // if selected filter type is 5 (Date) enable the modifier dropbox
                if (ftype == 5) {
-                       Element.show("filter_dlg_date_mod_box");
-                       Element.show("filter_dlg_date_chk_box");
+                       Element.show("filterDlg_dateModBox");
+                       Element.show("filterDlg_dateChkBox");
                } else {
-                       Element.hide("filter_dlg_date_mod_box");
-                       Element.hide("filter_dlg_date_chk_box");
+                       Element.hide("filterDlg_dateModBox");
+                       Element.hide("filterDlg_dateChkBox");
 
                }
 
@@ -754,20 +577,9 @@ function filterDlgCheckAction(sender) {
 
        try {
 
-               var action = sender[sender.selectedIndex].value;
+               var action = sender.value;
 
-               var form = document.forms["filter_add_form"];
-       
-               if (!form) {
-                       form = document.forms["filter_edit_form"];
-               }
-
-               if (!form) {
-                       console.log("filterDlgCheckAction: can't find form!");
-                       return;
-               }
-
-               var action_param = $("filter_dlg_param_box");
+               var action_param = $("filterDlg_paramBox");
 
                if (!action_param) {
                        console.log("filterDlgCheckAction: can't find action param box!");
@@ -776,13 +588,13 @@ function filterDlgCheckAction(sender) {
 
                // if selected action supports parameters, enable params field
                if (action == 4 || action == 6 || action == 7) {
-                       Element.show(action_param);
+                       new Effect.Appear(action_param, {duration : 0.5});
                        if (action != 7) {
-                               Element.show(form.action_param);
-                               Element.hide(form.action_param_label);
+                               Element.show(dijit.byId("filterDlg_actionParam").domNode);
+                               Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
                        } else {
-                               Element.show(form.action_param_label);
-                               Element.hide(form.action_param);
+                               Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
+                               Element.hide(dijit.byId("filterDlg_actionParam").domNode);
                        }
                } else {
                        Element.hide(action_param);
@@ -796,46 +608,25 @@ function filterDlgCheckAction(sender) {
 
 function filterDlgCheckDate() {
        try {
-               var form = document.forms["filter_add_form"];
-       
-               if (!form) {
-                       form = document.forms["filter_edit_form"];
-               }
+               var dialog = dijit.byId("filterEditDlg");
 
-               if (!form) {
-                       console.log("filterDlgCheckAction: can't find form!");
-                       return;
-               }
-
-               var reg_exp = form.reg_exp.value;
+               var reg_exp = dialog.attr('value').reg_exp;
 
                var query = "?op=rpc&subop=checkDate&date=" + reg_exp;
 
                new Ajax.Request("backend.php", {
                        parameters: query,
-                       onComplete: function(transport) { 
-
-                               var form = document.forms["filter_add_form"];
-       
-                               if (!form) {
-                                       form = document.forms["filter_edit_form"];
-                               }
-
-                               if (transport.responseXML) {
-                                       var result = transport.responseXML.getElementsByTagName("result")[0];
-
-                                       if (result && result.firstChild) {
-                                               if (result.firstChild.nodeValue == "1") {
+                       onComplete: function(transport) {
 
-                                                       new Effect.Highlight(form.reg_exp, {startcolor : '#00ff00'});
+                               var reply = JSON.parse(transport.responseText);
 
-                                                       return;
-                                               }
-                                       }
+                               if (reply['result'] == true) {
+                                       alert(__("Date syntax appears to be correct:") + " " + reply['date']);
+                                       return;
+                               } else {
+                                       alert(__("Date syntax is incorrect."));
                                }
 
-                               new Effect.Highlight(form.reg_exp, {startcolor : '#ff0000'});
-
                        } });
 
 
@@ -852,28 +643,20 @@ function displayHelpInfobox(topic_id) {
 
        var url = "backend.php?op=help&tid=" + param_escape(topic_id);
 
-       var w = window.open(url, "ttrss_help", 
+       var w = window.open(url, "ttrss_help",
                "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
 
 }
 
 function loading_set_progress(p) {
        try {
-               if (p < last_progress_point || !Element.visible("overlay")) return;
-
-               console.log("loading_set_progress : " + p + " (" + last_progress_point + ")");
-
-               var o = $("l_progress_i");
-
-//             o.style.width = (p * 2) + "px";
+               loading_progress += p;
 
-               new Effect.Scale(o, p, { 
-                       scaleY : false,
-                       scaleFrom : last_progress_point,
-                       scaleMode: { originalWidth : 200 },
-                       queue: { position: 'end', scope: 'LSP-Q', limit: 3 } }); 
+               if (dijit.byId("loading_bar"))
+                       dijit.byId("loading_bar").update({progress: loading_progress});
 
-               last_progress_point = p;
+               if (loading_progress >= 90)
+                       remove_splash();
 
        } catch (e) {
                exception_error("loading_set_progress", e);
@@ -881,6 +664,7 @@ function loading_set_progress(p) {
 }
 
 function remove_splash() {
+
        if (Element.visible("overlay")) {
                console.log("about to remove splash, OMG!");
                Element.hide("overlay");
@@ -888,61 +672,6 @@ function remove_splash() {
        }
 }
 
-function getSelectedFeedsFromBrowser() {
-
-       var list = $$("#browseFeedList li[id*=FBROW]");
-
-       var selected = new Array();
-
-       list.each(function(child) {     
-               var id = child.id.replace("FBROW-", "");
-               var cb = $("FBCHK-" + id);
-
-               if (cb.checked) {
-                       selected.push(id);
-               }       
-       });
-
-       return selected;
-}
-
-function updateFeedBrowser() {
-       try {
-
-               var query = Form.serialize("feed_browser");
-
-               Element.show('feed_browser_spinner');
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) { 
-                               notify('');
-
-                               Element.hide('feed_browser_spinner');
-
-                               var c = $("browseFeedList");
-                               var r = transport.responseXML.getElementsByTagName("content")[0];
-                               var nr = transport.responseXML.getElementsByTagName("num-results")[0];
-                               var mode = transport.responseXML.getElementsByTagName("mode")[0];
-
-                               if (c && r) {
-                                       c.innerHTML = r.firstChild.nodeValue;
-                               }
-
-                               if (parseInt(mode.getAttribute("value")) == 2) {
-                                       Element.show('feed_archive_remove');
-                               } else {
-                                       Element.hide('feed_archive_remove');
-                               }
-       
-                       } });
-
-       } catch (e) {
-               exception_error("updateFeedBrowser", e);
-       }
-
-}
-
 function transport_error_check(transport) {
        try {
                if (transport.responseXML) {
@@ -1002,78 +731,6 @@ function hideAuxDlg() {
        }
 }
 
-function feedBrowserSubscribe() {
-       try {
-
-               var selected = getSelectedFeedsFromBrowser();
-
-               var mode = document.forms['feed_browser'].mode;
-
-               mode = mode[mode.selectedIndex].value;
-
-               if (selected.length > 0) {
-                       closeInfoBox();
-
-                       notify_progress("Loading, please wait...", true);
-
-                       var query = "?op=rpc&subop=massSubscribe&ids="+
-                               param_escape(selected.toString()) + "&mode=" + param_escape(mode);
-
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) { 
-
-                                       var nf = transport.responseXML.getElementsByTagName('num-feeds')[0];
-                                       var nf_value = nf.getAttribute("value");
-
-                                       notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value));
-
-                                       if (inPreferences()) {
-                                               updateFeedList();
-                                       } else {
-                                               setTimeout('updateFeedList(false, false)', 50);
-                                       }
-                               } });
-
-               } else {
-                       alert(__("No feeds are selected."));
-               }
-
-       } catch (e) {
-               exception_error("feedBrowserSubscribe", e);
-       }
-}
-
-function feedArchiveRemove() {
-       try {
-
-               var selected = getSelectedFeedsFromBrowser();
-
-               if (selected.length > 0) {
-
-                       var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
-
-                       if (confirm(pr)) {
-                               Element.show('feed_browser_spinner');
-
-                               var query = "?op=rpc&subop=remarchived&ids=" + 
-                                       param_escape(selected.toString());;
-
-                               new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function(transport) { 
-                                               updateFeedBrowser();
-                                       } }); 
-                       }
-
-               } else {
-                       alert(__("No feeds are selected."));
-               }
-
-       } catch (e) {
-               exception_error("feedArchiveRemove", e);
-       }
-}
 
 function uploadIconHandler(rc) {
        try {
@@ -1112,14 +769,14 @@ function removeFeedIcon(id) {
 
                        new Ajax.Request("backend.php", {
                                parameters: query,
-                               onComplete: function(transport) { 
+                               onComplete: function(transport) {
                                        notify_info("Feed icon removed.");
                                        if (inPreferences()) {
                                                updateFeedList();
                                        } else {
                                                setTimeout('updateFeedList(false, false)', 50);
                                        }
-                               } }); 
+                               } });
                }
 
                return false;
@@ -1157,13 +814,13 @@ function addLabel(select, callback) {
                var caption = prompt(__("Please enter label caption:"), "");
 
                if (caption != undefined) {
-       
+
                        if (caption == "") {
                                alert(__("Can't create label: missing caption."));
                                return false;
                        }
 
-                       var query = "?op=pref-labels&subop=add&caption=" + 
+                       var query = "?op=pref-labels&subop=add&caption=" +
                                param_escape(caption);
 
                        if (select)
@@ -1175,11 +832,11 @@ function addLabel(select, callback) {
 
                        new Ajax.Request("backend.php", {
                                parameters: query,
-                               onComplete: function(transport) { 
+                               onComplete: function(transport) {
                                        if (callback) {
                                                callback(transport);
                                        } else if (inPreferences()) {
-                                               infobox_submit_callback2(transport);
+                                               updateLabelList();
                                        } else {
                                                updateFeedList();
                                        }
@@ -1193,15 +850,203 @@ function addLabel(select, callback) {
 }
 
 function quickAddFeed() {
-       displayDlg('quickAddFeed', '',
-          function () {$('feed_url').focus();});
+       try {
+               var query = "backend.php?op=dlg&id=quickAddFeed";
+
+               if (dijit.byId("feedAddDlg"))
+                       dijit.byId("feedAddDlg").destroyRecursive();
+
+               var dialog = new dijit.Dialog({
+                       id: "feedAddDlg",
+                       title: __("Subscribe to Feed"),
+                       style: "width: 600px",
+                       execute: function() {
+                               if (this.validate()) {
+                                       console.log(dojo.objectToQuery(this.attr('value')));
+
+                                       var feed_url = this.attr('value').feed;
+
+                                       notify_progress(__("Subscribing to feed..."), true);
+
+                                       new Ajax.Request("backend.php", {
+                                               parameters: dojo.objectToQuery(this.attr('value')),
+                                               onComplete: function(transport) {
+                                                       try {
+
+                                                               var reply = JSON.parse(transport.responseText);
+
+                                                               var rc = parseInt(reply['result']);
+
+                                                               notify('');
+
+                                                               console.log("GOT RC: " + rc);
+
+                                                               switch (rc) {
+                                                               case 1:
+                                                                       dialog.hide();
+                                                                       notify_info(__("Subscribed to %s").replace("%s", feed_url));
+
+                                                                       updateFeedList();
+                                                                       break;
+                                                               case 2:
+                                                                       alert(__("Specified URL seems to be invalid."));
+                                                                       break;
+                                                               case 3:
+                                                                       alert(__("Specified URL doesn't seem to contain any feeds."));
+                                                                       break;
+                                                               case 4:
+                                                                       notify_progress("Searching for feed urls...", true);
+
+                                                                       new Ajax.Request("backend.php", {
+                                                                               parameters: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url),
+                                                                               onComplete: function(transport, dialog, feed_url) {
+
+                                                                                       notify('');
+
+                                                                                       var reply = JSON.parse(transport.responseText);
+
+                                                                                       var feeds = reply['urls'];
+
+                                                                                       console.log(transport.responseText);
+
+                                                                                       var select = dijit.byId("feedDlg_feedContainerSelect");
+
+                                                                                       while (select.getOptions().length > 0)
+                                                                                               select.removeOption(0);
+
+                                                                                       var count = 0;
+                                                                                       for (var feedUrl in feeds) {
+                                                                                               select.addOption({value: feedUrl, label: feeds[feedUrl]});
+                                                                                               count++;
+                                                                                       }
+
+//                                                                                     if (count > 5) count = 5;
+//                                                                                     select.size = count;
+
+                                                                                       Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
+                                                                               }
+                                                                       });
+                                                                       break;
+                                                               case 5:
+                                                                       alert(__("Couldn't download the specified URL."));
+                                                                       break;
+                                                               case 0:
+                                                                       alert(__("You are already subscribed to this feed."));
+                                                                       break;
+                                                               }
+
+                                                       } catch (e) {
+                                                               exception_error("subscribeToFeed", e, transport);
+                                                       }
+
+                                               } });
+
+                                       }
+                       },
+                       href: query});
+
+               dialog.show();
+       } catch (e) {
+               exception_error("quickAddFeed", e);
+       }
 }
 
 function quickAddFilter() {
-       displayDlg('quickAddFilter', '',
-          function () {document.forms['filter_add_form'].reg_exp.focus();});
+       try {
+               var query = "backend.php?op=dlg&id=quickAddFilter";
+
+               if (dijit.byId("filterEditDlg"))
+                       dijit.byId("filterEditDlg").destroyRecursive();
+
+               dialog = new dijit.Dialog({
+                       id: "filterEditDlg",
+                       title: __("Create Filter"),
+                       style: "width: 600px",
+                       test: function() {
+                               if (this.validate()) {
+
+                                       if (dijit.byId("filterTestDlg"))
+                                               dijit.byId("filterTestDlg").destroyRecursive();
+
+                                       tdialog = new dijit.Dialog({
+                                               id: "filterTestDlg",
+                                               title: __("Filter Test Results"),
+                                               style: "width: 600px",
+                                               href: "backend.php?savemode=test&" +
+                                                       dojo.objectToQuery(dialog.attr('value')),
+                                               });
+
+                                       tdialog.show();
+
+                               }
+                       },
+                       execute: function() {
+                               if (this.validate()) {
+
+                                       var query = "?op=rpc&subop=verifyRegexp&reg_exp=" +
+                                               param_escape(dialog.attr('value').reg_exp);
+
+                                       notify_progress("Verifying regular expression...");
+
+                                       new Ajax.Request("backend.php", {
+                                               parameters: query,
+                                               onComplete: function(transport) {
+                                                       var reply = JSON.parse(transport.responseText);
+
+                                                       if (reply) {
+                                                               notify('');
+
+                                                               if (!reply['status']) {
+                                                                       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});
+
+               dialog.show();
+       } catch (e) {
+               exception_error("quickAddFilter", e);
+       }
 }
 
+function resetPubSub(feed_id, title) {
+
+       var msg = __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title);
+
+       if (title == undefined || confirm(msg)) {
+               notify_progress("Loading, please wait...");
+
+               var query = "?op=pref-feeds&quiet=1&subop=resetPubSub&ids=" + feed_id;
+
+               new Ajax.Request("backend.php", {
+                       parameters: query,
+                       onComplete: function(transport) {
+                               dijit.byId("pubsubReset_Btn").attr('disabled', true);
+                               notify_info("Subscription reset.");
+                       } });
+       }
+
+       return false;
+}
+
+
 function unsubscribeFeed(feed_id, title) {
 
        var msg = __("Unsubscribe from %s?").replace("%s", title);
@@ -1215,12 +1060,13 @@ function unsubscribeFeed(feed_id, title) {
                        parameters: query,
                        onComplete: function(transport) {
 
-                                       closeInfoBox();
+                                       if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
 
                                        if (inPreferences()) {
-                                               updateFeedList();                               
+                                               updateFeedList();
                                        } else {
-                                               dlg_frefresh_callback(transport, feed_id);
+                                               if (feed_id == getActiveFeedId())
+                                                       setTimeout("viewfeed(-5)", 100);
                                        }
 
                                } });
@@ -1241,36 +1087,26 @@ function backend_sanity_check_callback(transport) {
                        return;
                }
 
-               if (!transport.responseXML) {
-                       if (!store) {
-                               fatalError(3, "Sanity check: Received reply is not XML", 
-                                       transport.responseText);
-                               return;
-                       }
-               }
-
-               var reply = transport.responseXML.getElementsByTagName("error")[0];
+               var reply = JSON.parse(transport.responseText);
 
                if (!reply) {
                        fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
                        return;
                }
 
-               var error_code = reply.getAttribute("error-code");
-       
+               var error_code = reply['error']['code'];
+
                if (error_code && error_code != 0) {
-                       return fatalError(error_code, reply.getAttribute("error-msg"));
+                       return fatalError(error_code, reply['error']['message']);
                }
 
                console.log("sanity check ok");
 
-               var params = transport.responseXML.getElementsByTagName("init-params")[0];
+               var params = reply['init-params'];
 
                if (params) {
                        console.log('reading init-params...');
 
-                       params = JSON.parse(params.firstChild.nodeValue);
-
                        if (params) {
                                for (k in params) {
                                        var v = params[k];
@@ -1286,22 +1122,21 @@ function backend_sanity_check_callback(transport) {
                init_second_stage();
 
        } catch (e) {
-               exception_error("backend_sanity_check_callback", e, transport); 
-       } 
+               exception_error("backend_sanity_check_callback", e, transport);
+       }
 }
 
-function has_local_storage() {
-       return false;
-/*     try {
-               return 'localStorage' in window && window['localStorage'] != null;
+/*function has_local_storage() {
+       try {
+               return 'sessionStorage' in window && window['sessionStorage'] != null;
        } catch (e) {
                return false;
-       } */
-}
+       }
+} */
 
 function catSelectOnChange(elem) {
        try {
-               var value = elem[elem.selectedIndex].value;
+/*             var value = elem[elem.selectedIndex].value;
                var def = elem.getAttribute('default');
 
                if (value == "ADD_CAT") {
@@ -1312,7 +1147,7 @@ function catSelectOnChange(elem) {
                                elem.selectedIndex = 0;
 
                        quickAddCat(elem);
-               }
+               } */
 
        } catch (e) {
                exception_error("catSelectOnChange", e);
@@ -1353,35 +1188,34 @@ function genUrlChangeKey(feed, is_cat) {
 
        try {
                var ok = confirm(__("Generate new syndication address for this feed?"));
-       
+
                if (ok) {
-       
+
                        notify_progress("Trying to change address...", true);
-       
-                       var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) + 
+
+                       var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) +
                                "&is_cat=" + param_escape(is_cat);
 
                        new Ajax.Request("backend.php", {
                                parameters: query,
                                onComplete: function(transport) {
-                                               var new_link = transport.responseXML.getElementsByTagName("link")[0];
-       
+                                               var reply = JSON.parse(transport.responseText);
+                                               var new_link = reply.link;
+
                                                var e = $('gen_feed_url');
-       
+
                                                if (new_link) {
-                                                       
-                                                       new_link = new_link.firstChild.nodeValue;
 
-                                                       e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/, 
+                                                       e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
                                                                "&amp;key=" + new_link);
 
-                                                       e.href = e.href.replace(/\&amp;key=.*$/,
-                                                               "&amp;key=" + new_link);
+                                                       e.href = e.href.replace(/\&key=.*$/,
+                                                               "&key=" + new_link);
 
                                                        new Effect.Highlight(e);
 
                                                        notify('');
-       
+
                                                } else {
                                                        notify_error("Could not change feed URL.");
                                                }
@@ -1395,7 +1229,7 @@ function genUrlChangeKey(feed, is_cat) {
 
 function labelSelectOnChange(elem) {
        try {
-               var value = elem[elem.selectedIndex].value;
+/*             var value = elem[elem.selectedIndex].value;
                var def = elem.getAttribute('default');
 
                if (value == "ADD_LABEL") {
@@ -1420,7 +1254,7 @@ function labelSelectOnChange(elem) {
                                                exception_error("addLabel", e);
                                        }
                        });
-               }
+               } */
 
        } catch (e) {
                exception_error("labelSelectOnChange", e);
@@ -1477,7 +1311,7 @@ function selectTableRows(id, mode) {
                                for (var j = 0; j < inputs.length; j++) {
                                        var input = inputs[j];
 
-                                       if (input.getAttribute("type") == "checkbox" && 
+                                       if (input.getAttribute("type") == "checkbox" &&
                                                        input.id.match(bare_id)) {
 
                                                cb = input;
@@ -1534,3 +1368,295 @@ function getSelectedTableRowIds(id) {
        return rows;
 }
 
+function editFeed(feed, event) {
+       try {
+               if (feed <= 0)
+                       return alert(__("You can't edit this kind of feed."));
+
+               var query = "backend.php?op=pref-feeds&subop=editfeed&id=" +
+                       param_escape(feed);
+
+               console.log(query);
+
+               if (dijit.byId("feedEditDlg"))
+                       dijit.byId("feedEditDlg").destroyRecursive();
+
+               dialog = new dijit.Dialog({
+                       id: "feedEditDlg",
+                       title: __("Edit Feed"),
+                       style: "width: 600px",
+                       execute: function() {
+                               if (this.validate()) {
+//                                     console.log(dojo.objectToQuery(this.attr('value')));
+
+                                       notify_progress("Saving data...", true);
+
+                                       new Ajax.Request("backend.php", {
+                                               parameters: dojo.objectToQuery(dialog.attr('value')),
+                                               onComplete: function(transport) {
+                                                       dialog.hide();
+                                                       notify('');
+                                                       updateFeedList();
+                                       }})
+                               }
+                       },
+                       href: query});
+
+               dialog.show();
+
+       } catch (e) {
+               exception_error("editFeed", e);
+       }
+}
+
+function feedBrowser() {
+       try {
+               var query = "backend.php?op=dlg&id=feedBrowser";
+
+               if (dijit.byId("feedAddDlg"))
+                       dijit.byId("feedAddDlg").hide();
+
+               if (dijit.byId("feedBrowserDlg"))
+                       dijit.byId("feedBrowserDlg").destroyRecursive();
+
+               var dialog = new dijit.Dialog({
+                       id: "feedBrowserDlg",
+                       title: __("More Feeds"),
+                       style: "width: 600px",
+                       getSelectedFeedIds: function() {
+                               var list = $$("#browseFeedList li[id*=FBROW]");
+                               var selected = new Array();
+
+                               list.each(function(child) {
+                                       var id = child.id.replace("FBROW-", "");
+
+                                       if (child.hasClassName('Selected')) {
+                                               selected.push(id);
+                                       }
+                               });
+
+                               return selected;
+                       },
+                       getSelectedFeeds: function() {
+                               var list = $$("#browseFeedList li.Selected");
+                               var selected = new Array();
+
+                               list.each(function(child) {
+                                       var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
+                                       var url = child.getElementsBySelector("a.fb_feedUrl")[0].href;
+
+                                       selected.push([title,url]);
+
+                               });
+
+                               return selected;
+                       },
+
+                       subscribe: function() {
+                               var mode = this.attr('value').mode;
+                               var selected = [];
+
+                               if (mode == "1")
+                                       selected = this.getSelectedFeeds();
+                               else
+                                       selected = this.getSelectedFeedIds();
+
+                               if (selected.length > 0) {
+                                       dijit.byId("feedBrowserDlg").hide();
+
+                                       notify_progress("Loading, please wait...", true);
+
+                                       // we use dojo.toJson instead of JSON.stringify because
+                                       // it somehow escapes everything TWICE, at least in Chrome 9
+
+                                       var query = "?op=rpc&subop=massSubscribe&payload="+
+                                               param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode);
+
+                                       console.log(query);
+
+                                       new Ajax.Request("backend.php", {
+                                               parameters: query,
+                                               onComplete: function(transport) {
+                                                       notify('');
+                                                       updateFeedList();
+                                               } });
+
+                               } else {
+                                       alert(__("No feeds are selected."));
+                               }
+
+                       },
+                       update: function() {
+                               var query = dojo.objectToQuery(dialog.attr('value'));
+
+                               Element.show('feed_browser_spinner');
+
+                               new Ajax.Request("backend.php", {
+                                       parameters: query,
+                                       onComplete: function(transport) {
+                                               notify('');
+
+                                               Element.hide('feed_browser_spinner');
+
+                                               var c = $("browseFeedList");
+
+                                               var reply = JSON.parse(transport.responseText);
+
+                                               var r = reply['content'];
+                                               var mode = reply['mode'];
+
+                                               if (c && r) {
+                                                       c.innerHTML = r;
+                                               }
+
+                                               dojo.parser.parse("browseFeedList");
+
+                                               if (mode == 2) {
+                                                       Element.show(dijit.byId('feed_archive_remove').domNode);
+                                               } else {
+                                                       Element.hide(dijit.byId('feed_archive_remove').domNode);
+                                               }
+
+                                       } });
+                       },
+                       removeFromArchive: function() {
+                               var selected = this.getSelectedFeeds();
+
+                               if (selected.length > 0) {
+
+                                       var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
+
+                                       if (confirm(pr)) {
+                                               Element.show('feed_browser_spinner');
+
+                                               var query = "?op=rpc&subop=remarchived&ids=" +
+                                                       param_escape(selected.toString());;
+
+                                               new Ajax.Request("backend.php", {
+                                                       parameters: query,
+                                                       onComplete: function(transport) {
+                                                               dialog.update();
+                                                       } });
+                                       }
+                               }
+                       },
+                       execute: function() {
+                               if (this.validate()) {
+                                       this.subscribe();
+                               }
+                       },
+                       href: query});
+
+               dialog.show();
+
+       } catch (e) {
+               exception_error("editFeed", e);
+       }
+}
+
+function showFeedsWithErrors() {
+       try {
+               var query = "backend.php?op=dlg&id=feedsWithErrors";
+
+               if (dijit.byId("errorFeedsDlg"))
+                       dijit.byId("errorFeedsDlg").destroyRecursive();
+
+               dialog = new dijit.Dialog({
+                       id: "errorFeedsDlg",
+                       title: __("Feeds with update errors"),
+                       style: "width: 600px",
+                       getSelectedFeeds: function() {
+                               return getSelectedTableRowIds("prefErrorFeedList");
+                       },
+                       removeSelected: function() {
+                               var sel_rows = this.getSelectedFeeds();
+
+                               console.log(sel_rows);
+
+                               if (sel_rows.length > 0) {
+                                       var ok = confirm(__("Remove selected feeds?"));
+
+                                       if (ok) {
+                                               notify_progress("Removing selected feeds...", true);
+
+                                               var query = "?op=pref-feeds&subop=remove&ids="+
+                                                       param_escape(sel_rows.toString());
+
+                                               new Ajax.Request("backend.php", {
+                                                       parameters: query,
+                                                       onComplete: function(transport) {
+                                                               notify('');
+                                                               dialog.hide();
+                                                               updateFeedList();
+                                                       } });
+                                       }
+
+                               } else {
+                                       alert(__("No feeds are selected."));
+                               }
+                       },
+                       execute: function() {
+                               if (this.validate()) {
+                               }
+                       },
+                       href: query});
+
+               dialog.show();
+
+       } catch (e) {
+               exception_error("showFeedsWithErrors", e);
+       }
+
+}
+
+/* new support functions for SelectByTag */
+
+function get_all_tags(selObj){
+       try {
+               if( !selObj ) return "";
+
+               var result = "";
+               var len = selObj.options.length;
+
+               for (var i=0; i < len; i++){
+                       if (selObj.options[i].selected) {
+                               result += selObj[i].value + "%2C";   // is really a comma
+                       }
+               }
+
+               if (result.length > 0){
+                       result = result.substr(0, result.length-3);  // remove trailing %2C
+               }
+
+               return(result);
+
+       } catch (e) {
+               exception_error("get_all_tags", e);
+       }
+}
+
+function get_radio_checked(radioObj) {
+       try {
+               if (!radioObj) return "";
+
+               var len = radioObj.length;
+
+               if (len == undefined){
+                       if(radioObj.checked){
+                               return(radioObj.value);
+                       } else {
+                               return("");
+                       }
+               }
+
+               for( var i=0; i < len; i++ ){
+                       if( radioObj[i].checked ){
+                               return( radioObj[i].value);
+                       }
+               }
+
+       } catch (e) {
+               exception_error("get_radio_checked", e);
+       }
+       return("");
+}