]> git.wh0rd.org - tt-rss.git/blobdiff - prefs.js
refactor feed edit dialog
[tt-rss.git] / prefs.js
index c959e5dfa32b6ddd4640f44683861605210d09ea..5ca4e33383fa500666e60f64b7db1a8cfc1843d9 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -25,7 +25,6 @@ function feedlist_callback2(transport) {
                        caller_subop = false;
                }
                notify("");
-               remove_splash();
 
        } catch (e) {
                exception_error("feedlist_callback2", e);
@@ -35,7 +34,6 @@ function feedlist_callback2(transport) {
 function filterlist_callback2(transport) {
        dijit.byId('filterConfigTab').attr('content', transport.responseText); 
        notify("");
-       remove_splash();
 }
 
 function labellist_callback2(transport) {
@@ -46,7 +44,6 @@ function labellist_callback2(transport) {
                closeInfoBox();
 
                notify("");
-               remove_splash();
 
        } catch (e) {
                exception_error("labellist_callback2", e);
@@ -58,7 +55,6 @@ function userlist_callback2(transport) {
                dijit.byId('userConfigTab').attr('content', transport.responseText); 
 
                notify("");
-               remove_splash();
        } catch (e) {
                exception_error("userlist_callback2", e);
        }
@@ -69,7 +65,6 @@ function prefslist_callback2(transport) {
                dijit.byId('genConfigTab').attr('content', transport.responseText); 
 
                notify("");
-               remove_splash();
        } catch (e) {
                exception_error("prefslist_callback2", e);
        }
@@ -224,7 +219,7 @@ function addFeedCat() {
                                        infobox_callback2(transport);
                                } });
 
-               link.value = "";
+               cat.value = "";
 
        }
 }
@@ -293,63 +288,62 @@ function editUser(id, event) {
 }
 
 function editFilter(id, event) {
-
        try {
 
-               if (!event || !event.ctrlKey) {
+               var query = "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id);
 
-                       notify_progress("Loading, please wait...", true);
+               if (dijit.byId("filterEditDlg"))
+                       dijit.byId("filterEditDlg").destroyRecursive();
 
-                       var query = "?op=pref-filters&subop=edit&id=" + 
-                               param_escape(id);
-       
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) {
-                                               infobox_callback2(transport);
-                                               document.forms['filter_edit_form'].reg_exp.focus();
-                                       } });
-               } else if (event.ctrlKey) {
-                       var cb = $('FICHK-' + id);
-                       cb.checked = !cb.checked;
-                       toggleSelectRow(cb);
-               }
+               dialog = new dijit.Dialog({
+                       id: "filterEditDlg",
+                       title: __("Edit Filter"),
+                       style: "width: 600px",
+                       execute: function() {
+                               if (this.validate()) {
 
-       } catch (e) {
-               exception_error("editFilter", e);
-       }
-}
-
-function editFeed(feed, event) {
-
-       try {
+                                       var query = "?op=rpc&subop=verifyRegexp&reg_exp=" + 
+                                               param_escape(dialog.attr('value').reg_exp);
 
-               if (event && !event.ctrlKey) {
+                                       notify_progress("Verifying regular expression...");
 
-                       notify_progress("Loading, please wait...");
-
-//                     selectTableRows('prefFeedList', 'none');        
-//                     selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
-       
-                       var query = "?op=pref-feeds&subop=editfeed&id=" +
-                               param_escape(feed);
-       
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) {
-                                               infobox_callback2(transport);
-                                               document.forms["edit_feed_form"].title.focus();
-                                       } });
+                                       new Ajax.Request("backend.php", {
+                                               parameters: query,
+                                               onComplete: function(transport) {
+                                                       handle_rpc_reply(transport);
+                                                       var response = transport.responseXML;
+
+                                                       if (response) {
+                                                               var s = response.getElementsByTagName("status")[0].firstChild.nodeValue;
+       
+                                                               notify('');
+
+                                                               if (s == "INVALID") {
+                                                                       alert("Match regular expression seems to be invalid.");
+                                                                       return;
+                                                               } else {
+                                                                       notify_progress("Saving data...", true);
+
+                                                                       console.log(dojo.objectToQuery(dialog.attr('value')));
+
+                                                                       new Ajax.Request("backend.php", {
+                                                                               parameters: dojo.objectToQuery(dialog.attr('value')),
+                                                                               onComplete: function(transport) {
+                                                                                       dialog.hide();
+                                                                                       updateFilterList();                             
+                                                                       }})
+                                                               }       
+                                                       }
+                                       }});
+                               }
+                       },
+                       href: query});
 
