]> git.wh0rd.org - tt-rss.git/commitdiff
implement instance edit & save
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 20 Apr 2011 10:11:15 +0000 (14:11 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 20 Apr 2011 10:11:15 +0000 (14:11 +0400)
modules/backend-rpc.php
modules/pref-instances.php
prefs.js

index 8b4fb04c7fd8673994fbd2ad2cfca73df41fd1ec..2ff9a6312ba0882f0e4937633e0cdb410c44a16a 100644 (file)
                        return;
                }
 
+               if ($subop == "genHash") {
+                       $hash = sha1(uniqid(rand(), true));
+
+                       print json_encode(array("hash" => $hash));
+                       return;
+               }
+
                print json_encode(array("error" => array("code" => 7,
                        "message" => "Unknown method: $subop")));
        }
index 0671944d34889ce3c7f8abb2cc0405ff8819912d..c57b46f35aed058be9b9b81fa1cf4fdc2158f367 100644 (file)
@@ -5,8 +5,70 @@
 
                if ($subop == "edit") {
 
-                       print "TODO: function not implemented.";
+                       $id = db_escape_string($_REQUEST["id"]);
 
+                       $result = db_query($link, "SELECT * FROM ttrss_linked_instances WHERE
+                               id = '$id'");
+
+                       print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"id\" value=\"$id\">";
+                       print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"op\" value=\"pref-instances\">";
+                       print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"subop\" value=\"editSave\">";
+
+                       print "<div class=\"dlgSec\">".__("Instance")."</div>";
+
+                       print "<div class=\"dlgSecCont\">";
+
+                       /* URL */
+
+                       $access_url = htmlspecialchars(db_fetch_result($result, 0, "access_url"));
+
+                       print __("URL:") . " ";
+
+                       print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
+                               placeHolder=\"".__("Instance URL")."\"
+                               regExp='^(http|https)://.*'
+                               style=\"font-size : 16px; width: 20em\" name=\"access_url\"
+                               value=\"$access_url\">";
+
+                       print "<hr/>";
+
+                       $access_key = htmlspecialchars(db_fetch_result($result, 0, "access_key"));
+
+                       /* Access key */
+
+                       print __("Access key:") . " ";
+
+                       print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
+                               placeHolder=\"".__("Access key")."\"
+                               style=\"width: 20em\" name=\"access_key\" id=\"instance_edit_key\"
+                               value=\"$access_key\">";
+
+                       print "</div>";
+
+                       print "<div class=\"dlgButtons\">
+                               <div style='float : left'>
+                                       <button dojoType=\"dijit.form.Button\"
+                                               onclick=\"return dijit.byId('instanceEditDlg').regenKey()\">".
+                                               __('Generate new key')."</button>
+                               </div>
+                               <button dojoType=\"dijit.form.Button\"
+                                       onclick=\"return dijit.byId('instanceEditDlg').execute()\">".
+                                       __('Save')."</button>
+                               <button dojoType=\"dijit.form.Button\"
+                                       onclick=\"return dijit.byId('instanceEditDlg').hide()\"\">".
+                                       __('Cancel')."</button></div>";
+
+                       return;
+               }
+
+               if ($subop == "editSave") {
+                       $id = db_escape_string($_REQUEST["id"]);
+                       $access_url = db_escape_string($_REQUEST["access_url"]);
+                       $access_key = db_escape_string($_REQUEST["access_key"]);
+
+                       db_query($link, "UPDATE ttrss_linked_instances SET
+                               access_key = '$access_key', access_url = '$access_url'
+                               WHERE id = '$id'");
 
                        return;
                }
index c13f0e0d41339a9c4350ef83efe10200ca5d05d2..5c7131d2f41b8a518264b52a1c7e18c04b06fffe 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -1810,6 +1810,30 @@ function editInstance(id, event) {
                        id: "instanceEditDlg",
                        title: __("Edit Instance"),
                        style: "width: 600px",
+                       regenKey: function() {
+                               new Ajax.Request("backend.php", {
+                                       parameters: "?op=rpc&subop=genHash",
+                                       onComplete: function(transport) {
+                                               var reply = JSON.parse(transport.responseText);
+                                               if (reply)
+                                                       dijit.byId('instance_edit_key').attr('value', reply.hash);
+
+                                       } });
+                       },
+                       execute: function() {
+                               if (this.validate()) {
+//                                     console.warn(dojo.objectToQuery(this.attr('value')));
+
+                                       notify_progress('Saving data...', true);
+                                       new Ajax.Request("backend.php", {
+                                               parameters: dojo.objectToQuery(this.attr('value')),
+                                               onComplete: function(transport) {
+                                                       dialog.hide();
+                                                       notify('');
+                                                       updateInstanceList();
+                                       } });
+                               }
+                       },
                        href: query,
                });