]> git.wh0rd.org - tt-rss.git/blobdiff - js/functions.js
pass several image files used in notify messages to frontend as base64 to prevent...
[tt-rss.git] / js / functions.js
old mode 100644 (file)
new mode 100755 (executable)
index 8e56949..e29a834
@@ -212,15 +212,15 @@ function notify_real(msg, no_hide, n_type) {
        msg = "<span class=\"msg\"> " + __(msg) + "</span>";
 
        if (n_type == 2) {
-               msg = "<span><img src='images/indicator_white.gif'></span>" + msg;
+               msg = "<span><img src=\""+getInitParam("icon_indicator_white")+"\"></span>" + msg;
                no_hide = true;
        } else if (n_type == 3) {
-               msg = "<span><img src='images/alert.png'></span>" + msg;
+               msg = "<span><img src=\""+getInitParam("icon_alert")+"\"></span>" + msg;
        } else if (n_type == 4) {
-               msg = "<span><img src='images/information.png'></span>" + msg;
+               msg = "<span><img src=\""+getInitParam("icon_information")+"\"></span>" + msg;
        }
 
-       msg += " <span><img src=\"images/cross.png\" class=\"close\" title=\"" +
+       msg += " <span><img src=\""+getInitParam("icon_cross")+"\" class=\"close\" title=\"" +
                __("Click to close") + "\" onclick=\"notify('')\"></span>";
 
        n.innerHTML = msg;
@@ -668,7 +668,7 @@ function hotkey_prefix_timeout() {
                        Element.hide('cmdline');
                }
 
-               setTimeout("hotkey_prefix_timeout()", 1000);
+               setTimeout(hotkey_prefix_timeout, 1000);
 
        } catch  (e) {
                exception_error("hotkey_prefix_timeout", e);
@@ -804,6 +804,15 @@ function quickAddFeed() {
                        id: "feedAddDlg",
                        title: __("Subscribe to Feed"),
                        style: "width: 600px",
+                       show_error: function(msg) {
+                               var elem = $("fadd_error_message");
+
+                               elem.innerHTML = msg;
+
+                               if (!Element.visible(elem))
+                                       new Effect.Appear(elem);
+
+                       },
                        execute: function() {
                                if (this.validate()) {
                                        console.log(dojo.objectToQuery(this.attr('value')));
@@ -811,6 +820,7 @@ function quickAddFeed() {
                                        var feed_url = this.attr('value').feed;
 
                                        Element.show("feed_add_spinner");
+                                       Element.hide("fadd_error_message");
 
                                        new Ajax.Request("backend.php", {
                                                parameters: dojo.objectToQuery(this.attr('value')),
@@ -841,10 +851,10 @@ function quickAddFeed() {
                                                                        updateFeedList();
                                                                        break;
                                                                case 2:
-                                                                       alert(__("Specified URL seems to be invalid."));
+                                                                       dialog.show_error(__("Specified URL seems to be invalid."));
                                                                        break;
                                                                case 3:
-                                                                       alert(__("Specified URL doesn't seem to contain any feeds."));
+                                                                       dialog.show_error(__("Specified URL doesn't seem to contain any feeds."));
                                                                        break;
                                                                case 4:
                                                                        feeds = rc['feeds'];
@@ -868,16 +878,16 @@ function quickAddFeed() {
 
                                                                        break;
                                                                case 5:
-                                                                       alert(__("Couldn't download the specified URL: %s").
+                                                                       dialog.show_error(__("Couldn't download the specified URL: %s").
                                                                                        replace("%s", rc['message']));
                                                                        break;
                                                                case 6:
-                                                                       alert(__("XML validation failed: %s").
+                                                                       dialog.show_error(__("XML validation failed: %s").
                                                                                        replace("%s", rc['message']));
                                                                        break;
                                                                        break;
                                                                case 0:
-                                                                       alert(__("You are already subscribed to this feed."));
+                                                                       dialog.show_error(__("You are already subscribed to this feed."));
                                                                        break;
                                                                }
 
@@ -901,7 +911,7 @@ function createNewRuleElement(parentNode, replaceNode) {
        try {
                var form = document.forms["filter_new_rule_form"];
 
-               form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
+               //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
 
                var query = "backend.php?op=pref-filters&method=printrulename&rule="+
                        param_escape(dojo.formToJson(form));
@@ -1051,6 +1061,100 @@ function addFilterAction(replaceNode, actionStr) {
        }
 }
 
+function editFilterTest(query) {
+       try {
+
+               if (dijit.byId("filterTestDlg"))
+                       dijit.byId("filterTestDlg").destroyRecursive();
+
+               var test_dlg = new dijit.Dialog({
+                       id: "filterTestDlg",
+                       title: "Test Filter",
+                       style: "width: 600px",
+                       results: 0,
+                       limit: 100,
+                       max_offset: 10000,
+                       getTestResults: function(query, offset) {
+                               var updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit;
+
+                               console.log("getTestResults:" + offset);
+
+                               new Ajax.Request("backend.php", {
+                                       parameters: updquery,
+                                       onComplete: function (transport) {
+                                               try {
+                                                       var result = JSON.parse(transport.responseText);
+
+                                                       if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
+                                                               test_dlg.results += result.size();
+
+                                                               console.log("got results:" + result.size());
+
+                                                               $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
+                                                                       .replace("%f", test_dlg.results)
+                                                                       .replace("%d", offset);
+
+                                                               console.log(offset + " " + test_dlg.max_offset);
+
+                                                               for (var i = 0; i < result.size(); i++) {
+                                                                       var tmp = new Element("table");
+                                                                       tmp.innerHTML = result[i];
+                                                                       dojo.parser.parse(tmp);
+
+                                                                       $("prefFilterTestResultList").innerHTML += tmp.innerHTML;
+                                                               }
+
+                                                               if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
+
+                                                                       // get the next batch
+                                                                       window.setTimeout(function () {
+                                                                               test_dlg.getTestResults(query, offset + test_dlg.limit);
+                                                                       }, 0);
+
+                                                               } else {
+                                                                       // all done
+
+                                                                       Element.hide("prefFilterLoadingIndicator");
+
+                                                                       if (test_dlg.results == 0) {
+                                                                               $("prefFilterTestResultList").innerHTML = "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
+                                                                               $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:";
+                                                                       } else {
+                                                                               $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:")
+                                                                                       .replace("%d", test_dlg.results);
+                                                                       }
+
+                                                               }
+
+                                                       } else if (!result) {
+                                                               console.log("getTestResults: can't parse results object");
+
+                                                               Element.hide("prefFilterLoadingIndicator");
+
+                                                               notify_error("Error while trying to get filter test results.");
+
+                                                       } else {
+                                                               console.log("getTestResults: dialog closed, bailing out.");
+                                                       }
+                                               } catch (e) {
+                                                       exception_error("editFilterTest/inner", e);
+                                               }
+
+                                       } });
+                       },
+                       href: query});
+
+               dojo.connect(test_dlg, "onLoad", null, function(e) {
+                       test_dlg.getTestResults(query, 0);
+               });
+
+               test_dlg.show();
+
+       } catch (e) {
+               exception_error("editFilterTest", e);
+       }
+}
+
 function quickAddFilter() {
        try {
                var query = "";
@@ -1077,16 +1181,7 @@ function quickAddFilter() {
                        test: function() {
                                var query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test";
 
-                               if (dijit.byId("filterTestDlg"))
-                                       dijit.byId("filterTestDlg").destroyRecursive();
-
-                               var test_dlg = new dijit.Dialog({
-                                       id: "filterTestDlg",
-                                       title: "Test Filter",
-                                       style: "width: 600px",
-                                       href: query});
-
-                               test_dlg.show();
+                               editFilterTest(query);
                        },
                        selectRules: function(select) {
                                $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
@@ -1240,7 +1335,7 @@ function unsubscribeFeed(feed_id, title) {
                                                updateFeedList();
                                        } else {
                                                if (feed_id == getActiveFeedId())
-                                                       setTimeout("viewfeed({feed:-5})", 100);
+                                                       setTimeout(function() { viewfeed({feed:-5}) }, 100);
 
                                                if (feed_id < 0) updateFeedList();
                                        }
@@ -1968,3 +2063,18 @@ function getSelectionText() {
 
        return text.stripTags();
 }
+
+function openUrlPopup(url) {
+       var w = window.open("");
+
+       w.opener = null;
+       w.location = url;
+}
+function openArticlePopup(id) {
+       var w = window.open("",
+               "ttrss_article_popup",
+               "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
+
+       w.opener = null;
+       w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + getInitParam("csrf_token");
+}
\ No newline at end of file