]> git.wh0rd.org Git - tt-rss.git/commitdiff
rework prefs profile dialog
authorAndrew Dolgov <fox@fakecake.org>
Sun, 21 Nov 2010 09:50:14 +0000 (12:50 +0300)
committerAndrew Dolgov <fox@fakecake.org>
Sun, 21 Nov 2010 09:50:41 +0000 (12:50 +0300)
modules/popup-dialog.php
modules/pref-feeds.php
prefs.js

index 062542a1cf27511a1fa18d7a3d0b13baabcfc7a5..1b90ecfd7d44ea65bd822c1a569e0fbe3103d04e 100644 (file)
 
                if ($id == "editPrefProfiles") {
 
-                       print "<title>".__('Settings Profiles')."</title>";
-                       print "<content><![CDATA[";
-
-                       print "<div><input id=\"fadd_profile\" 
-                                       onkeypress=\"return filterCR(event, addPrefProfile)\"
-                                       size=\"40\">
-                                       <button onclick=\"javascript:addPrefProfile()\">".
+                       print "<div dojoType=\"dijit.Toolbar\">";
+
+#                      TODO: depends on selectTableRows() being broken for this list
+#                      print "<div dojoType=\"dijit.form.DropDownButton\">".
+#                              "<span>" . __('Select')."</span>";
+#                      print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+#                      print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\" 
+#                              dojoType=\"dijit.MenuItem\">".__('All')."</div>";
+#                      print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\" 
+#                              dojoType=\"dijit.MenuItem\">".__('None')."</div>";
+#                      print "</div></div>";
+
+#                      print "<div style='float : right'>";
+                       print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
+                                       required=\"1\">
+                               <button dojoType=\"dijit.form.Button\" 
+                               onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
                                        __('Create profile')."</button></div>";
 
-                       print "<p>";
+#                      print "</div>";
+
 
                        $result = db_query($link, "SELECT title,id FROM ttrss_settings_profiles
                                WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
 
-                       print   __('Select:')." 
-                               <a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'all')\">".__('All')."</a>,
-                               <a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'none')\">".__('None')."</a>";
-
                        print "<div class=\"prefFeedCatHolder\">";
 
                        print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
 
-                       print "<table width=\"100%\" class=\"prefFeedCatList\" 
-                               cellspacing=\"0\" id=\"prefFeedCatList\">";
+                       print "<table width=\"100%\" class=\"prefFeedProfileList\" 
+                               cellspacing=\"0\" id=\"prefFeedProfileList\">";
 
-                       print "<tr class=\"odd\" id=\"FCATR-0\">";
+                       print "<tr class=\"\" id=\"FCATR-0\">"; #odd
 
                        print "<td width='5%' align='center'><input 
-                               onclick='toggleSelectRow(this);' 
-                               type=\"checkbox\" id=\"FCCHK-0\"></td>";
+                               onclick='toggleSelectRow2(this);' 
+                               dojoType=\"dijit.form.CheckBox\"
+                               type=\"checkbox\"></td>";
 
                        if (!$_SESSION["profile"]) {
                                $is_active = __("(active)");
                                $is_active = "";
                        }
 
-                       print "<td><span id=\"FCATT-0\">" . 
+                       print "<td><span>" . 
                                __("Default profile") . " $is_active</span></td>";
                                
                        print "</tr>";
        
                                $class = ($lnum % 2) ? "even" : "odd";
        
-                               $cat_id = $line["id"];
-                               $this_row_id = "id=\"FCATR-$cat_id\"";
+                               $profile_id = $line["id"];
+                               $this_row_id = "id=\"FCATR-$profile_id\"";
        
-                               print "<tr class=\"$class\" $this_row_id>";
+                               print "<tr class=\"\" $this_row_id>";
        
                                $edit_title = htmlspecialchars($line["title"]);
        
                                print "<td width='5%' align='center'><input 
-                                       onclick='toggleSelectRow(this);' 
-                                       type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
+                                       onclick='toggleSelectRow2(this);' 
+                                       dojoType=\"dijit.form.CheckBox\"
+                                       type=\"checkbox\"></td>";
 
                                if ($_SESSION["profile"] == $line["id"]) {
                                        $is_active = __("(active)");
                                        $is_active = "";
                                }
 
-                               print "<td><span id=\"FCATT-$cat_id\">" . 
-                                       $edit_title . "</span> $is_active</td>";
-                               
+                               print "<td><span dojoType=\"dijit.InlineEditBox\" 
+                                       width=\"300px\" autoSave=\"false\"
+                                       profile-id=\"$profile_id\">" . $edit_title .
+                                       "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
+                                               var elem = this;
+                                               dojo.xhrPost({
+                                                       url: 'backend.php',
+                                                       content: {op: 'rpc', subop: 'saveprofile',
+                                                               value: this.value,
+                                                               id: this.srcNodeRef.getAttribute('profile-id')},
+                                                               load: function(response) {
+                                                                       elem.attr('value', response);
+                                                       }
+                                               });     
+                                       </script>
+                               </span> $is_active</td>";
+                       
                                print "</tr>";
        
                                ++$lnum;
 
                        print "<div class='dlgButtons'>
                                <div style='float : left'>
-                               <button onclick=\"return removeSelectedPrefProfiles()\">".
-                               __('Remove')."</button>
-                               <button onclick=\"return activatePrefProfile()\">".
-                               __('Activate')."</button>
+                               <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
+                               __('Remove selected profiles')."</button>
+                               <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
+                               __('Activate profile')."</button>
                                </div>";
 
