]> git.wh0rd.org - tt-rss.git/blobdiff - functions.js
rework loading progressbar
[tt-rss.git] / functions.js
index 2e7412c239cef75a668caec6bbdbe6b0f209841f..48a9ef230fed360a1fd0a13ad28d2b76cbd44e66 100644 (file)
@@ -1,6 +1,6 @@
 var hotkeys_enabled = true;
 var notify_silent = false;
-var last_progress_point = 0;
+var loading_progress = 0;
 var sanity_check_done = false;
 
 /* add method to remove element from array */
@@ -23,42 +23,42 @@ function exception_error(location, e, ext_info) {
 
        if (!ext_info) ext_info = false;
 
-       disableHotkeys();
-
        try {
 
-               var ebc = $("xebContent");
-       
-               if (ebc) {
-       
-                       Element.show("dialog_overlay");
-                       Element.show("errorBoxShadow");
-       
-                       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>";
+               }
 
-                       if (ext_info) {
-                               ebc.innerHTML += "<div><b>Additional information:</b></div>" +
-                               "<textarea readonly=\"1\">" + ext_info + "</textarea>";
-                       }
+               var content = "<div class=\"fatalError\">" +
+                       "<pre>" + msg + "</pre>";
 
-                       ebc.innerHTML += "<div><b>Stack trace:</b></div>" +
-                               "<textarea readonly=\"1\">" + e.stack + "</textarea>";
-       
-               } else {
-                       alert(msg);
+               if (ext_info) {
+                       content += "<div><b>Additional information:</b></div>" +
+                       "<textarea readonly=\"1\">" + ext_info + "</textarea>";
                }
 
+               content += "<div><b>Stack trace:</b></div>" +
+                       "<textarea readonly=\"1\">" + e.stack + "</textarea>";
+
+//             content += "<div style='text-align : center'>" +
+//                     "<button onclick=\"closeInfoBox()\">" +
+//                     "Close this window" + "</button></div>";
+
+               content += "</div>";
+
+               // TODO: add code to automatically report errors to tt-rss.org
+
+               var dialog = new dijit.Dialog({
+                       title: "Unhandled exception",
+                       style: "width: 600px",
+                       content: content});
+
+               dialog.show();
+
        } catch (e) {
                alert(msg);
-
        }
 
 }
@@ -306,10 +306,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;
@@ -388,20 +406,16 @@ function closeErrorBox() {
 }
 
 function closeInfoBox(cleanup) {
-
        try {
                enableHotkeys();
 
-               if (Element.visible("infoBoxShadow")) {
-                       Element.hide("dialog_overlay");
-                       Element.hide("infoBoxShadow");
+               dialog = dijit.byId("infoBox");
+
+               if (dialog)     dialog.hide();
 
-                       if (cleanup) $("infoBox").innerHTML = "&nbsp;";
-               }
        } catch (e) {
-               exception_error("closeInfoBox", e);
+               //exception_error("closeInfoBox", e);
        }
-       
        return false;
 }
 
@@ -410,8 +424,6 @@ function displayDlg(id, param, callback) {
 
        notify_progress("Loading, please wait...", true);
 
-       disableHotkeys();
-
        var query = "?op=dlg&id=" +
                param_escape(id) + "&param=" + param_escape(param);
 
@@ -442,25 +454,54 @@ function infobox_submit_callback2(transport) {
 
 function infobox_callback2(transport) {
        try {
+               var dialog = false;
 
-               console.log("infobox_callback2");
+               if (dijit.byId("infoBox")) {
+                       dialog = dijit.byId("infoBox");
+               }
 
-               var box = $('infoBox');
-               
-               if (box) {                      
+               //console.log("infobox_callback2");
+               notify('');
 
-                       if (!getInitParam("infobox_disable_overlay")) {
-                               Element.show("dialog_overlay");
-                       }
+               var content;
+               var dtitle = "Dialog";
+
+               if (transport.responseXML) {
+                       var dlg = transport.responseXML.getElementsByTagName("dlg")[0];
 
-                       box.innerHTML=transport.responseText;                   
-                       Element.show("infoBoxShadow");
-                       //Effect.SlideDown("infoBoxShadow", {duration : 1.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;
+
+               } else {
+                       content = transport.responseText;
+               }
 
+               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 {
+                       dialog.attr('title', title);
+                       dialog.attr('content', content);
                }
 
-               disableHotkeys();
+               dialog.show();
 
                notify("");
        } catch (e) {
@@ -551,8 +592,6 @@ function subscribeToFeed() {
        new Ajax.Request("backend.php", {
                parameters: query,
                onComplete: function(transport) { 
-                       //dlg_frefresh_callback(transport); 
-
                        try {
 
                                if (!transport.responseXML) {
@@ -840,21 +879,13 @@ function displayHelpInfobox(topic_id) {
 
 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");
+               loading_progress += p;
 
-//             o.style.width = (p * 2) + "px";
+               if (dijit.byId("loading_bar"))
+                       dijit.byId("loading_bar").update({progress: loading_progress});
 
-               new Effect.Scale(o, p, { 
-                       scaleY : false,
-                       scaleFrom : last_progress_point,
-                       scaleMode: { originalWidth : 200 },
-                       queue: { position: 'end', scope: 'LSP-Q', limit: 3 } }); 
-
-               last_progress_point = p;
+               if (loading_progress >= 90)
+                       remove_splash();
 
        } catch (e) {
                exception_error("loading_set_progress", e);
@@ -862,6 +893,7 @@ function loading_set_progress(p) {
 }
 
 function remove_splash() {
+
        if (Element.visible("overlay")) {
                console.log("about to remove splash, OMG!");
                Element.hide("overlay");
@@ -871,22 +903,18 @@ function remove_splash() {
 
 function getSelectedFeedsFromBrowser() {
 
-       var list = $("browseFeedList");
+       var list = $$("#browseFeedList li[id*=FBROW]");
 
        var selected = new Array();
-       
-       for (i = 0; i < list.childNodes.length; i++) {
-               var child = list.childNodes[i];
-               if (child.id && child.id.match("FBROW-")) {
-                       var id = child.id.replace("FBROW-", "");
-                       
-                       var cb = $("FBCHK-" + id);
 
-                       if (cb.checked) {
-                               selected.push(id);
-                       }
-               }
-       }
+       list.each(function(child) {     
+               var id = child.id.replace("FBROW-", "");
+               var cb = $("FBCHK-" + id);
+
+               if (cb.checked) {
+                       selected.push(id);
+               }       
+       });
 
        return selected;
 }
@@ -1231,16 +1259,9 @@ function backend_sanity_check_callback(transport) {
                                fatalError(3, "Sanity check: Received reply is not XML", 
                                        transport.responseText);
                                return;
-                       } else {
-                               init_offline();
-                               return;
                        }
                }
 
-               if (getURLParam("offline")) {
-                       return init_offline();
-               }
-
                var reply = transport.responseXML.getElementsByTagName("error")[0];
 
                if (!reply) {
@@ -1265,16 +1286,8 @@ function backend_sanity_check_callback(transport) {
 
                        if (params) {
                                for (k in params) {
-       
                                        var v = params[k];
-       
                                        console.log("IP: " + k + " => " + v);
-
-                                       if (db) {
-                                               db.execute("DELETE FROM init_params WHERE key = ?", [k]);
-                                               db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
-                                                       [k, v]);
-                                       }
                                }
                        }