]> git.wh0rd.org - tt-rss.git/blobdiff - functions.js
allow adding labels on the fly
[tt-rss.git] / functions.js
index f3756051f218a295eea2d8b8da7746f824446e5e..ae4737dca7086e96b99a061aad5382b747e363ce 100644 (file)
@@ -1319,6 +1319,7 @@ function subscribeToFeed() {
                                }
                                break;
                        case 2:
+                       case 3:
                                alert(__("Can't subscribe to the specified URL."));
                                break;
                        case 0:
@@ -1633,36 +1634,6 @@ function openArticleInNewWindow(id) {
        }
 }
 
-/* http://textsnippets.com/posts/show/835 */
-
-Position.GetWindowSize = function(w) {
-        w = w ? w : window;
-        var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
-        var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
-        return [width, height]
-}
-
-/* http://textsnippets.com/posts/show/836 */
-
-Position.Center = function(element, parent) {
-        var w, h, pw, ph;
-        var d = Element.getDimensions(element);
-        w = d.width;
-        h = d.height;
-        Position.prepare();
-        if (!parent) {
-                var ws = Position.GetWindowSize();
-                pw = ws[0];
-                ph = ws[1];
-        } else {
-                pw = parent.offsetWidth;
-                ph = parent.offsetHeight;
-        }
-        element.style.top = (ph/2) - (h/2) -  Position.deltaY + "px";
-        element.style.left = (pw/2) - (w/2) -  Position.deltaX + "px";
-}
-
-
 function isCdmMode() {
        return !$("headlinesList");
 }
@@ -2012,7 +1983,7 @@ function uploadFeedIcon() {
        }
 }
 
-function addLabel() {
+function addLabel(select, callback) {
 
        try {
 
@@ -2028,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();
@@ -2261,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);
+       }
+}
+
+