From 5ef071e00ba62c5b66a594b55185ef87012dc40a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 15 Aug 2012 09:38:57 +0400 Subject: [PATCH] remove old category editor allow creating/removing categories in main feed editor --- classes/pref_feeds.php | 162 +---------------------------------------- js/PrefFeedTree.js | 45 ++++++++++++ js/prefs.js | 85 ++++++++------------- 3 files changed, 79 insertions(+), 213 deletions(-) diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php index 381330da..bddf3218 100644 --- a/classes/pref_feeds.php +++ b/classes/pref_feeds.php @@ -1290,164 +1290,6 @@ class Pref_Feeds extends Protected_Handler { db_query($this->link, "COMMIT"); } - function editCats() { - - $action = $_REQUEST["action"]; - - if ($action == "save") { - - $cat_title = db_escape_string(trim($_REQUEST["value"])); - $cat_id = db_escape_string($_REQUEST["cid"]); - - db_query($this->link, "BEGIN"); - - $result = db_query($this->link, "SELECT title FROM ttrss_feed_categories - WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]); - - if (db_num_rows($result) == 1) { - - $old_title = db_fetch_result($result, 0, "title"); - - if ($cat_title != "") { - $result = db_query($this->link, "UPDATE ttrss_feed_categories SET - title = '$cat_title' WHERE id = '$cat_id' AND - owner_uid = ".$_SESSION["uid"]); - - print $cat_title; - } else { - print $old_title; - } - } else { - print $_REQUEST["value"]; - } - - db_query($this->link, "COMMIT"); - - return; - - } - - if ($action == "add") { - - $feed_cat = db_escape_string(trim($_REQUEST["cat"])); - - if (!add_feed_category($this->link, $feed_cat)) - print_warning(T_sprintf("Category $%s already exists in the database.", $feed_cat)); - - } - - if ($action == "remove") { - - $ids = split(",", db_escape_string($_REQUEST["ids"])); - - foreach ($ids as $id) { - remove_feed_category($this->link, $id, $_SESSION["uid"]); - } - } - - print "
"; - - print "
". - "" . __('Select').""; - print "
"; - print "
".__('All')."
"; - print "
".__('None')."
"; - print "
"; - - print "
"; - - print " -
"; - - print "
"; - - $result = db_query($this->link, "SELECT c.title, c.id,COUNT(f.id) AS count - FROM ttrss_feed_categories AS c LEFT JOIN ttrss_feeds AS f ON - (f.cat_id = c.id) - WHERE c.owner_uid = ".$_SESSION["uid"]." - GROUP BY c.title, c.id ORDER BY title"); - - if (db_num_rows($result) != 0) { - - print "
"; - - print ""; - - $lnum = 0; - - while ($line = db_fetch_assoc($result)) { - - $class = ($lnum % 2) ? "even" : "odd"; - - $cat_id = $line["id"]; - $this_row_id = "id=\"FCATR-$cat_id\""; - - print ""; - - $edit_title = htmlspecialchars($line["title"]); - - print ""; - - print ""; - - print ""; - - ++$lnum; - } - - print "
"; - - if ($line['count'] == 0) print ''; - - print "" . $edit_title . - " - "; - - if ($line['count'] == 0) print ''; - - print ""; - echo T_sprintf("%d feeds", $line['count']); - print "
"; - print "
"; - - } else { - print "

".__('No feed categories defined.')."

"; - } - - print "
-
- -
"; - - print "
"; - - return; - - } - function index() { print "
"; @@ -1530,8 +1372,8 @@ class Pref_Feeds extends Protected_Handler { print "
". "" . __('Categories').""; print "
"; - print "
".__('Edit categories')."
"; + print "
".__('Add category')."
"; print "
".__('(Un)hide empty categories')."
"; print "
0) { + var menu = new dijit.Menu(); + menu.row_id = bare_id; + menu.item = args.item; + + menu.addChild(new dijit.MenuItem({ + label: __("Edit category"), + onClick: function() { + editCat(this.getParent().row_id, this.getParent().item, null); + }})); + + + menu.addChild(new dijit.MenuItem({ + label: __("Remove category"), + onClick: function() { + removeCategory(this.getParent().row_id, this.getParent().item); + }})); + + menu.bindDomNode(tnode.domNode); + tnode._menu = menu; + } else if (id.match("FEED:")) { + var menu = new dijit.Menu(); + menu.row_id = bare_id; + menu.item = args.item; + + menu.addChild(new dijit.MenuItem({ + label: __("Edit feed"), + onClick: function() { + editFeed(this.getParent().row_id); + }})); + + menu.addChild(new dijit.MenuItem({ + label: __("Unsubscribe"), + onClick: function() { + unsubscribeFeed(this.getParent().row_id, this.getParent().item.name); + }})); + + menu.bindDomNode(tnode.domNode); + tnode._menu = menu; + + } + return tnode; }, onDndDrop: function() { diff --git a/js/prefs.js b/js/prefs.js index 4ca3ec18..c0ad6a86 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -1169,72 +1169,51 @@ function pref_hotkey_handler(e) { } } -function editFeedCats() { +function removeCategory(id, item) { try { - var query = "backend.php?op=pref-feeds&method=editCats"; - if (dijit.byId("feedCatEditDlg")) - dijit.byId("feedCatEditDlg").destroyRecursive(); + var ok = confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name)); - dialog = new dijit.Dialog({ - id: "feedCatEditDlg", - title: __("Feed Categories"), - style: "width: 600px", - getSelectedCategories: function() { - return getSelectedTableRowIds("prefFeedCatList"); - }, - removeSelected: function() { - var sel_rows = this.getSelectedCategories(); - - if (sel_rows.length > 0) { - var ok = confirm(__("Remove selected categories?")); + if (ok) { + var query = "?op=pref-feeds&method=editCats&action=remove&ids="+ + param_escape(id); - if (ok) { - notify_progress("Removing selected categories...", true); + notify_progress("Removing category..."); - var query = "?op=pref-feeds&method=editCats&action=remove&ids="+ - param_escape(sel_rows.toString()); + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + notify(''); + updateFeedList(); + } }); + } - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - notify(''); - dialog.attr('content', transport.responseText); - updateFeedList(); - } }); + } catch (e) { + exception_error("removeCategory", e); + } +} - } +function createCategory() { + try { + var title = prompt(__("Category title:")); - } else { - alert(__("No categories are selected.")); - } - }, - addCategory: function() { - if (this.validate()) { - notify_progress("Creating category..."); + if (title) { - var query = "?op=pref-feeds&method=editCats&action=add&cat=" + - param_escape(this.attr('value').newcat); + notify_progress("Creating category..."); - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - notify(''); - dialog.attr('content', transport.responseText); - updateFeedList(); - } }); - } - }, - execute: function() { - if (this.validate()) { - } - }, - href: query}); + var query = "?op=pref-feeds&method=editCats&action=add&cat=" + + param_escape(title); - dialog.show(); + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + notify(''); + updateFeedList(); + } }); + } } catch (e) { - exception_error("editFeedCats", e); + exception_error("createCategory", e); } } -- 2.39.2