]> git.wh0rd.org - tt-rss.git/commitdiff
remove old category editor
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 15 Aug 2012 05:38:57 +0000 (09:38 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 15 Aug 2012 05:38:57 +0000 (09:38 +0400)
allow creating/removing categories in main feed editor

classes/pref_feeds.php
js/PrefFeedTree.js
js/prefs.js

index 381330da0c2b6c1ecf3a68003313acc50cf83cee..bddf321852f268a641ee1f782ebb5ae87d4ab3b5 100644 (file)
@@ -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()\"
index 12c02c4479d037cf9daa7e22497cf2159f353d7a..942793c768b4d0f798d8186819365a6c8aaa973d 100644 (file)
@@ -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() {
index 4ca3ec182188d85ec6cbe4095a547feefc7b8b01..c0ad6a86e634d99d6bb58b5fa67e6ff455f8dfed 100644 (file)
@@ -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);
        }
 }