]> git.wh0rd.org - tt-rss.git/blobdiff - prefs.js
tweak README
[tt-rss.git] / prefs.js
index 6aae959e6fcd0e330de3a12dbc994b0c84f06479..404602c33b9b2aa635b54a331446d01fa1ce7b58 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -1,11 +1,7 @@
-/*
-       This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>              
-       Licensed under GPL v.2 or (at your preference) any later version.
-*/
-
 var xmlhttp = false;
 
 var active_feed = false;
+var active_feed_cat = false;
 var active_filter = false;
 var active_label = false;
 var active_user = false;
@@ -79,7 +75,7 @@ function labellist_callback() {
        if (xmlhttp.readyState == 4) {
                container.innerHTML=xmlhttp.responseText;
 
-               if (active_filter) {
+               if (active_label) {
                        var row = document.getElementById("LILRR-" + active_label);
                        if (row) {
                                if (!row.className.match("Selected")) {
@@ -119,11 +115,19 @@ function userlist_callback() {
        }
 }
 
-function userdetails_callback() {
-       var container = document.getElementById('prefUserDetails');
+function infobox_callback() {
        if (xmlhttp.readyState == 4) {
-               container.innerHTML=xmlhttp.responseText;
-               container.style.display = "block";
+               var box = document.getElementById('infoBox');
+               var shadow = document.getElementById('infoBoxShadow');
+
+               if (box) {
+                       box.innerHTML=xmlhttp.responseText;
+                       if (shadow) {
+                               shadow.style.display = "block";
+                       } else {
+                               box.style.display = "block";
+                       }
+               }
        }
 }
 
@@ -156,8 +160,7 @@ function notify_callback() {
        }
 }
 
-
-function updateFeedList() {
+function updateFeedList(sort_key) {
 
        if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
@@ -168,7 +171,8 @@ function updateFeedList() {
 
        p_notify("Loading, please wait...");
 
-       xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
+       xmlhttp.open("GET", "backend.php?op=pref-feeds" +
+               "&sort=" + param_escape(sort_key), true);
        xmlhttp.onreadystatechange=feedlist_callback;
        xmlhttp.send(null);
 
@@ -239,6 +243,7 @@ function addFilter() {
 
        var regexp = document.getElementById("fadd_regexp");
        var match = document.getElementById("fadd_match");
+       var feed = document.getElementById("fadd_feed");
 
        if (regexp.value.length == 0) {
                notify("Missing filter expression.");
@@ -247,8 +252,11 @@ function addFilter() {
 
                var v_match = match[match.selectedIndex].text;
 
+               var feed_id = feed[feed.selectedIndex].id;
+
                xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
-                       param_escape(regexp.value) + "&match=" + v_match, true);                        
+                       param_escape(regexp.value) + "&match=" + v_match +
+                       "&fid=" + param_escape(feed_id), true);                 
                        
                xmlhttp.onreadystatechange=filterlist_callback;
                xmlhttp.send(null);
@@ -283,6 +291,30 @@ function addFeed() {
 
 }
 
+function addFeedCat() {
+
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
+       var cat = document.getElementById("fadd_cat");
+
+       if (cat.value.length == 0) {
+               notify("Missing feed category.");
+       } else {
+               notify("Adding feed category...");
+
+               xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=addCat&cat=" +
+                       param_escape(cat.value), true);
+               xmlhttp.onreadystatechange=feedlist_callback;
+               xmlhttp.send(null);
+
+               link.value = "";
+
+       }
+
+}
 function addUser() {
 
        if (!xmlhttp_ready(xmlhttp)) {
@@ -374,97 +406,44 @@ function editFeed(feed) {
 
 }
 
-function getSelectedLabels() {
-
-       var content = document.getElementById("prefLabelList");
-
-       var sel_rows = new Array();
+function editFeedCat(cat) {
 
-       for (i = 0; i < content.rows.length; i++) {
-               if (content.rows[i].className.match("Selected")) {
-                       var row_id = content.rows[i].id.replace("LILRR-", "");
-                       sel_rows.push(row_id);  
-               }
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
        }
 
-       return sel_rows;
-}
-
-function getSelectedUsers() {
-
-       var content = document.getElementById("prefUserList");
-
-       var sel_rows = new Array();
+       active_feed_cat = cat;
 
-       for (i = 0; i < content.rows.length; i++) {
-               if (content.rows[i].className.match("Selected")) {
-                       var row_id = content.rows[i].id.replace("UMRR-", "");
-                       sel_rows.push(row_id);  
-               }
-       }
+       xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCat&id=" +
+               param_escape(cat), true);
+       xmlhttp.onreadystatechange=feedlist_callback;
+       xmlhttp.send(null);
 
-       return sel_rows;
 }
 
+function getSelectedLabels() {
+       return getSelectedTableRowIds("prefLabelList", "LILRR");
+}
 
-function getSelectedFilters() {
-
-       var content = document.getElementById("prefFilterList");
-
-       var sel_rows = new Array();
-
-       for (i = 0; i < content.rows.length; i++) {
-               if (content.rows[i].className.match("Selected")) {
-                       var row_id = content.rows[i].id.replace("FILRR-", "");
-                       sel_rows.push(row_id);  
-               }
-       }
-
-       return sel_rows;
+function getSelectedUsers() {
+       return getSelectedTableRowIds("prefUserList", "UMRR");
 }
 
 function getSelectedFeeds() {
-
-       var content = document.getElementById("prefFeedList");
-
-       var sel_rows = new Array();
-
-       for (i = 0; i < content.rows.length; i++) {
-               if (content.rows[i].className.match("Selected")) {
-                       var row_id = content.rows[i].id.replace("FEEDR-", "");
-                       sel_rows.push(row_id);  
-               }
-       }
-
-       return sel_rows;
+       return getSelectedTableRowIds("prefFeedList", "FEEDR");
 }
 
-function readSelectedFeeds() {
-
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
-       }
-
-       var sel_rows = getSelectedFeeds();
-
-       if (sel_rows.length > 0) {
-
-               notify("Marking selected feeds as read...");
-
-               xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
-                       param_escape(sel_rows.toString()), true);
-               xmlhttp.onreadystatechange=notify_callback;
-               xmlhttp.send(null);
-
-       } else {
-
-               notify("Please select some feeds first.");
+function getSelectedFilters() {
+       return getSelectedTableRowIds("prefFilterList", "FILRR");
+}
 
-       }
+function getSelectedFeedCats() {
+       return getSelectedTableRowIds("prefFeedCatList", "FCATR");
 }
 
-function unreadSelectedFeeds() {
+
+function readSelectedFeeds(read) {
 
        if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
@@ -475,9 +454,15 @@ function unreadSelectedFeeds() {
 
        if (sel_rows.length > 0) {
 
-               notify("Marking selected feeds as unread...");
+               if (!read) {
+                       op = "unread";
+               } else {
+                       op = "read";
+               }
+
+               notify("Marking selected feeds as " + op + "...");
 
-               xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
+               xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=" + op + "&ids="+
                        param_escape(sel_rows.toString()), true);
                xmlhttp.onreadystatechange=notify_callback;
                xmlhttp.send(null);
@@ -585,6 +570,32 @@ function removeSelectedFeeds() {
 
 }
 
+function removeSelectedFeedCats() {
+
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
+       var sel_rows = getSelectedFeedCats();
+
+       if (sel_rows.length > 0) {
+
+               notify("Removing selected categories...");
+
+               xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=removeCats&ids="+
+                       param_escape(sel_rows.toString()), true);
+               xmlhttp.onreadystatechange=feedlist_callback;
+               xmlhttp.send(null);
+
+       } else {
+
+               notify("Please select some feeds first.");
+
+       }
+
+}
+
 function feedEditCancel() {
 
        if (!xmlhttp_ready(xmlhttp)) {
@@ -602,6 +613,23 @@ function feedEditCancel() {
 
 }
 
+function feedCatEditCancel() {
+
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
+       active_feed_cat = false;
+
+       notify("Operation cancelled.");
+
+       xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
+       xmlhttp.onreadystatechange=feedlist_callback;
+       xmlhttp.send(null);
+
+}
+
 function feedEditSave() {
 
        var feed = active_feed;
@@ -615,6 +643,9 @@ function feedEditSave() {
        var title = document.getElementById("iedit_title").value;
        var upd_intl = document.getElementById("iedit_updintl").value;
        var purge_intl = document.getElementById("iedit_purgintl").value;
+       var fcat = document.getElementById("iedit_fcat");
+
+       var fcat_id = fcat[fcat.selectedIndex].id;
 
 //     notify("Saving feed.");
 
@@ -640,14 +671,30 @@ function feedEditSave() {
 
        active_feed = false;
 
+       notify("");
+
        xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
                feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) +
-               "&ui=" + param_escape(upd_intl) + "&pi=" + param_escape(purge_intl), true);
+               "&ui=" + param_escape(upd_intl) + "&pi=" + param_escape(purge_intl) +
+               "&catid=" + param_escape(fcat_id), true);
        xmlhttp.onreadystatechange=feedlist_callback;
        xmlhttp.send(null);
 
 }
 
+function labelTest() {
+
+       var sqlexp = document.getElementById("iedit_expr").value;
+       var descr = document.getElementById("iedit_descr").value;
+
+       xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
+               param_escape(sqlexp) + "&descr=" + param_escape(descr), true);
+
+       xmlhttp.onreadystatechange=infobox_callback;
+       xmlhttp.send(null);
+
+}
+
 function labelEditCancel() {
 
        if (!xmlhttp_ready(xmlhttp)) {
@@ -723,6 +770,8 @@ function labelEditSave() {
                return;
        }
 
+       notify("");
+
        active_label = false;
 
        xmlhttp.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
@@ -758,11 +807,13 @@ function userEditSave() {
 
        active_user = false;
 
+       notify("");
+
        xmlhttp.open("GET", "backend.php?op=pref-users&subop=editSave&id=" +
                user + "&l=" + param_escape(login) + "&al=" + param_escape(level),
                true);
                
-       xmlhttp.onreadystatechange=labellist_callback;
+       xmlhttp.onreadystatechange=userlist_callback;
        xmlhttp.send(null);
 
 }
@@ -780,9 +831,12 @@ function filterEditSave() {
        var regexp = document.getElementById("iedit_regexp").value;
        var descr = document.getElementById("iedit_descr").value;
        var match = document.getElementById("iedit_match");
-
+       
        var v_match = match[match.selectedIndex].text;
 
+       var feed = document.getElementById("iedit_feed");
+       var feed_id = feed[feed.selectedIndex].id;
+
 //     notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
 
        if (regexp.length == 0) {
@@ -794,8 +848,10 @@ function filterEditSave() {
 
        xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
                filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) +
-               "&m=" + param_escape(v_match), true);
-               
+               "&m=" + param_escape(v_match) + "&fid=" + param_escape(feed_id), true);
+
+       notify("");
+
        xmlhttp.onreadystatechange=filterlist_callback;
        xmlhttp.send(null); 
 
@@ -814,6 +870,8 @@ function editSelectedLabel() {
                return;
        }
 
+       notify("");
+
        editLabel(rows[0]);
 
 }
@@ -831,6 +889,8 @@ function editSelectedUser() {
                return;
        }
 
+       notify("");
+
        editUser(rows[0]);
 }
 
@@ -879,8 +939,39 @@ function selectedUserDetails() {
 
        var id = rows[0];
 
+       notify("");
+
        xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
-       xmlhttp.onreadystatechange=userdetails_callback;
+       xmlhttp.onreadystatechange=infobox_callback;
+       xmlhttp.send(null);
+
+}
+
+function selectedFeedDetails() {
+
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
+       var rows = getSelectedFeeds();
+
+       if (rows.length == 0) {
+               notify("No feeds are selected.");
+               return;
+       }
+
+       if (rows.length > 1) {
+               notify("Please select one feed.");
+               return;
+       }
+
+       var id = rows[0];
+
+       notify("");
+
+       xmlhttp.open("GET", "backend.php?op=feed-details&id=" + id, true);
+       xmlhttp.onreadystatechange=infobox_callback;
        xmlhttp.send(null);
 
 }
@@ -898,6 +989,8 @@ function editSelectedFilter() {
                return;
        }
 
+       notify("");
+
        editFilter(rows[0]);
 
 }
@@ -916,10 +1009,31 @@ function editSelectedFeed() {
                return;
        }
 
+       notify("");
+
        editFeed(rows[0]);
 
 }
 
+function editSelectedFeedCat() {
+       var rows = getSelectedFeedCats();
+
+       if (rows.length == 0) {
+               notify("No categories are selected.");
+               return;
+       }
+
+       if (rows.length > 1) {
+               notify("Please select one category.");
+               return;
+       }
+
+       notify("");
+
+       editFeedCat(rows[0]);
+
+}
+
 function localPiggieFunction(enable) {
        if (enable) {
                piggie.style.display = "block";
@@ -993,6 +1107,11 @@ function updatePrefsList() {
 
 function selectTab(id) {
 
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
        if (id == "feedConfig") {
                updateFeedList();
        } else if (id == "filterConfig") {
@@ -1066,7 +1185,13 @@ function dispOptionHelp(event, sender) {
 
 } */
 
-function closeUserDetails() {
-       var d = document.getElementById('prefUserDetails');
-       d.style.display = "none";
+function closeInfoBox() {
+       var box = document.getElementById('infoBox');
+       var shadow = document.getElementById('infoBoxShadow');
+
+       if (shadow) {
+               shadow.style.display = "none";
+       } else if (box) {
+               box.style.display = "none";
+       }
 }