-               } else if (event.ctrlKey) {
-//                     var cb = $('FRCHK-' + feed);
-//                     cb.checked = !cb.checked;
-//                     toggleSelectRow(cb);
-               }
+               dialog.show();
 
 
        } catch (e) {
-               exception_error("editFeed", e);
+               exception_error("editFilter", e);
        }
 }
 
@@ -652,46 +646,11 @@ function removeSelectedFeedCats() {
        return false;
 }
 
-function feedEditCancel() {
-       closeInfoBox();
-       return false;
-}
-
-function feedEditSave() {
-
-       try {
-       
-               // FIXME: add parameter validation
-
-               var query = Form.serialize("edit_feed_form");
-
-               notify_progress("Saving feed...");
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) { 
-                               feedlist_callback2(transport); 
-                       } });
-
-               closeInfoBox();
-
-               return false;
-
-       } catch (e) {
-               exception_error("feedEditSave", e);
-       } 
-}
-
 function userEditCancel() {
        closeInfoBox();
        return false;
 }
 
-function filterEditCancel() {
-       closeInfoBox();
-       return false;
-}
-
 function userEditSave() {
 
        try {
@@ -724,55 +683,6 @@ function userEditSave() {
 }
 
 
-function filterEditSave() {
-       try {
-               var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
-
-               var query = "?op=rpc&subop=verifyRegexp&reg_exp=" + param_escape(reg_exp);
-
-               notify_progress("Verifying regular expression...");
-
-               new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) {
-                                       handle_rpc_reply(transport);
-
-                                       var response = transport.responseXML;
-
-                                       if (response) {
-                                               var s = response.getElementsByTagName("status")[0].firstChild.nodeValue;
-       
-                                               notify('');
-
-                                               if (s == "INVALID") {
-                                                       alert("Match regular expression seems to be invalid.");
-                                                       return;
-                                               } else {
-
-                                                       var query = "?" + Form.serialize("filter_edit_form");
-                                       
-                                                       notify_progress("Saving filter...");
-                       
-                                                       Form.disable("filter_edit_form");
-
-                                                       new Ajax.Request("backend.php", {
-                                                                       parameters: query,
-                                                                       onComplete: function(transport) {
-                                                                                       closeInfoBox();
-                                                                                       filterlist_callback2(transport);
-                                                               } });
-                                               }
-                                       }
-                       } });
-
-       } catch (e) {
-               exception_error("filterEditSave", e);
-       }
-
-       return false;
-}
-
-
 function editSelectedUser() {
        var rows = getSelectedUsers();
 
@@ -1072,28 +982,22 @@ function init_second_stage() {
                        caller_subop = caller_subop + ":" + getURLParam("subopparam");
                }
 
-               loading_set_progress(60);
+               loading_set_progress(50);
 
                notify("");
 
                dojo.addOnLoad(function() {
 
-                       var active_tab = getInitParam("prefs_active_tab");
-                       if (!$(active_tab+"Tab")) active_tab = "genConfig";
-                       if (!active_tab || active_tab == '0') active_tab = "genConfig";
-
-                       var http_tab = getURLParam('tab');
-
-                       if (http_tab) active_tab = http_tab;
+                       var tab = getURLParam('tab');
 
-                       var tab = dijit.byId(active_tab + "Tab");
-
-                       if (tab) dijit.byId("pref-tabs").selectChild(tab);
+                       if (tab) {
+                               tab = dijit.byId(tab + "Tab");
+                               if (tab) dijit.byId("pref-tabs").selectChild(tab);
+                       }
 
                        });
 
                setTimeout("hotkey_prefix_timeout()", 5*1000);
-               remove_splash();
 
        } catch (e) {
                exception_error("init_second_stage", e);
@@ -1110,7 +1014,11 @@ function init() {
                dojo.require("dijit.layout.ContentPane");
                dojo.require("dijit.Dialog");
                dojo.require("dijit.form.Button");
+               dojo.require("dijit.form.Select");
+               dojo.require("dijit.form.FilteringSelect");
                dojo.require("dijit.form.TextBox");
+               dojo.require("dijit.form.CheckBox");
+               dojo.require("dijit.form.ValidationTextBox");
                dojo.require("dijit.form.RadioButton");
                dojo.require("dijit.form.Select");
                dojo.require("dijit.Toolbar");
@@ -1122,6 +1030,7 @@ function init() {
                dojo.require("dijit.tree.dndSource");
                dojo.require("dijit.InlineEditBox");
                dojo.require("dijit.ColorPalette");
+               dojo.require("dijit.ProgressBar"); 
 
                dojo.registerModulePath("lib", "..");
                dojo.registerModulePath("fox", "../..");
@@ -1131,15 +1040,15 @@ function init() {
                dojo.require("fox.PrefFilterTree");
                dojo.require("fox.PrefLabelTree");
 
-               loading_set_progress(30);
-
-               var query = "?op=rpc&subop=sanityCheck";
+               dojo.addOnLoad(function() {
+                       loading_set_progress(50);
 
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) { 
-                               backend_sanity_check_callback(transport);
-                       } });
+                       new Ajax.Request("backend.php", {
+                               parameters: {op: "rpc", subop: "sanityCheck"},
+                                       onComplete: function(transport) { 
+                                       backend_sanity_check_callback(transport);
+                               } });
+               });
 
        } catch (e) {
                exception_error("init", e);
@@ -1655,8 +1564,8 @@ function removeFilter(id, title) {
                var ok = confirm(msg);
        
                if (ok) {
-                       closeInfoBox();
-       
+                       dijit.byId("filterEditDlg").hide();
+
                        notify_progress("Removing filter...");
                
                        var query = "?op=pref-filters&subop=remove&ids="+
@@ -1966,18 +1875,42 @@ function editCat(id, item, event) {
 
 function editLabel(id, event) {
        try {
-               var query = "?op=pref-labels&subop=edit&id=" +
+               var query = "backend.php?op=pref-labels&subop=edit&id=" +
                        param_escape(id);
 
-               notify_progress("Loading, please wait...", true);
+               if (dijit.byId("labelEditDlg"))
+                       dijit.byId("labelEditDlg").destroyRecursive();
+
+               dialog = new dijit.Dialog({
+                       id: "labelEditDlg",
+                       title: __("Label Editor"),
+                       style: "width: 600px",
+                       execute: function() {
+                               if (this.validate()) {
+                                       var caption = this.attr('value').id;
+                                       var caption = this.attr('value').caption;
+                                       var fg_color = this.attr('value').fg_color;
+                                       var bg_color = this.attr('value').bg_color;
+                                       var query = dojo.objectToQuery(this.attr('value'));
+
+                                       dijit.byId('labelTree').setNameById(id, caption);
+                                       setLabelColor(id, fg_color, bg_color);
+                                       this.hide();
+
+                                       new Ajax.Request("backend.php", {
+                                               parameters: query,
+                                               onComplete: function(transport) {
+                                                       updateFilterList();     
+                                       } });
+                               }
+                       },
+                       href: query});
 
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               infobox_callback2(transport);
-                       } });
+               dialog.show();
 
        } catch (e) {
                exception_error("editLabel", e);
        }
 }
+
+