From 7b8a143f1b523a5b70b92af8389af1cb1cb0a844 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 18 Nov 2010 13:46:11 +0300 Subject: [PATCH] allow onclick editing of categories and drag-reordering of feeds and categories --- PrefFeedTree.js | 20 +++++ backend.php | 25 ------ functions.php | 4 +- modules/pref-feeds.php | 191 ++++++++++++++++++++++++++++++++++++++--- prefs.js | 57 ++++++++++++ 5 files changed, 257 insertions(+), 40 deletions(-) diff --git a/PrefFeedTree.js b/PrefFeedTree.js index 026e5d489..511f4fafe 100644 --- a/PrefFeedTree.js +++ b/PrefFeedTree.js @@ -1,8 +1,28 @@ dojo.provide("fox.PrefFeedTree"); +dojo.provide("fox.PrefFeedStore"); dojo.require("lib.CheckBoxTree"); +dojo.declare("fox.PrefFeedStore", dojo.data.ItemFileWriteStore, { + + _saveEverything: function(saveCompleteCallback, saveFailedCallback, + newFileContentString) { + + dojo.xhrPost({ + url: "backend.php", + content: {op: "pref-feeds", subop: "savefeedorder", + payload: newFileContentString}, + error: saveFailedCallback, + load: saveCompleteCallback}); + }, + +}); + dojo.declare("fox.PrefFeedTree", lib.CheckBoxTree, { + onDndDrop: function() { + this.inherited(arguments); + this.tree.model.store.save(); + }, checkItemAcceptance: function(target, source, position) { var item = dijit.getEnclosingWidget(target).item; diff --git a/backend.php b/backend.php index 3d415eb5e..c17344a79 100644 --- a/backend.php +++ b/backend.php @@ -178,31 +178,6 @@ toggle_collapse_cat($link, $cat_id, $mode); return; break; - - case "catsortreset": - db_query($link, "UPDATE ttrss_feed_categories - SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); - return; - break; - - case "catsort": - $corder = db_escape_string($_REQUEST["corder"]); - - $cats = split(",", $corder); - - for ($i = 0; $i < count($cats); $i++) { - $cat_id = $cats[$i]; - - if ($cat_id > 0) { - db_query($link, "UPDATE ttrss_feed_categories - SET order_id = '$i' WHERE id = '$cat_id' AND - owner_uid = " . $_SESSION["uid"]); - } - } - - return; - break; - } if (!$root) { diff --git a/functions.php b/functions.php index 6fa9e9f27..1d1b2440d 100644 --- a/functions.php +++ b/functions.php @@ -4278,7 +4278,8 @@ } */ if ($enable_cats) - $order_by_qpart = "order_id,category,title"; + $order_by_qpart = "ttrss_feed_categories.order_id,category, + ttrss_feeds.order_id,title"; else $order_by_qpart = "title"; @@ -7029,7 +7030,6 @@ $obj['error'] = $error; $obj['updated'] = $updated; $obj['icon'] = getFeedIcon($feed_id); - $obj['checkbox'] = false; $obj['bare_id'] = $feed_id; return $obj; diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index 3eb3c4621..f6776e20d 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -15,6 +15,159 @@ $quiet = $_REQUEST["quiet"]; $mode = $_REQUEST["mode"]; + if ($subop == "renamecat") { + $title = db_escape_string($_REQUEST['title']); + $id = db_escape_string($_REQUEST['id']); + + if ($title) { + db_query($link, "UPDATE ttrss_feed_categories SET + title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); + } + return; + } + + if ($subop == "getfeedtree") { + + $root = array(); + $root['id'] = 'root'; + $root['name'] = __('Feeds'); + $root['items'] = array(); + + if (get_pref($link, 'ENABLE_FEED_CATS')) { + + $result = db_query($link, "SELECT id, title FROM ttrss_feed_categories + WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY order_id, title"); + + while ($line = db_fetch_assoc($result)) { + $cat = array(); + $cat['id'] = 'CAT:' . $line['id']; + $cat['bare_id'] = $feed_id; + $cat['name'] = $line['title']; + $cat['items'] = array(); + + $feed_result = db_query($link, "SELECT id, title FROM ttrss_feeds + WHERE cat_id = '".$line['id']."' AND owner_uid = ".$_SESSION["uid"]. + " ORDER BY order_id, title"); + + while ($feed_line = db_fetch_assoc($feed_result)) { + $feed = array(); + $feed['id'] = 'FEED:' . $feed_line['id']; + $feed['bare_id'] = $feed_line['id']; + $feed['name'] = $feed_line['title']; + $feed['checkbox'] = false; + array_push($cat['items'], $feed); + } + + array_push($root['items'], $cat); + } + + /* Uncategorized is a special case */ + + $cat = array(); + $cat['id'] = 'CAT:0'; + $cat['bare_id'] = 0; + $cat['name'] = __("Uncategorized"); + $cat['items'] = array(); + + $feed_result = db_query($link, "SELECT id, title FROM ttrss_feeds + WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"]. + " ORDER BY order_id, title"); + + while ($feed_line = db_fetch_assoc($feed_result)) { + $feed = array(); + $feed['id'] = 'FEED:' . $feed_line['id']; + $feed['bare_id'] = $feed_line['id']; + $feed['name'] = $feed_line['title']; + $feed['checkbox'] = false; + array_push($cat['items'], $feed); + } + + array_push($root['items'], $cat); + } else { + $feed_result = db_query($link, "SELECT id, title FROM ttrss_feeds + WHERE owner_uid = ".$_SESSION["uid"]. + " ORDER BY order_id, title"); + + while ($feed_line = db_fetch_assoc($feed_result)) { + $feed = array(); + $feed['id'] = 'FEED:' . $feed_line['id']; + $feed['bare_id'] = $feed_line['id']; + $feed['name'] = $feed_line['title']; + $feed['checkbox'] = false; + array_push($root['items'], $feed); + } + } + + $fl = array(); + $fl['identifier'] = 'id'; + $fl['label'] = 'name'; + $fl['items'] = array($root); + + print json_encode($fl); + return; + } + + if ($subop == "catsortreset") { + db_query($link, "UPDATE ttrss_feed_categories + SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); + return; + } + + if ($subop == "feedsortreset") { + db_query($link, "UPDATE ttrss_feeds + SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); + return; + } + + if ($subop == "savefeedorder") { + if ($_POST['payload']) { + file_put_contents("/tmp/blahblah.txt", $_POST['payload']); + } + + $data = file_get_contents("/tmp/blahblah.txt"); + $data = json_decode($data, true); + + if (is_array($data) && is_array($data['items'])) { + $cat_order_id = 0; + + $data_map = array(); + + foreach ($data['items'] as $item) { + $data_map[$item['id']] =& $item['items']; + } + + foreach ($data['items'][0]['items'] as $item) { + $id = $item['_reference']; + $bare_id = substr($id, strpos($id, ':')+1); + + ++$cat_order_id; + + if ($bare_id > 0) { + db_query($link, "UPDATE ttrss_feed_categories + SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND + owner_uid = " . $_SESSION["uid"]); + } + + $feed_order_id = 0; + + if (is_array($data_map[$id])) { + foreach ($data_map[$id] as $feed) { + $id = $feed['_reference']; + $bare_id = substr($id, strpos($id, ':')+1); + + db_query($link, "UPDATE ttrss_feeds + SET order_id = '$feed_order_id' WHERE id = '$bare_id' AND + owner_uid = " . $_SESSION["uid"]); + + ++$feed_order_id; + } + } + } + } + + return; + } + if ($subop == "removeicon") { $feed_id = db_escape_string($_REQUEST["feed_id"]); @@ -1004,16 +1157,27 @@ dojoType=\"dijit.MenuItem\">".__('None').""; print ""; - print " "; - - print " "; + print "
". + "" . __('Feeds').""; + print "
"; + print "
".__('Subscribe to feed')."
"; + print "
".__('Edit feeds')."
"; + print "
".__('Reset sort order')."
"; + print "
"; if (get_pref($link, 'ENABLE_FEED_CATS')) { + print "
". + "" . __('Categories').""; + print "
"; + print "
".__('Edit categories')."
"; + print "
".__('Reset sort order')."
"; + print "
"; - print " "; } print $error_button; @@ -1045,8 +1209,8 @@ ". __("Loading, please wait...").""; - print "
+ print "