-                       print "<button onclick=\"return closeInfoBox()\">".
+                       print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
                                __('Close this window')."</button>";
-
                        print "</div>";
-                       print "]]></content>";
 
-                       //return;
                }
 
                if ($id == "pubOPMLUrl") {
index 0927b48375e538707b2b7a18d1fd7ab7e8d4f632..d82cb3f0d179805d5365378ed0d290e34ecfba72 100644 (file)
                
                                        print "<td width='5%' align='center'><input 
                                                onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" 
-                                               type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
+                                               type=\"checkbox\"></td>";
        
                                        print "<td>";
                                        
index d8276160989a800748ff0af04f603d90b2d17a08..6baa9a0d4981aca7628968501344cd3e55a655ec 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -72,26 +72,6 @@ function notify_callback2(transport) {
        notify_info(transport.responseText);     
 }
 
-function init_profile_inline_editor() {
-       try {
-
-               if ($("prefFeedCatList")) {
-                       var elems = $("prefFeedCatList").getElementsByTagName("SPAN");
-
-                       for (var i = 0; i < elems.length; i++) {
-                               if (elems[i].id && elems[i].id.match("FCATT-")) {
-                                       var id = elems[i].id.replace("FCATT-", "");
-                                               new Ajax.InPlaceEditor(elems[i],
-                                               'backend.php?op=rpc&subop=saveprofile&id=' + id);
-                               }
-                       }
-               }
-
-       } catch (e) {
-               exception_error("init_profile_inline_editor", e);
-       }
-}
-
 function updateFeedList(sort_key) {
 
        try {
@@ -145,51 +125,6 @@ function updateUsersList(sort_key) {
        }
 }
 
-function addPrefProfile() {
-
-       var profile = $("fadd_profile");
-
-       if (profile.value.length == 0) {
-               alert(__("Can't add profile: no name specified."));
-       } else {
-               notify_progress("Adding profile...");
-
-               var query = "?op=rpc&subop=addprofile&title=" + 
-                       param_escape(profile.value);
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                                       editProfiles();
-                               } });
-
-       }
-}
-
-
-function addFeedCat() {
-
-       var cat = $("fadd_cat");
-
-       if (cat.value.length == 0) {
-               alert(__("Can't add category: no name specified."));
-       } else {
-               notify_progress("Adding feed category...");
-
-               var query = "?op=pref-feeds&subop=editCats&action=add&cat=" +
-                       param_escape(cat.value);
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                                       infobox_callback2(transport);
-                               } });
-
-               cat.value = "";
-
-       }
-}
-
 function addUser() {
 
        try {
@@ -1488,9 +1423,95 @@ function inPreferences() {
 }
 
 function editProfiles() {
-       displayDlg('editPrefProfiles', false, function() {
-               init_profile_inline_editor();                   
-                       });
+       try {
+
+               if (dijit.byId("profileEditDlg"))
+                       dijit.byId("profileEditDlg").destroyRecursive();
+
+               var query = "backend.php?op=dlg&id=editPrefProfiles";
+
+               dialog = new dijit.Dialog({
+                       id: "profileEditDlg",
+                       title: __("Settings Profiles"),
+                       style: "width: 600px",
+                       getSelectedProfiles: function() {
+                               return getSelectedTableRowIds("prefFeedProfileList");
+                       },
+                       removeSelected: function() {
+                               var sel_rows = this.getSelectedProfiles();
+                       
+                               if (sel_rows.length > 0) {                      
+                                       var ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed."));
+                       
+                                       if (ok) {
+                                               notify_progress("Removing selected profiles...", true);
+                               
+                                               var query = "?op=rpc&subop=remprofiles&ids="+
+                                                       param_escape(sel_rows.toString());
+                       
+                                               new Ajax.Request("backend.php", {
+                                                       parameters: query,
+                                                       onComplete: function(transport) {
+                                                               notify('');
+                                                               editProfiles();
+                                                       } });
+                       
+                                       }
+                       
+                               } else {        
+                                       alert(__("No profiles are selected."));                 
+                               }
+                       },
+                       activateProfile: function() {
+                               var sel_rows = this.getSelectedProfiles();
+                       
+                               if (sel_rows.length == 1) {
+                       
+                                       var ok = confirm(__("Activate selected profile?"));
+                       
+                                       if (ok) {
+                                               notify_progress("Loading, please wait...");
+                               
+                                               var query = "?op=rpc&subop=setprofile&id="+
+                                                       param_escape(sel_rows.toString());
+                       
+                                               new Ajax.Request("backend.php", {
+                                                       parameters: query,
+                                                       onComplete: function(transport) {
+                                                               window.location.reload();
+                                                       } });
+                                       }
+                       
+                               } else {
+                                       alert(__("Please choose a profile to activate."));
+                               }                       
+                       },                                                                        
+                       addProfile: function() {
+                               if (this.validate()) {
+                                       notify_progress("Creating profile...", true);
+
+                                       var query = "?op=rpc&subop=addprofile&title=" + 
+                                               param_escape(dialog.attr('value').newprofile);
+
+                                       new Ajax.Request("backend.php", {
+                                               parameters: query,
+                                               onComplete: function(transport) {
+                                                       notify('');
+                                                       editProfiles();
+                                               } });
+
+                               }
+                       },
+                       execute: function() {
+                               if (this.validate()) {
+                               }
+                       },
+                       href: query});
+
+               dialog.show();
+       } catch (e) {
+               exception_error("editProfiles", e);
+       }
 }
 
 function activatePrefProfile() {