]> git.wh0rd.org - tt-rss.git/blobdiff - prefs.js
ccache: skip non-numeric feeds (e.g. tags)
[tt-rss.git] / prefs.js
index b4d7169312f193c9321458e4c08d3f5375d71fc2..38dde4660b92c4462895ea5e931cbda0c619a130 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -1,7 +1,6 @@
 var xmlhttp = false;
 
 var active_feed_cat = false;
-var active_label = false;
 var active_tab = false;
 var feed_to_expand = false;
 
@@ -62,6 +61,7 @@ function expand_feed_callback() {
                        container.innerHTML=xmlhttp.responseText;
 //                     container.style.display = "block";
                        Effect.Appear(container, {duration : 0.5});
+                       notify('');
                } catch (e) {
                        exception_error("expand_feed_callback", e);
                }
@@ -135,28 +135,37 @@ function filterlist_callback() {
 }
 
 function labellist_callback() {
-       var container = document.getElementById('prefContent');
-       if (xmlhttp.readyState == 4) {
-               closeInfoBox();
-               container.innerHTML=xmlhttp.responseText;
-               if (active_label) {
-                       var row = document.getElementById("LILRR-" + active_label);
-                       if (row) {
-                               if (!row.className.match("Selected")) {
-                                       row.className = row.className + "Selected";
-                               }               
+
+       try {
+
+               var container = document.getElementById('prefContent');
+               if (xmlhttp.readyState == 4) {
+                       closeInfoBox();
+                       container.innerHTML=xmlhttp.responseText;
+       
+                       if (document.getElementById("prefLabelList")) {
+                               var elems = document.getElementById("prefLabelList").getElementsByTagName("SPAN");
+
+                               for (var i = 0; i < elems.length; i++) {
+                                       if (elems[i].id && elems[i].id.match("LILT-")) {
+
+                                               var id = elems[i].id.replace("LILT-", "");
+                                                       new Ajax.InPlaceEditor(elems[i],
+                                                       'backend.php?op=pref-labels&subop=save&id=' + id,
+                                                       {cols: 20, rows: 1});
+                                       }
+                               }
                        }
-                       var checkbox = document.getElementById("LICHK-" + active_label);
-                       
-                       if (checkbox) {
-                               checkbox.checked = true;
+       
+                       if (typeof correctPNG != 'undefined') {
+                               correctPNG();
                        }
+                       notify("");
+                       remove_splash();
                }
-               if (typeof correctPNG != 'undefined') {
-                       correctPNG();
-               }
-               notify("");
-               remove_splash();
+
+       } catch (e) {
+               exception_error("labellist_callback", e);
        }
 }
 
@@ -231,24 +240,32 @@ function changepass_callback() {
        }
 }
 
-function infobox_feed_cat_callback() {
-       if (xmlhttp.readyState == 4) {
-               try {
-
-                       infobox_callback();
-
-                       if (document.getElementById("prefFeedCatList")) {
-                               var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
+function init_cat_inline_editor() {
+       try {
 
-                               for (var i = 0; i < elems.length; i++) {
-                                       if (elems[i].id && elems[i].id.match("FCATT-")) {
-                                               var cat_id = elems[i].id.replace("FCATT-", "");
+               if (document.getElementById("prefFeedCatList")) {
+                       var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
 
+                       for (var i = 0; i < elems.length; i++) {
+                               if (elems[i].id && elems[i].id.match("FCATT-")) {
+                                       var cat_id = elems[i].id.replace("FCATT-", "");
                                                new Ajax.InPlaceEditor(elems[i],
-                                                       'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
-                                       }
+                                               'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
                                }
                        }
+               }
+
+       } catch (e) {
+               exception_error("init_cat_inline_editor", e);
+       }
+}
+
+function infobox_feed_cat_callback() {
+       if (xmlhttp.readyState == 4) {
+               try {
+
+                       infobox_callback();
+                       init_cat_inline_editor();
 
                } catch (e) {
                        exception_error("infobox_feed_cat_callback", e);
@@ -304,34 +321,36 @@ function updateUsersList(sort_key) {
 
 function addLabel() {
 
+       try {
+
        if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
                return
        }
 
-       var form = document.forms['label_edit_form'];
-
-       var sql_exp = form.sql_exp.value;
-       var description = form.description.value;
+       var caption = prompt(__("Please enter label caption:"), "");
 
-       if (sql_exp == "") {
-               alert(__("Can't create label: missing SQL expression."));
+       if (caption == null) { 
                return false;
        }
 
-       if (description == "") {
+       if (caption == "") {
                alert(__("Can't create label: missing caption."));
                return false;
        }
 
-       var query = Form.serialize("label_edit_form");
-
        // we can be called from some other tab
        active_tab = "labelConfig";
 
+       var query = "caption=" + param_escape(caption);
+
        xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);                     
        xmlhttp.onreadystatechange=infobox_submit_callback;
        xmlhttp.send(null);
+
+       } catch (e) {
+               exception_error("addLabel", e);
+       }
 }
 
 function addFeed() {
@@ -377,7 +396,7 @@ function addFeedCat() {
 
                xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
                        param_escape(cat.value), true);
-               xmlhttp.onreadystatechange=infobox_callback;
+               xmlhttp.onreadystatechange=infobox_feed_cat_callback;
                xmlhttp.send(null);
 
                link.value = "";
@@ -410,31 +429,6 @@ function addUser() {
 
 }
 
-function editLabel(id) {
-
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
-       }
-
-       disableHotkeys();
-
-       notify_progress("Loading, please wait...");
-
-       document.getElementById("label_create_btn").disabled = true;
-
-       active_label = id;
-
-       selectTableRowsByIdPrefix('prefLabelList', 'LILRR-', 'LICHK-', false);
-       selectTableRowById('LILRR-'+id, 'LICHK-'+id, true);
-
-       xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
-               param_escape(id), true);
-       xmlhttp.onreadystatechange=infobox_callback;
-       xmlhttp.send(null);
-
-}
-
 function editUser(id) {
 
        if (!xmlhttp_ready(xmlhttp)) {
@@ -449,6 +443,8 @@ function editUser(id) {
        selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
        selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
 
+       disableContainerChildren("userOpToolbar", false);
+
        xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
                param_escape(id), true);
        xmlhttp.onreadystatechange=infobox_callback;
@@ -467,7 +463,9 @@ function editFilter(id) {
 
        notify_progress("Loading, please wait...");
 
-       document.getElementById("create_filter_btn").disabled = true;
+//     document.getElementById("create_filter_btn").disabled = true;
+
+       disableContainerChildren("filterOpToolbar", false);
 
        selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
        selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
@@ -490,18 +488,20 @@ function editFeed(feed) {
 
        notify_progress("Loading, please wait...");
 
-       document.getElementById("subscribe_to_feed_btn").disabled = true;
+/*     document.getElementById("subscribe_to_feed_btn").disabled = true;
 
        try {
                document.getElementById("top25_feeds_btn").disabled = true;
        } catch (e) {
                // this button is not always available, no-op if not found
-       }
+       } */
 
        // clean selection from all rows & select row being edited
        selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
        selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
 
+       disableContainerChildren("feedOpToolbar", false);
+
        xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
                param_escape(feed), true);
 
@@ -777,7 +777,7 @@ function removeSelectedFeedCats() {
        
                        xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
                                param_escape(sel_rows.toString()), true);
-                       xmlhttp.onreadystatechange=infobox_callback;
+                       xmlhttp.onreadystatechange=infobox_feed_cat_callback;
                        xmlhttp.send(null);
                }
 
@@ -820,7 +820,12 @@ function feedCatEditCancel() {
 
        active_feed_cat = false;
 
-//     notify("Operation cancelled.");
+       try {
+               document.getElementById("subscribe_to_feed_btn").disabled = false;
+               document.getElementById("top25_feeds_btn").disabled = false;
+       } catch (e) {
+               // this button is not always available, no-op if not found
+       }
 
        xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
        xmlhttp.onreadystatechange=infobox_callback;
@@ -858,45 +863,6 @@ function feedEditSave() {
        } 
 }
 
-function feedCatEditSave() {
-
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
-       }
-
-       notify_progress("Saving category...");
-
-       var query = Form.serialize("feed_cat_edit_form");
-
-       xmlhttp.open("GET", "backend.php?" + query, true);
-       xmlhttp.onreadystatechange=infobox_callback;
-       xmlhttp.send(null);
-
-       active_feed_cat = false;
-
-       return false;
-}
-
-function labelEditCancel() {
-
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
-       }
-
-       try {
-               document.getElementById("label_create_btn").disabled = false;
-               selectPrefRows('label', false); // cleanup feed selection
-       } catch (e) { }
-
-       active_label = false;
-
-       closeInfoBox();
-
-       return false;
-}
-
 function userEditCancel() {
 
        if (!xmlhttp_ready(xmlhttp)) {
@@ -927,46 +893,6 @@ function filterEditCancel() {
        return false;
 }
 
-function labelEditSave() {
-
-       var label = active_label;
-
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
-       }
-
-/*     if (!is_opera()) {
-
-               var sql_exp = document.forms["label_edit_form"].sql_exp.value;
-               var description = document.forms["label_edit_form"].description.value;
-       
-               if (sql_exp.length == 0) {
-                       alert("SQL Expression cannot be blank.");
-                       return false;
-               }
-       
-               if (description.length == 0) {
-                       alert("Caption field cannot be blank.");
-                       return false;
-               }
-       } */
-
-       closeInfoBox();
-
-       notify_progress("Saving label...");
-
-       active_label = false;
-
-       query = Form.serialize("label_edit_form");
-
-       xmlhttp.open("GET", "backend.php?" + query, true);              
-       xmlhttp.onreadystatechange=labellist_callback;
-       xmlhttp.send(null);
-
-       return false;
-}
-
 function userEditSave() {
 
        if (!xmlhttp_ready(xmlhttp)) {
@@ -1026,24 +952,6 @@ function filterEditSave() {
        return false;
 }
 
-function editSelectedLabel() {
-       var rows = getSelectedLabels();
-
-       if (rows.length == 0) {
-               alert(__("No labels are selected."));
-               return;
-       }
-
-       if (rows.length > 1) {
-               alert(__("Please select only one label."));
-               return;
-       }
-
-       notify("");
-
-       editLabel(rows[0]);
-
-}
 
 function editSelectedUser() {
        var rows = getSelectedUsers();
@@ -1113,7 +1021,7 @@ function selectedUserDetails() {
 
        var id = rows[0];
 
-       xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
+       xmlhttp.open("GET", "backend.php?op=pref-users&subop=user-details&id=" + id, true);
        xmlhttp.onreadystatechange=infobox_callback;
        xmlhttp.send(null);
 
@@ -1188,6 +1096,34 @@ function editSelectedFeed() {
 
 }
 
+function editSelectedFeeds() {
+
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
+       var rows = getSelectedFeeds();
+
+       if (rows.length == 0) {
+               alert(__("No feeds are selected."));
+               return;
+       }
+
+       notify("");
+
+       disableHotkeys();
+
+       notify_progress("Loading, please wait...");
+
+       xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeeds&ids=" +
+               param_escape(rows.toString()), true);
+
+       xmlhttp.onreadystatechange=infobox_callback;
+       xmlhttp.send(null);
+
+}
+
 function editSelectedFeedCat() {
        var rows = getSelectedFeedCats();
 
@@ -1310,7 +1246,6 @@ function selectTab(id, noupdate, subop) {
        
                        // clean up all current selections, just in case
                        active_feed_cat = false;
-                       active_label = false;
 
 //                     Effect.Fade("prefContent", {duration: 1, to: 0.01, 
 //                             queue: { position:'end', scope: 'FEED_TAB', limit: 1 } } );
@@ -1429,6 +1364,10 @@ function init_second_stage() {
                
                caller_subop = getURLParam('subop');
 
+               if (getURLParam("subopparam")) {
+                       caller_subop = caller_subop + ":" + getURLParam("subopparam");
+               }
+
                if (tab) {
                        active_tab = tab;
                }
@@ -1559,7 +1498,12 @@ function feedBrowserSubscribe() {
        }
 }
 
-function updateBigFeedBrowser(limit) {
+function updateBigFeedBrowserBtn() {
+       notify_progress("Loading, please wait...");
+       return updateBigFeedBrowser();
+}
+
+function updateBigFeedBrowser(limit, from_button) {
 
        if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
@@ -1575,6 +1519,12 @@ function updateBigFeedBrowser(limit) {
                query = query + "&limit=" + param_escape(limit);
        }
 
+       var search = document.getElementById("feed_browser_search");
+
+       if (search) {
+               query = query + "&search=" + param_escape(search.value);
+       }
+
        xmlhttp.open("GET", query, true);
        xmlhttp.onreadystatechange=feed_browser_callback;
        xmlhttp.send(null);
@@ -1598,6 +1548,8 @@ function browserToggleExpand(id) {
 
                var d = document.getElementById("BRDET-" + id);
        
+               notify_progress("Loading, please wait...");
+
                if (Element.visible(d)) {
                        Effect.Fade(d, {duration : 0.5});
                } else {
@@ -1774,7 +1726,7 @@ function pref_hotkey_handler(e) {
 
                        if (keycode == 191 || keychar == '/') { // /
                                var search_boxes = new Array("label_search", 
-                                       "feed_search", "filter_search", "user_search");
+                                       "feed_search", "filter_search", "user_search", "feed_browser_search");
 
                                for (var i = 0; i < search_boxes.length; i++) {
                                        var elem = document.getElementById(search_boxes[i]);
@@ -1801,10 +1753,10 @@ function pref_hotkey_handler(e) {
                                return false;
                        }
 
-                       if (keycode == 76) { // l
+/*                     if (keycode == 76) { // l
                                displayDlg("quickAddLabel");
                                return false;
-                       }
+                       } */
 
                        if (keycode == 85) { // u
                                // no-op
@@ -2073,7 +2025,14 @@ function feedActionChange() {
 function feedActionGo(op) {    
        try {
                if (op == "facEdit") {
-                       editSelectedFeed();
+
+                       var rows = getSelectedFeeds();
+
+                       if (rows.length > 1) {
+                               editSelectedFeeds();
+                       } else {
+                               editSelectedFeed();
+                       }
                }
 
                if (op == "facClear") {
@@ -2131,7 +2090,7 @@ function rescoreSelectedFeeds() {
                var ok = confirm(__("Rescore articles in selected feeds?"));
 
                if (ok) {
-                       notify_progress("Rescoring selected feeds...");
+                       notify_progress("Rescoring selected feeds...", true);
        
                        xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
                                param_escape(sel_rows.toString()), true);
@@ -2149,10 +2108,151 @@ function rescore_all_feeds() {
                var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
 
                if (ok) {
-                       notify_progress("Rescoring feeds...");
+                       notify_progress("Rescoring feeds...", true);
 
                        xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescoreAll&quiet=1", true);
                        xmlhttp.onreadystatechange=notify_callback;
                        xmlhttp.send(null);
                }
 }
+
+function removeFilter(id, title) {
+
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
+       var msg = __("Remove filter %s?").replace("%s", title);
+
+       var ok = confirm(msg);
+
+       if (ok) {
+               closeInfoBox();
+
+               notify_progress("Removing filter...");
+       
+               xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
+                       param_escape(id), true);
+               xmlhttp.onreadystatechange=filterlist_callback;
+               xmlhttp.send(null);
+       }
+
+       return false;
+}
+
+function unsubscribeFeed(id, title) {
+
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
+       var msg = __("Unsubscribe from %s?").replace("%s", title);
+
+       var ok = confirm(msg);
+
+       if (ok) {
+               closeInfoBox();
+
+               notify_progress("Removing feed...");
+       
+               xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
+                       param_escape(id), true);
+               xmlhttp.onreadystatechange=filterlist_callback;
+               xmlhttp.send(null);
+       }
+
+       return false;
+
+       return false;
+
+}
+
+function feedsEditSave() {
+       try {
+
+               if (!xmlhttp_ready(xmlhttp)) {
+                       printLockingError();
+                       return
+               }
+
+               var ok = confirm(__("Save changes to selected feeds?"));
+
+               if (ok) {
+
+                       var f = document.forms["batch_edit_feed_form"];
+
+                       var query = Form.serialize("batch_edit_feed_form");
+
+                       /* Form.serialize ignores unchecked checkboxes */
+
+                       if (!query.match("&hidden=") && 
+                                       f.hidden.disabled == false) {
+                               query = query + "&hidden=false";
+                       }
+
+                       if (!query.match("&rtl_content=") && 
+                                       f.rtl_content.disabled == false) {
+                               query = query + "&rtl_content=false";
+                       }
+
+                       if (!query.match("&private=") && 
+                                       f.private.disabled == false) {
+                               query = query + "&private=false";
+                       }
+
+                       if (!query.match("&cache_images=") && 
+                                       f.cache_images.disabled == false) {
+                               query = query + "&cache_images=false";
+                       }
+
+                       if (!query.match("&include_in_digest=") && 
+                                       f.include_in_digest.disabled == false) {
+                               query = query + "&include_in_digest=false";
+                       }
+       
+                       closeInfoBox();
+       
+                       notify_progress("Saving feeds...");
+       
+                       xmlhttp.open("POST", "backend.php", true);
+                       xmlhttp.onreadystatechange=feedlist_callback;
+                       xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+                       xmlhttp.send(query);
+               }
+
+               return false;
+       } catch (e) {
+               exception_error("feedsEditSave", e);
+       }
+}
+
+function batchFeedsToggleField(cb, elem, label) {
+       try {
+               var f = document.forms["batch_edit_feed_form"];
+               var l = document.getElementById(label);
+
+               if (cb.checked) {
+                       f[elem].disabled = false;
+
+                       if (l) {
+                               l.className = "";
+                       };
+
+//                     new Effect.Highlight(f[elem], {duration: 1, startcolor: "#fff7d5",
+//                             queue: { position:'end', scope: 'BPEFQ', limit: 1 } } );
+
+               } else {
+                       f[elem].disabled = true;
+
+                       if (l) {
+                               l.className = "insensitive";
+                       };
+
+               }
+       } catch (e) {
+               exception_error("batchFeedsToggleField", e);
+       }
+}
+