]> git.wh0rd.org Git - tt-rss.git/commitdiff
exception handling in some code blocks
authorAndrew Dolgov <fox@bah.spb.su>
Sat, 26 Nov 2005 10:06:56 +0000 (11:06 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sat, 26 Nov 2005 10:06:56 +0000 (11:06 +0100)
feedlist.js
functions.js
prefs.js
tt-rss.css
tt-rss.js

index e8d79c6ba4ecec14585af7f3569574e0d6281521..499705b634bca4560c0e618f88362be10179002c 100644 (file)
 
 function viewfeed(feed, skip, subop, doc) {
+       try {
 
-       if (!doc) doc = parent.document;
-
-//     p_notify("Loading headlines...");
-
-       enableHotkeys();
-
-       var searchbox = doc.getElementById("searchbox");
-
-       if (searchbox) {
-               search_query = searchbox.value;
-       } else {
-               search_query = "";
-       } 
-
-       var searchmodebox = doc.getElementById("searchmodebox");
-
-       var search_mode;
+               if (!doc) doc = parent.document;
        
-       if (searchmodebox) {
-               search_mode = searchmodebox[searchmodebox.selectedIndex].text;
-       } else {
-               search_mode = "";
-       }
-
-       setCookie("ttrss_vf_smode", search_mode);
-
-       var viewbox = doc.getElementById("viewbox");
-
-       var view_mode;
-
-       if (viewbox) {
-               view_mode = viewbox[viewbox.selectedIndex].text;
-       } else {
-               view_mode = "All Posts";
-       }
-
-       setCookie("ttrss_vf_vmode", view_mode);
-
-       var limitbox = doc.getElementById("limitbox");
-
-       var limit;
-
-       if (limitbox) {
-               limit = limitbox[limitbox.selectedIndex].text;
-               setCookie("ttrss_vf_limit", limit);
-       } else {
-               limit = "All";
-       }
-
-//     document.getElementById("ACTFEEDID").innerHTML = feed;
-
-       setActiveFeedId(feed);
-
-       if (subop == "MarkAllRead") {
-
-               var feedr = document.getElementById("FEEDR-" + feed);
-               var feedctr = document.getElementById("FEEDCTR-" + feed);
+               enableHotkeys();
        
-               feedctr.className = "invisible";
-
-               if (feedr.className.match("Unread")) {
-                       feedr.className = feedr.className.replace("Unread", "");
+               var searchbox = doc.getElementById("searchbox");
+       
+               if (searchbox) {
+                       search_query = searchbox.value;
+               } else {
+                       search_query = "";
+               } 
+       
+               var searchmodebox = doc.getElementById("searchmodebox");
+       
+               var search_mode;
+               
+               if (searchmodebox) {
+                       search_mode = searchmodebox[searchmodebox.selectedIndex].text;
+               } else {
+                       search_mode = "";
                }
-       }
-
-       var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
-               "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
-               "&view=" + param_escape(view_mode) + "&limit=" + limit + 
-               "&smode=" + param_escape(search_mode);
-
-       if (search_query != "") {
-               query = query + "&search=" + param_escape(search_query);
-       }
        
-       var headlines_frame = parent.frames["headlines-frame"];
-
-//     alert(headlines_frame)
-
-       headlines_frame.location.href = query + "&addheader=true";
-
-       cleanSelectedList("feedList");
-
-       var feedr = document.getElementById("FEEDR-" + feed);
-       if (feedr) {    
-               feedr.className = feedr.className + "Selected";
-       } 
+               setCookie("ttrss_vf_smode", search_mode);
        
-       disableContainerChildren("headlinesToolbar", false, doc);
-
-/*     var btnMarkAsRead = doc.getElementById("btnMarkFeedAsRead");
-
-       if (btnMarkAsRead && !isNumeric(feed)) {
-               btnMarkAsRead.disabled = true;
-               btnMarkAsRead.className = "disabledButton";
-       } */
-
-//     notify("");
-
+               var viewbox = doc.getElementById("viewbox");
+       
+               var view_mode;
+       
+               if (viewbox) {
+                       view_mode = viewbox[viewbox.selectedIndex].text;
+               } else {
+                       view_mode = "All Posts";
+               }
+       
+               setCookie("ttrss_vf_vmode", view_mode);
+       
+               var limitbox = doc.getElementById("limitbox");
+       
+               var limit;
+       
+               if (limitbox) {
+                       limit = limitbox[limitbox.selectedIndex].text;
+                       setCookie("ttrss_vf_limit", limit);
+               } else {
+                       limit = "All";
+               }
+       
+       //      document.getElementById("ACTFEEDID").innerHTML = feed;
+       
+               setActiveFeedId(feed);
+       
+               if (subop == "MarkAllRead") {
+       
+                       var feedr = document.getElementById("FEEDR-" + feed);
+                       var feedctr = document.getElementById("FEEDCTR-" + feed);
+               
+                       feedctr.className = "invisible";
+       
+                       if (feedr.className.match("Unread")) {
+                               feedr.className = feedr.className.replace("Unread", "");
+                       }
+               }
+       
+               var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
+                       "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
+                       "&view=" + param_escape(view_mode) + "&limit=" + limit + 
+                       "&smode=" + param_escape(search_mode);
+       
+               if (search_query != "") {
+                       query = query + "&search=" + param_escape(search_query);
+               }
+               
+               var headlines_frame = parent.frames["headlines-frame"];
+       
+       //      alert(headlines_frame)
+       
+               headlines_frame.location.href = query + "&addheader=true";
+       
+               cleanSelectedList("feedList");
+       
+               var feedr = document.getElementById("FEEDR-" + feed);
+               if (feedr) {    
+                       feedr.className = feedr.className + "Selected";
+               } 
+               
+               disableContainerChildren("headlinesToolbar", false, doc);
+       
+       /*      var btnMarkAsRead = doc.getElementById("btnMarkFeedAsRead");
+       
+               if (btnMarkAsRead && !isNumeric(feed)) {
+                       btnMarkAsRead.disabled = true;
+                       btnMarkAsRead.className = "disabledButton";
+               } */
+       
+       //      notify("");
+       } catch (e) {
+               exception_error("viewfeed", e);
+       }               
 }
 
 function localHotkeyHandler(keycode) {
index d236c4e18f7dca1134024aa86cc472fab0b1bf0d..36aa8fd6a7c1abab32d65e32156281708f7eeddc 100644 (file)
@@ -1,5 +1,10 @@
 var hotkeys_enabled = true;
 
+function exception_error(location, e) {
+       alert("Exception: " + e.name + "\nMessage: " + e.message + 
+               "\nLocation: " + location);
+}
+
 function disableHotkeys() {
        hotkeys_enabled = false;
 }
@@ -330,48 +335,51 @@ if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
 
 function all_counters_callback() {
        if (xmlhttp_rpc.readyState == 4) {
-
-               if (!xmlhttp_rpc.responseXML) {
-                       notify("[all_counters_callback] backend did not return valid XML");
-                       return;
-               }
-
-               var reply = xmlhttp_rpc.responseXML.firstChild;
-
-               var f_document = parent.frames["feeds-frame"].document;
-
-               for (var l = 0; l < reply.childNodes.length; l++) {
-                       var id = reply.childNodes[l].getAttribute("id");
-                       var ctr = reply.childNodes[l].getAttribute("counter");
-
-                       var feedctr = f_document.getElementById("FEEDCTR-" + id);
-                       var feedu = f_document.getElementById("FEEDU-" + id);
-                       var feedr = f_document.getElementById("FEEDR-" + id);
-
-                       if (feedctr && feedu && feedr) {
-
-                               feedu.innerHTML = ctr;
+               try {
+                       if (!xmlhttp_rpc.responseXML) {
+                               notify("[all_counters_callback] backend did not return valid XML");
+                               return;
+                       }
+       
+                       var reply = xmlhttp_rpc.responseXML.firstChild;
+       
+                       var f_document = parent.frames["feeds-frame"].document;
+       
+                       for (var l = 0; l < reply.childNodes.length; l++) {
+                               var id = reply.childNodes[l].getAttribute("id");
+                               var ctr = reply.childNodes[l].getAttribute("counter");
+       
+                               var feedctr = f_document.getElementById("FEEDCTR-" + id);
+                               var feedu = f_document.getElementById("FEEDU-" + id);
+                               var feedr = f_document.getElementById("FEEDR-" + id);
+       
+                               if (feedctr && feedu && feedr) {
+       
+                                       feedu.innerHTML = ctr;
+               
+                                       if (ctr > 0) {
+                                               feedctr.className = "odd";
+                                               if (!feedr.className.match("Unread")) {
+                                                       var is_selected = feedr.className.match("Selected");
+       
+                                                       feedr.className = feedr.className.replace("Selected", "");
+                                                       feedr.className = feedr.className.replace("Unread", "");
+       
+                                                       feedr.className = feedr.className + "Unread";
+       
+                                                       if (is_selected) {
+                                                               feedr.className = feedr.className + "Selected";
+                                                       }
        
-                               if (ctr > 0) {
-                                       feedctr.className = "odd";
-                                       if (!feedr.className.match("Unread")) {
-                                               var is_selected = feedr.className.match("Selected");
-
-                                               feedr.className = feedr.className.replace("Selected", "");
-                                               feedr.className = feedr.className.replace("Unread", "");
-
-                                               feedr.className = feedr.className + "Unread";
-
-                                               if (is_selected) {
-                                                       feedr.className = feedr.className + "Selected";
                                                }
-
-                                       }
-                               } else {
-                                       feedctr.className = "invisible";
-                                       feedr.className = feedr.className.replace("Unread", "");
-                               }                       
+                                       } else {
+                                               feedctr.className = "invisible";
+                                               feedr.className = feedr.className.replace("Unread", "");
+                                       }                       
+                               }
                        }
+               } catch (e) {
+                       exception_error("all_counters_callback", e);
                }
        }
 }
@@ -506,4 +514,3 @@ function getSelectedTableRowIds(content_id, prefix) {
 
 }
 
-
index 404602c33b9b2aa635b54a331446d01fa1ce7b58..b69369ba1fa05acbdcb3f628d22c2fe52e92fdcb 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -28,8 +28,8 @@ if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 }
 
 function feedlist_callback() {
-       var container = document.getElementById('prefContent');
        if (xmlhttp.readyState == 4) {
+               var container = document.getElementById('prefContent'); 
                container.innerHTML=xmlhttp.responseText;
                if (active_feed) {
                        var row = document.getElementById("FEEDR-" + active_feed);
@@ -1146,45 +1146,25 @@ function selectTab(id) {
 
 function init() {
 
-       // IE kludge
-
-       if (!xmlhttp) {
-               document.getElementById("prefContent").innerHTML = 
-                       "<b>Fatal error:</b> This program needs XmlHttpRequest " + 
-                       "to function properly. Your browser doesn't seem to support it.";
-               return;
+       try {
+       
+               // IE kludge
+               if (!xmlhttp) {
+                       document.getElementById("prefContent").innerHTML = 
+                               "<b>Fatal error:</b> This program needs XmlHttpRequest " + 
+                               "to function properly. Your browser doesn't seem to support it.";
+                       return;
+               }
+       
+               selectTab("genConfig");
+       
+               document.onkeydown = hotkey_handler;
+               notify("");
+       } catch (e) {
+               exception_error("init", e);
        }
-
-       selectTab("genConfig");
-
-       document.onkeydown = hotkey_handler;
-       notify("");
-
 }
 
-/*
-var help_topic_id = false;
-
-function do_dispOptionHelp() {
-
-       if (!xmlhttp_ready(xmlhttp))
-               return;
-
-       xmlhttp.open("GET", "backend.php?op=pref-prefs&subop=getHelp&pn=" +
-               param_escape(help_topic_id), true);
-       xmlhttp.onreadystatechange=gethelp_callback;
-       xmlhttp.send(null);
-
-}
-
-function dispOptionHelp(event, sender) {
-
-       help_topic_id = sender.id;
-
-//     document.setTimeout("do_dispOptionHelp()", 100);
-
-} */
-
 function closeInfoBox() {
        var box = document.getElementById('infoBox');
        var shadow = document.getElementById('infoBoxShadow');
index e4699f343ecaf323c36ff2cc88c61495cb1de3dd..78a7a8d033b0fae5bd4edd1ee7e1a08e97da4f90 100644 (file)
@@ -386,13 +386,10 @@ a.button {
        font-weight : bold;
 }
 
-.evenSelected {
+.evenSelected, .oddSelected {
        background-color : #e0e0ff;
 }
 
-.oddSelected {
-       background-color : #e0e0ff;
-} 
 
 /*
 .feedUnreadSelected, .feedSelectedUnread, 
index 0af11bfca9d9a4e40e3f8b109c30f64a9ff32eac..94aad44d0677e5ba19a55e1b9a741e9823e11fc4 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -62,108 +62,99 @@ function dialog_refresh_callback() {
 
 function refetch_callback() {
        if (xmlhttp.readyState == 4) {
+               try {
 
-//             document.title = "Tiny Tiny RSS";
-
-               if (!xmlhttp.responseXML) {
-                       notify("refetch_callback: backend did not return valid XML");
-                       return;
-               }
+                       if (!xmlhttp.responseXML) {
+                               notify("refetch_callback: backend did not return valid XML");
+                               return;
+                       }
+               
+                       var reply = xmlhttp.responseXML.firstChild;
        
-               var reply = xmlhttp.responseXML.firstChild;
-
-               if (!reply) {
-                       notify("refetch_callback: backend did not return expected XML object");
-                       return;
-               } 
-
-               var error_code = reply.getAttribute("error-code");
+                       if (!reply) {
+                               notify("refetch_callback: backend did not return expected XML object");
+                               return;
+                       } 
        
-               if (error_code && error_code != 0) {
-                       return fatalError(error_code);
-               }
-
-               var f_document = window.frames["feeds-frame"].document;
-
-               for (var l = 0; l < reply.childNodes.length; l++) {
-                       var id = reply.childNodes[l].getAttribute("id");
-                       var ctr = reply.childNodes[l].getAttribute("counter");
-
-                       var feedctr = f_document.getElementById("FEEDCTR-" + id);
-                       var feedu = f_document.getElementById("FEEDU-" + id);
-                       var feedr = f_document.getElementById("FEEDR-" + id);
-
-/*                     TODO figure out how to update this from viewfeed.js->view()
-                       disabled for now...
-
-                       if (id == "global-unread") {
-                               global_unread = ctr;
-                       } */
-
-                       if (feedctr && feedu && feedr) {
-
-                               feedu.innerHTML = ctr;
+                       var error_code = reply.getAttribute("error-code");
+               
+                       if (error_code && error_code != 0) {
+                               return fatalError(error_code);
+                       }
+       
+                       var f_document = window.frames["feeds-frame"].document;
        
-                               if (ctr > 0) {
-                                       feedctr.className = "odd";
-                                       if (!feedr.className.match("Unread")) {
-                                               feedr.className = feedr.className + "Unread";
+                       for (var l = 0; l < reply.childNodes.length; l++) {
+                               var id = reply.childNodes[l].getAttribute("id");
+                               var ctr = reply.childNodes[l].getAttribute("counter");
+       
+                               var feedctr = f_document.getElementById("FEEDCTR-" + id);
+                               var feedu = f_document.getElementById("FEEDU-" + id);
+                               var feedr = f_document.getElementById("FEEDR-" + id);
+       
+       /*                      TODO figure out how to update this from viewfeed.js->view()
+                               disabled for now...
+       
+                               if (id == "global-unread") {
+                                       global_unread = ctr;
+                               } */
+       
+                               if (feedctr && feedu && feedr) {
+       
+                                       feedu.innerHTML = ctr;
+               
+                                       if (ctr > 0) {
+                                               feedctr.className = "odd";
+                                               if (!feedr.className.match("Unread")) {
+                                                       feedr.className = feedr.className + "Unread";
+                                               }
+                                       } else {
+                                               feedctr.className = "invisible";
+                                               feedr.className = feedr.className.replace("Unread", "");
                                        }
-                               } else {
-                                       feedctr.className = "invisible";
-                                       feedr.className = feedr.className.replace("Unread", "");
                                }
-                       }
-               }  
-
-               updateTitle("");
-               notify("All feeds updated.");
-
+                       }  
+       
+                       updateTitle("");
+                       notify("All feeds updated.");
+               } catch (e) {
+                       exception_error("refetch_callback", e);
+               }
        }
 }
 
 function backend_sanity_check_callback() {
 
        if (xmlhttp.readyState == 4) {
-               
-               if (!xmlhttp.responseXML) {
-                       fatalError(3);
-                       return;
-               }
-
-               var reply = xmlhttp.responseXML.firstChild;
-
-               if (!reply) {
-                       fatalError(3);
-                       return;
-               }
 
-               var error_code = reply.getAttribute("error-code");
+               try {
+               
+                       if (!xmlhttp.responseXML) {
+                               fatalError(3);
+                               return;
+                       }
        
-               if (error_code && error_code != 0) {
-                       return fatalError(error_code);
-               }
+                       var reply = xmlhttp.responseXML.firstChild;
+       
+                       if (!reply) {
+                               fatalError(3);
+                               return;
+                       }
+       
+                       var error_code = reply.getAttribute("error-code");
+               
+                       if (error_code && error_code != 0) {
+                               return fatalError(error_code);
+                       }
+       
+                       init_second_stage();
 
-               init_second_stage();
+               } catch (e) {
+                       exception_error("backend_sanity_check_callback", e);
+               }
        } 
 }
 
-/* wtf this is obsolete
-function updateFeed(feed_id) {
-
-       var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
-
-       if (xmlhttp_ready(xmlhttp)) {
-               xmlhttp.open("GET", query_str, true);
-               xmlhttp.onreadystatechange=feed_update_callback;
-               xmlhttp.send(null);
-       } else {
-               printLockingError();
-       }   
-
-}
-*/
-
 function scheduleFeedUpdate(force) {
 
        notify("Updating feeds in background...");
@@ -343,71 +334,63 @@ function genericSanityCheck() {
                fatalError(2);
        }
 
-/*     if (!xmlhttp) {
-               document.getElementById("headlines").innerHTML = 
-                       "<b>Fatal error:</b> This program requires XmlHttpRequest " + 
-                       "to function properly. Your browser doesn't seem to support it.";
-               return false;
-       }
-
-       setCookie("ttrss_vf_test", "TEST");
-       if (getCookie("ttrss_vf_test") != "TEST") {
-
-               document.getElementById("headlines").innerHTML = 
-                       "<b>Fatal error:</b> This program requires cookies " + 
-                       "to function properly. Your browser doesn't seem to support them.";
-
-               return false;
-       } */
-
        return true;
 }
 
 function init() {
 
-       disableContainerChildren("headlinesToolbar", true);
-
-       if (!genericSanityCheck()) 
-               return;
-
-       xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
-       xmlhttp.onreadystatechange=backend_sanity_check_callback;
-       xmlhttp.send(null);
-
-}
-
-function init_second_stage() {
-
-       setCookie("ttrss_vf_actfeed", "");
+       try {
 
-       updateFeedList(false, false);
-       document.onkeydown = hotkey_handler;
+               disableContainerChildren("headlinesToolbar", true);
 
-       var content = document.getElementById("content");
+               if (!genericSanityCheck()) 
+                       return;
 
-       if (getCookie("ttrss_vf_vmode")) {
-               var viewbox = document.getElementById("viewbox");
-               viewbox.value = getCookie("ttrss_vf_vmode");
-       }
+               xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
+               xmlhttp.onreadystatechange=backend_sanity_check_callback;
+               xmlhttp.send(null);
 
-       if (getCookie("ttrss_vf_limit")) {
-               var limitbox = document.getElementById("limitbox");
-               limitbox.value = getCookie("ttrss_vf_limit");
+       } catch (e) {
+               exception_error("init", e);
        }
+}
 
-//     if (getCookie("ttrss_vf_actfeed")) {
-//             viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
-//     }
-
-//     setTimeout("timeout()", 2*1000);
-//     scheduleFeedUpdate(true);
+function init_second_stage() {
 
-       var splash = document.getElementById("splash");
+       try {
 
-       if (splash) {
-               splash.style.display = "none";
+               setCookie("ttrss_vf_actfeed", "");
+       
+               updateFeedList(false, false);
+               document.onkeydown = hotkey_handler;
+       
+               var content = document.getElementById("content");
+       
+               if (getCookie("ttrss_vf_vmode")) {
+                       var viewbox = document.getElementById("viewbox");
+                       viewbox.value = getCookie("ttrss_vf_vmode");
+               }
+       
+               if (getCookie("ttrss_vf_limit")) {
+                       var limitbox = document.getElementById("limitbox");
+                       limitbox.value = getCookie("ttrss_vf_limit");
+               }
+       
+       //      if (getCookie("ttrss_vf_actfeed")) {
+       //              viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
+       //      }
+       
+       //      setTimeout("timeout()", 2*1000);
+       //      scheduleFeedUpdate(true);
+       
+               var splash = document.getElementById("splash");
+       
+               if (splash) {
+                       splash.style.display = "none";
+               }
+       } catch (e) {
+               exception_error("init_second_stage", e);
        }
-
 }
 
 function quickMenuGo() {