]> git.wh0rd.org Git - tt-rss.git/commitdiff
allow adding labels on the fly
authorAndrew Dolgov <fox@fakecake.org>
Mon, 8 Nov 2010 22:04:00 +0000 (01:04 +0300)
committerAndrew Dolgov <fox@fakecake.org>
Mon, 8 Nov 2010 22:04:00 +0000 (01:04 +0300)
functions.js
modules/pref-filters.php
modules/pref-labels.php

index af18f8383629e52ab694af6fffc5e12f7b567255..ae4737dca7086e96b99a061aad5382b747e363ce 100644 (file)
@@ -1983,7 +1983,7 @@ function uploadFeedIcon() {
        }
 }
 
-function addLabel() {
+function addLabel(select, callback) {
 
        try {
 
@@ -1999,14 +1999,19 @@ function addLabel() {
                        var query = "?op=pref-labels&subop=add&caption=" + 
                                param_escape(caption);
 
+                       if (select)
+                               query += "&output=select";
+
                        notify_progress("Loading, please wait...", true);
 
-                       if (inPreferences()) active_tab = "labelConfig";
+                       if (inPreferences() && !select) active_tab = "labelConfig";
 
                        new Ajax.Request("backend.php", {
                                parameters: query,
                                onComplete: function(transport) { 
-                                       if (inPreferences()) {
+                                       if (callback) {
+                                               callback(transport);
+                                       } else if (inPreferences()) {
                                                infobox_submit_callback2(transport);
                                        } else {
                                                updateFeedList();
@@ -2232,3 +2237,31 @@ function genUrlChangeKey(feed, is_cat) {
        return false;
 }
 
+function labelSelectOnChange(elem) {
+       try {
+               var value = elem[elem.selectedIndex].value;
+               var def = elem.getAttribute('default');
+
+               if (value == "ADD_LABEL") {
+
+                       if (def)
+                               dropboxSelect(elem, def);
+                       else
+                               elem.selectedIndex = 0;
+
+                       addLabel(elem, function(transport) {
+                                       var response = transport.responseXML;
+
+                                       var payload = response.getElementsByTagName("payload")[0];
+
+                                       if (payload)
+                                               elem.innerHTML = payload.firstChild.nodeValue;
+                       });
+               }
+
+       } catch (e) {
+               exception_error("catSelectOnChange", e);
+       }
+}
+
+
index f3ca8e4cb4557f37c8f08bd016dd809143ead544..c629f9c18b852e0c6aec64faaec6b9b91487e17b 100644 (file)
                $result = db_query($link, "SELECT caption FROM ttrss_labels2
                        WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption");
 
-               print "<select name=\"$name\" style=\"$style\">";
+               print "<select default=\"$value\" name=\"$name\" style=\"$style\" 
+                       onchange=\"labelSelectOnChange(this)\" >";
 
                while ($line = db_fetch_assoc($result)) {
 
 
                }
 
+               print "<option value=\"ADD_LABEL\">" .__("Add label...") . "</option>";
+
                print "</select>";
 
 
index a744b9f6a893c37300992aa2700fd43aa210ddff..d9cacecc366b52e39e63a184f910b1e4c37e4605 100644 (file)
                }
 
                if ($subop == "add") {
-
                        $caption = db_escape_string($_REQUEST["caption"]);
+                       $output = db_escape_string($_REQUEST["output"]);
 
                        if ($caption) {
 
                                if (label_create($link, $caption)) {
-                                       print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
+                                       if (!$output) {
+                                               print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
+                                       }
                                }
 
+                               if ($output == "select") {
+                                       header("Content-Type: text/xml");
+
+                                       print "<rpc-reply><payload><![CDATA[";
+
+                                       print_label_select($link, "select_label", 
+                                               $caption, "");
+
+                                       print "]]></payload></rpc-reply>";
+                               }
                        }
 
                        return;