From: Andrew Dolgov Date: Sun, 7 Nov 2010 20:30:05 +0000 (+0300) Subject: allow adding cats from feed editor X-Git-Tag: 1.5.0~373 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=5c7c7da9e12134ae2c4be1f60823e5440015f0ca;p=tt-rss.git allow adding cats from feed editor --- diff --git a/functions.js b/functions.js index b9096706..f3ae1965 100644 --- a/functions.js +++ b/functions.js @@ -2169,3 +2169,50 @@ function has_local_storage() { return false; } } + +function catSelectOnChange(elem) { + try { + var value = elem[elem.selectedIndex].value; + var def = elem.getAttribute('default'); + + if (value == "ADD_CAT") { + + if (def) + dropboxSelect(elem, def); + else + elem.selectedIndex = 0; + + quickAddCat(elem); + } + + } catch (e) { + exception_error("catSelectOnChange", e); + } +} + +function quickAddCat(select) { + try { + var cat = prompt(__("Please enter category title:")); + + if (cat) { + + var query = "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat); + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function (transport) { + var response = transport.responseXML; + + var payload = response.getElementsByTagName("payload")[0]; + + if (payload) + select.innerHTML = payload.firstChild.nodeValue; + + } }); + + } + + } catch (e) { + exception_error("quickAddCat", e); + } +} diff --git a/functions.php b/functions.php index 8ef14d70..5c63eae0 100644 --- a/functions.php +++ b/functions.php @@ -3018,7 +3018,7 @@ function print_feed_cat_select($link, $id, $default_id = "", $attributes = "", $include_all_cats = true) { - print ""; if ($include_all_cats) { print ""; @@ -3041,6 +3041,8 @@ $line["id"], htmlspecialchars($line["title"])); } + print ""; + print ""; } @@ -6577,6 +6579,27 @@ } } + function add_feed_category($link, $feed_cat) { + db_query($link, "BEGIN"); + + $result = db_query($link, + "SELECT id FROM ttrss_feed_categories + WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + + $result = db_query($link, + "INSERT INTO ttrss_feed_categories (owner_uid,title) + VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); + + db_query($link, "COMMIT"); + + return true; + } + + return false; + } + function remove_feed_category($link, $id, $owner_uid) { db_query($link, "DELETE FROM ttrss_feed_categories diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index fee93a58..4a82a888 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -1094,6 +1094,31 @@ return; } + if ($subop == "quickAddCat") { + print ""; + + $cat = db_escape_string($_REQUEST["cat"]); + + add_feed_category($link, $cat); + + $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE + title = '$cat' AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) == 1) { + $id = db_fetch_result($result, 0, "id"); + } else { + $id = 0; + } + + print ""; + + print ""; + + return; + } + print "Unknown method: $subop"; } ?> diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index 376980ce..7a436cfd 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -1031,24 +1031,10 @@ if ($action == "add") { - $feed_cat = db_escape_string(trim($_REQUEST["cat"])); - $result = db_query($link, - "SELECT id FROM ttrss_feed_categories - WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); - - if (db_num_rows($result) == 0) { - - $result = db_query($link, - "INSERT INTO ttrss_feed_categories (owner_uid,title) - VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); - - } else { - - print_warning(T_sprintf("Category $%s already exists in the database.", - $feed_cat)); - } + if (!add_feed_category($link, $feed_cat)) + print_warning(T_sprintf("Category $%s already exists in the database.", $feed_cat)); }