From 1c31e1908a1c8d8e46df83a756f2a5ad445ceb70 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 9 Nov 2010 01:04:00 +0300 Subject: allow adding labels on the fly --- functions.js | 39 ++++++++++++++++++++++++++++++++++++--- modules/pref-filters.php | 5 ++++- modules/pref-labels.php | 16 ++++++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/functions.js b/functions.js index af18f8383..ae4737dca 100644 --- a/functions.js +++ b/functions.js @@ -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); + } +} + + diff --git a/modules/pref-filters.php b/modules/pref-filters.php index f3ca8e4cb..c629f9c18 100644 --- a/modules/pref-filters.php +++ b/modules/pref-filters.php @@ -523,7 +523,8 @@ $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption"); - print ""; while ($line = db_fetch_assoc($result)) { @@ -533,6 +534,8 @@ } + print ""; + print ""; diff --git a/modules/pref-labels.php b/modules/pref-labels.php index a744b9f6a..d9cacecc3 100644 --- a/modules/pref-labels.php +++ b/modules/pref-labels.php @@ -93,15 +93,27 @@ } 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 %s", htmlspecialchars($caption)); + if (!$output) { + print T_sprintf("Created label %s", htmlspecialchars($caption)); + } } + if ($output == "select") { + header("Content-Type: text/xml"); + + print ""; + } } return; -- cgit v1.2.3