]> git.wh0rd.org Git - tt-rss.git/commitdiff
properly handle on-the-fly adding of labels
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 9 Nov 2010 10:14:59 +0000 (13:14 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 9 Nov 2010 10:15:26 +0000 (13:15 +0300)
functions.js
functions.php
modules/pref-filters.php
modules/pref-labels.php

index ae4737dca7086e96b99a061aad5382b747e363ce..a9d90f1aab6c5c17b5d50049911170e26bb623b0 100644 (file)
@@ -2250,18 +2250,47 @@ function labelSelectOnChange(elem) {
                                elem.selectedIndex = 0;
 
                        addLabel(elem, function(transport) {
-                                       var response = transport.responseXML;
 
-                                       var payload = response.getElementsByTagName("payload")[0];
+                                       try {
 
-                                       if (payload)
-                                               elem.innerHTML = payload.firstChild.nodeValue;
+                                               var response = transport.responseXML;
+                                               var select = response.getElementsByTagName("select")[0];
+                                               var options = select.getElementsByTagName("option");
+
+                                               dropbox_replace_options(elem, options);
+
+                                               notify('');
+                                       } catch (e) {
+                                               exception_error("addLabel", e);
+                                       }
                        });
                }
 
        } catch (e) {
-               exception_error("catSelectOnChange", e);
+               exception_error("labelSelectOnChange", e);
        }
 }
 
+function dropbox_replace_options(elem, options) {
+
+       try {
+               while (elem.hasChildNodes())
+                       elem.removeChild(elem.firstChild);
+
+               var sel_idx = -1;
+
+               for (var i = 0; i < options.length; i++) {
+                       var text = options[i].firstChild.nodeValue;
+                       var value = options[i].getAttribute("value");
+                       var issel = options[i].getAttribute("selected") == "1";
+                       elem.insert(new Option(text, value, issel));
+                       if (issel) sel_idx = i;
+               }
 
+               // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
+               if (sel_idx >= 0) elem.selectedIndex = sel_idx;
+
+       } catch (e) {
+               exception_error("dropbox_replace_options", e);
+       }
+}
index c17d9d64e6edc5507369e2469734e7bc57add81e..f9de0622fe3a07cc7e38e210c6de6c9a15306519 100644 (file)
 
                while ($line = db_fetch_assoc($result)) {
                        if ($line["id"] == $default_id) {
-                               $is_selected = "selected";
+                               $is_selected = "selected=\"1\"";
                        } else {
                                $is_selected = "";
                        }
 
                while ($line = db_fetch_assoc($result)) {
                        if ($line["id"] == $default_id) {
-                               $is_selected = "selected";
+                               $is_selected = "selected=\"1\"";
                        } else {
                                $is_selected = "";
                        }
index c629f9c18b852e0c6aec64faaec6b9b91487e17b..18d25a82f90bb88b989f4ebb179791e5348551bc 100644 (file)
                $result = db_query($link, "SELECT caption FROM ttrss_labels2
                        WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption");
 
-               print "<select default=\"$value\" name=\"$name\" style=\"$style\" 
-                       onchange=\"labelSelectOnChange(this)\" >";
+               print "<select default=\"$value\" name=\"" . htmlspecialchars($name) . 
+                       "\" style=\"$style\" onchange=\"labelSelectOnChange(this)\" >";
 
                while ($line = db_fetch_assoc($result)) {
 
-                       $issel = ($line["caption"] == $value) ? "selected" : "";
+                       $issel = ($line["caption"] == $value) ? "selected=\"1\"" : "";
 
-                       print "<option $issel>" . $line["caption"] . "</option>";
+                       print "<option $issel>" . htmlspecialchars($line["caption"]) . "</option>";
 
                }
 
index d9cacecc366b52e39e63a184f910b1e4c37e4605..73d6e583f40b49f290a927a47ae682d424bd5ee1 100644 (file)
                                if ($output == "select") {
                                        header("Content-Type: text/xml");
 
-                                       print "<rpc-reply><payload><![CDATA[";
+                                       print "<rpc-reply><payload>";
 
                                        print_label_select($link, "select_label", 
                                                $caption, "");
 
-                                       print "]]></payload></rpc-reply>";
+                                       print "</payload></rpc-reply>";
                                }
                        }