summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/pref_feeds.php162
-rw-r--r--js/PrefFeedTree.js45
-rw-r--r--js/prefs.js85
3 files changed, 79 insertions, 213 deletions
diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php
index 381330da0..bddf32185 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 <b>$%s</b> 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 "<div dojoType=\"dijit.Toolbar\">";
-
- print "<div dojoType=\"dijit.form.DropDownButton\">".
- "<span>" . __('Select')."</span>";
- print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
- print "<div onclick=\"selectTableRows('prefFeedCatList', 'all')\"
- dojoType=\"dijit.MenuItem\">".__('All')."</div>";
- print "<div onclick=\"selectTableRows('prefFeedCatList', 'none')\"
- dojoType=\"dijit.MenuItem\">".__('None')."</div>";
- print "</div></div>";
-
- print "<div style='float : right'>";
-
- print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"newcat\">
- <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').addCategory()\">".
- __('Create category')."</button></div>";
-
- print "</div>";
-
- $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 "<div class=\"prefFeedCatHolder\">";
-
- print "<table width=\"100%\" class=\"prefFeedCatList\"
- cellspacing=\"0\" id=\"prefFeedCatList\">";
-
- $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 "<tr class=\"placeholder\" $this_row_id>";
-
- $edit_title = htmlspecialchars($line["title"]);
-
- print "<td width='5%' align='center'><input id=\"FCATC-$cat_id\"
- onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
- type=\"checkbox\"></td>";
-
- print "<td>";
-
- if ($line['count'] == 0) print '<em>';
-
- print "<span dojoType=\"dijit.InlineEditBox\"
- width=\"300px\" autoSave=\"false\"
- cat-id=\"$cat_id\">" . $edit_title .
- "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
- var elem = this;
- dojo.xhrPost({
- url: 'backend.php',
- content: {op: 'pref-feeds', method: 'editCats',
- action: 'save',
- value: this.value,
- cid: this.srcNodeRef.getAttribute('cat-id')},
- load: function(response) {
- elem.attr('value', response);
- updateFeedList();
- }
- });
- </script>
- </span>";
-
- if ($line['count'] == 0) print '</em>';
-
- print "</td>";
-
- print "<td align='right' class='insensitive'>";
- echo T_sprintf("%d feeds", $line['count']);
- print "</td></tr>";
-
- ++$lnum;
- }
-
- print "</table>";
- print "</div>";
-
- } else {
- print "<p>".__('No feed categories defined.')."</p>";
- }
-
- print "<div class='dlgButtons'>
- <div style='float : left'>
- <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').removeSelected()\">".
- __('Remove selected categories')."</button>
- </div>";
-
- print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').hide()\">".
- __('Close this window')."</button></div>";
-
- return;
-
- }
-
function index() {
print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
@@ -1530,8 +1372,8 @@ class Pref_Feeds extends Protected_Handler {
print "<div dojoType=\"dijit.form.DropDownButton\">".
"<span>" . __('Categories')."</span>";
print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
- print "<div onclick=\"editFeedCats()\"
- dojoType=\"dijit.MenuItem\">".__('Edit categories')."</div>";
+ print "<div onclick=\"createCategory()\"
+ dojoType=\"dijit.MenuItem\">".__('Add category')."</div>";
print "<div onclick=\"toggleHiddenFeedCats()\"
dojoType=\"dijit.MenuItem\">".__('(Un)hide empty categories')."</div>";
print "<div onclick=\"resetCatOrder()\"
diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js
index 12c02c447..942793c76 100644
--- a/js/PrefFeedTree.js
+++ b/js/PrefFeedTree.js
@@ -35,6 +35,51 @@ dojo.declare("fox.PrefFeedTree", lib.CheckBoxTree, {
dojo.place(param, tnode.labelNode, 'after');
}
+ var id = args.item.id[0];
+ var bare_id = parseInt(id.substr(id.indexOf(':')+1));
+
+ if (id.match("CAT:") && bare_id > 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 4ca3ec182..c0ad6a86e 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);
}
}