]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
add net-alert icon
[tt-rss.git] / js / viewfeed.js
index c55b5ccd9ad8faa971473e3a07cc68fb12b7891e..d6801a186a1e8a201e63a91397d26d9a785b7311 100644 (file)
@@ -13,6 +13,7 @@ var feed_precache_timeout_id = false;
 var precache_idle_timeout_id = false;
 
 var cids_requested = [];
+var loaded_article_ids = [];
 
 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
 
@@ -78,6 +79,8 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        //var runtime_info = reply['runtime-info'];
 
                        if (offset == 0 && infscroll_req == false) {
+                               loaded_article_ids = [];
+
                                dijit.byId("headlines-frame").attr('content',
                                        reply['headlines']['content']);
 
@@ -85,8 +88,10 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                        reply['headlines']['toolbar']);
 
                                $$("#headlines-frame > div[id*=RROW]").each(function(row) {
-                                       if ($$("#headlines-frame DIV[id="+row.id+"]").length > 1) {
+                                       if (loaded_article_ids.indexOf(row.id) != -1) {
                                                row.parentNode.removeChild(row);
+                                       } else {
+                                               loaded_article_ids.push(row.id);
                                        }
                                });
 
@@ -98,6 +103,12 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                initHeadlinesMenu();
 
+                               if (_search_query) {
+                                       $("feed_title").innerHTML += "<span id='cancel_search'>" +
+                                               " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
+                                               "</span>";
+                               }
+
                        } else {
 
                                if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
@@ -105,7 +116,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                        var c = dijit.byId("headlines-frame");
                                        var ids = getSelectedArticleIds2();
-                                       var num_added = 0;
+                                       var new_elems = [];
 
                                        $("headlines-tmp").innerHTML = reply['headlines']['content'];
 
@@ -116,15 +127,14 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                        $$("#headlines-tmp > div").each(function(row) {
                                                if (row.className == 'cdmFeedTitle') {
-                                                       row.addClassName('new');
                                                        row.style.display = 'none';
                                                        c.domNode.appendChild(row);
-                                                       ++num_added;
-                                               } else if ($$("#headlines-frame DIV[id="+row.id+"]").length == 0) {
+                                                       new_elems.push(row);
+                                               } else if (loaded_article_ids.indexOf(row.id) == -1) {
                                                        row.style.display = 'none';
-                                                       row.addClassName('new');
                                                        c.domNode.appendChild(row);
-                                                       ++num_added;
+                                                       new_elems.push(row);
+                                                       loaded_article_ids.push(row.id);
                                                } else {
                                                        row.parentNode.removeChild(row);
                                                }
@@ -138,9 +148,9 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                                c.domNode.appendChild(hsp);
                                        }
 
-                                       console.log("added " + num_added + " headlines");
+                                       console.log("added " + new_elems.size() + " headlines");
 
-                                       if (num_added == 0)
+                                       if (new_elems.size() == 0)
                                                _infscroll_disable = true;
 
                                        console.log("restore selected ids: " + ids);
@@ -151,11 +161,17 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                        initHeadlinesMenu();
 
-                                       $$("#headlines-frame > div[class*=new]").each(
-                                       function(child) {
-                                               child.removeClassName('new');
-                                               if (!Element.visible(child))
-                                                       new Effect.Appear(child, { duration : 0.5 });
+                                       new_elems.each(function(child) {
+                                               var cb = dijit.byId(child.id.replace("RROW-", "RCHK-"));
+
+                                               if (!cb) {
+                                                       dojo.parser.parse(child);
+
+                                                       if (!Element.visible(child))
+                                                               new Effect.Appear(child, { duration : 0.5 });
+                                               } else {
+                                                       c.domNode.removeChild(child);
+                                               }
                                        });
 
                                } else {
@@ -188,11 +204,14 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        else
                                request_counters();
 
-               } else {
+               } else if (transport.responseText) {
                        console.error("Invalid object received: " + transport.responseText);
                        dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
                                        __('Could not update headlines (invalid object received - see error console for details)') +
                                        "</div>");
+               } else {
+                       //notify_error("Error communicating with server.");
+                       Element.show("net-alert");
                }
 
                _infscroll_request_sent = 0;
@@ -244,8 +263,6 @@ function showArticleInHeadlines(id) {
 
                selectArticles('none');
 
-               var upd_img_pic = $("FUPDPIC-" + id);
-
                var view_mode = false;
 
                try {
@@ -255,14 +272,7 @@ function showArticleInHeadlines(id) {
                        //
                }
 
-               if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
-                                       upd_img_pic.src.match("fresh_sign.png"))) {
-
-                       upd_img_pic.src = "images/blank_icon.gif";
-
-                       cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-
-               } else if (article_is_unread && view_mode == "all_articles") {
+               if (article_is_unread && view_mode == "all_articles") {
                        cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
                }
 
@@ -292,10 +302,6 @@ function article_callback2(transport, id) {
 
                if (reply) {
 
-                       var upic = $('FUPDPIC-' + id);
-
-                       if (upic) upic.src = 'images/blank_icon.gif';
-
                        reply.each(function(article) {
                                if (active_post_id == article['id']) {
                                        render_article(article['content']);
@@ -310,11 +316,13 @@ function article_callback2(transport, id) {
 //                             return;
 //                     }
 
-               } else {
+               } else if (transport.responseText) {
                        console.error("Invalid object received: " + transport.responseText);
 
                        render_article("<div class='whiteBox'>" +
                                        __('Could not display article (invalid object received - see error console for details)') + "</div>");
+               } else {
+                       Element.show("net-alert");
                }
 
                request_counters();
@@ -375,15 +383,7 @@ function view(id) {
 
                precache_headlines();
 
-               if (!cached_article) {
-
-                       var upic = $('FUPDPIC-' + id);
-
-                       if (upic) {
-                               upic.src = getInitParam("sign_progress");
-                       }
-
-               } else if (cached_article && article_is_unread) {
+               if (cached_article && article_is_unread) {
 
                        query = query + "&mode=prefetch";
 
@@ -578,16 +578,16 @@ function moveToPost(mode) {
 function toggleSelected(id, force_on) {
        try {
 
-               var cb = $("RCHK-" + id);
+               var cb = dijit.byId("RCHK-" + id);
                var row = $("RROW-" + id);
 
                if (row) {
                        if (row.hasClassName('Selected') && !force_on) {
                                row.removeClassName('Selected');
-                               if (cb) cb.checked = false;
+                               if (cb) cb.attr("checked", false);
                        } else {
                                row.addClassName('Selected');
-                               if (cb) cb.checked = true;
+                               if (cb) cb.attr("checked", true);
                        }
                }
        } catch (e) {
@@ -873,52 +873,52 @@ function selectArticles(mode) {
 
                children.each(function(child) {
                        var id = child.id.replace("RROW-", "");
-                       var cb = $("RCHK-" + id);
+                       var cb = dijit.byId("RCHK-" + id);
 
                        if (mode == "all") {
                                child.addClassName("Selected");
-                               cb.checked = true;
+                               if (cb) cb.attr("checked", true);
                        } else if (mode == "unread") {
                                if (child.hasClassName("Unread")) {
                                        child.addClassName("Selected");
-                                       cb.checked = true;
+                                       if (cb) cb.attr("checked", true);
                                } else {
                                        child.removeClassName("Selected");
-                                       cb.checked = false;
+                                       if (cb) cb.attr("checked", false);
                                }
                        } else if (mode == "marked") {
                                var img = $("FMPIC-" + child.id.replace("RROW-", ""));
 
                                if (img && img.src.match("mark_set")) {
                                        child.addClassName("Selected");
-                                       cb.checked = true;
+                                       if (cb) cb.attr("checked", true);
                                } else {
                                        child.removeClassName("Selected");
-                                       cb.checked = false;
+                                       if (cb) cb.attr("checked", false);
                                }
                        } else if (mode == "published") {
                                var img = $("FPPIC-" + child.id.replace("RROW-", ""));
 
                                if (img && img.src.match("pub_set")) {
                                        child.addClassName("Selected");
-                                       cb.checked = true;
+                                       if (cb) cb.attr("checked", true);
                                } else {
                                        child.removeClassName("Selected");
-                                       cb.checked = false;
+                                       if (cb) cb.attr("checked", false);
                                }
 
                        } else if (mode == "invert") {
                                if (child.hasClassName("Selected")) {
                                        child.removeClassName("Selected");
-                                       cb.checked = false;
+                                       if (cb) cb.attr("checked", false);
                                } else {
                                        child.addClassName("Selected");
-                                       cb.checked = true;
+                                       if (cb) cb.attr("checked", true);
                                }
 
                        } else {
                                child.removeClassName("Selected");
-                               cb.checked = false;
+                               if (cb) cb.attr("checked", false);
                        }
                });
 
@@ -1306,14 +1306,6 @@ function cdmExpandArticle(id) {
 
                var elem = $("CICD-" + active_post_id);
 
-               var upd_img_pic = $("FUPDPIC-" + id);
-
-               if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
-                               upd_img_pic.src.match("fresh_sign.png"))) {
-
-                       upd_img_pic.src = "images/blank_icon.gif";
-               }
-
                if (id == active_post_id && Element.visible(elem))
                        return true;
 
@@ -1626,14 +1618,6 @@ function cdmClicked(event, id) {
                                if (elem)
                                        elem.removeClassName("Unread");
 
-                               var upd_img_pic = $("FUPDPIC-" + id);
-
-                               if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
-                                               upd_img_pic.src.match("fresh_sign.png"))) {
-
-                                       upd_img_pic.src = "images/blank_icon.gif";
-                               }
-
                                active_post_id = id;
 
                                if (article_is_unread) {
@@ -1743,10 +1727,10 @@ function isCdmMode() {
 function markHeadline(id) {
        var row = $("RROW-" + id);
        if (row) {
-               var check = $("RCHK-" + id);
+               var check = dijit.byId("RCHK-" + id);
 
                if (check) {
-                       check.checked = true;
+                       check.attr("checked", true);
                }
 
                row.addClassName("Selected");
@@ -2123,4 +2107,83 @@ function precache_headlines() {
        }
 }
 
+function cancelSearch() {
+       try {
+               _search_query = "";
+               viewCurrentFeed();
+       } catch (e) {
+               exception_error("cancelSearch", e);
+       }
+}
 
+function setSelectionScore() {
+       try {
+               var ids = getSelectedArticleIds2();
+
+               if (ids.length > 0) {
+                       console.log(ids);
+
+                       var score = prompt(__("Please enter new score for selected articles:"), score);
+
+                       if (score != undefined) {
+                               var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
+                                       "&score=" + param_escape(score);
+
+                               new Ajax.Request("backend.php", {
+                                       parameters: query,
+                                       onComplete: function(transport) {
+                                               var reply = JSON.parse(transport.responseText);
+                                               if (reply) {
+                                                       console.log(ids);
+
+                                                       ids.each(function(id) {
+                                                               var row = $("RROW-" + id);
+
+                                                               if (row) {
+                                                                       var pic = row.getElementsByClassName("hlScorePic")[0];
+
+                                                                       if (pic) {
+                                                                               pic.src = pic.src.replace(/score_.*?\.png/,
+                                                                                       reply["score_pic"]);
+                                                                               pic.setAttribute("score", score);
+                                                                       }
+                                                               }
+                                                       });
+                                               }
+                                       } });
+                       }
+
+               } else {
+                       alert(__("No articles are selected."));
+               }
+       } catch (e) {
+               exception_error("setSelectionScore", e);
+       }
+}
+
+function changeScore(id, pic) {
+       try {
+               var score = pic.getAttribute("score");
+
+               var new_score = prompt(__("Please enter new score for this article:"), score);
+
+               if (new_score != undefined) {
+
+                       var query = "op=rpc&method=setScore&id=" + param_escape(id) +
+                               "&score=" + param_escape(new_score);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       var reply = JSON.parse(transport.responseText);
+
+                                       if (reply) {
+                                               pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
+                                               pic.setAttribute("score", new_score);
+                                       }
+                               } });
+               }
+       } catch (e) {
+               exception_error("changeScore", e);
+       }
+}