From 10249c41b763a373926d9b1f78b7b8cef68e411b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 9 Nov 2010 13:14:59 +0300 Subject: [PATCH] properly handle on-the-fly adding of labels --- functions.js | 39 ++++++++++++++++++++++++++++++++++----- functions.php | 4 ++-- modules/pref-filters.php | 8 ++++---- modules/pref-labels.php | 4 ++-- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/functions.js b/functions.js index ae4737dca..a9d90f1aa 100644 --- a/functions.js +++ b/functions.js @@ -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); + } +} diff --git a/functions.php b/functions.php index c17d9d64e..f9de0622f 100644 --- a/functions.php +++ b/functions.php @@ -3020,7 +3020,7 @@ while ($line = db_fetch_assoc($result)) { if ($line["id"] == $default_id) { - $is_selected = "selected"; + $is_selected = "selected=\"1\""; } else { $is_selected = ""; } @@ -3052,7 +3052,7 @@ while ($line = db_fetch_assoc($result)) { if ($line["id"] == $default_id) { - $is_selected = "selected"; + $is_selected = "selected=\"1\""; } else { $is_selected = ""; } diff --git a/modules/pref-filters.php b/modules/pref-filters.php index c629f9c18..18d25a82f 100644 --- a/modules/pref-filters.php +++ b/modules/pref-filters.php @@ -523,14 +523,14 @@ $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption"); - print ""; while ($line = db_fetch_assoc($result)) { - $issel = ($line["caption"] == $value) ? "selected" : ""; + $issel = ($line["caption"] == $value) ? "selected=\"1\"" : ""; - print ""; + print ""; } diff --git a/modules/pref-labels.php b/modules/pref-labels.php index d9cacecc3..73d6e583f 100644 --- a/modules/pref-labels.php +++ b/modules/pref-labels.php @@ -107,12 +107,12 @@ if ($output == "select") { header("Content-Type: text/xml"); - print ""; print_label_select($link, "select_label", $caption, ""); - print "]]>"; + print ""; } }