]> git.wh0rd.org - tt-rss.git/commitdiff
implement instance adding and deleting
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 20 Apr 2011 10:25:02 +0000 (14:25 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 20 Apr 2011 10:25:02 +0000 (14:25 +0400)
modules/popup-dialog.php
modules/pref-instances.php
prefs.js

index 2eb63af9dd166d613634094681704a50234ab06c..906e89f4f0b52d2aee21a2fe2d069a5f36673b60 100644 (file)
                                type=\"submit\">".
                                __('Close this window')."</button>";
                        print "</div>";
+               }
+
+               if ($id == "addInstance") {
+
+                       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=\"add\">";
+
+                       print "<div class=\"dlgSec\">".__("Instance")."</div>";
+
+                       print "<div class=\"dlgSecCont\">";
+
+                       /* 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\">";
+
+                       print "<hr/>";
+
+                       $access_key = sha1(uniqid(rand(), true));
+
+                       /* Access key */
+
+                       print __("Access key:") . " ";
+
+                       print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
+                               placeHolder=\"".__("Access key")."\"
+                               style=\"width: 20em\" name=\"access_key\" id=\"instance_add_key\"
+                               value=\"$access_key\">";
+
+                       print "</div>";
+
+                       print "<div class=\"dlgButtons\">
+                               <div style='float : left'>
+                                       <button dojoType=\"dijit.form.Button\"
+                                               onclick=\"return dijit.byId('instanceAddDlg').regenKey()\">".
+                                               __('Generate new key')."</button>
+                               </div>
+                               <button dojoType=\"dijit.form.Button\"
+                                       onclick=\"return dijit.byId('instanceAddDlg').execute()\">".
+                                       __('Create link')."</button>
+                               <button dojoType=\"dijit.form.Button\"
+                                       onclick=\"return dijit.byId('instanceAddDlg').hide()\"\">".
+                                       __('Cancel')."</button></div>";
+
+                       return;
+
+
+
+
                }
 
                print "</dlg>";
index c57b46f35aed058be9b9b81fa1cf4fdc2158f367..ab3d78c44bb22e23653cf0e4c4213ebbf70d7f29 100644 (file)
@@ -3,6 +3,37 @@
 
                $subop = $_REQUEST['subop'];
 
+               if ($subop == "remove") {
+                       $ids = db_escape_string($_REQUEST['ids']);
+
+                       db_query($link, "DELETE FROM ttrss_linked_instances WHERE
+                               id IN ($ids)");
+
+                       return;
+               }
+
+               if ($subop == "add") {
+                       $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, "BEGIN");
+
+                       $result = db_query($link, "SELECT id FROM ttrss_linked_instances
+                               WHERE access_url = '$access_url'");
+
+                       if (db_num_rows($result) == 0) {
+                               db_query($link, "INSERT INTO ttrss_linked_instances
+                                       (access_url, access_key, last_connected) VALUES
+                                       ('$access_url', '$access_key', '1970-01-01')");
+
+                       }
+
+                       db_query($link, "COMMIT");
+
+                       return;
+               }
+
                if ($subop == "edit") {
 
                        $id = db_escape_string($_REQUEST["id"]);
@@ -67,7 +98,8 @@
                        $access_key = db_escape_string($_REQUEST["access_key"]);
 
                        db_query($link, "UPDATE ttrss_linked_instances SET
-                               access_key = '$access_key', access_url = '$access_url'
+                               access_key = '$access_key', access_url = '$access_url',
+                               last_connected = '1970-01-01'
                                WHERE id = '$id'");
 
                        return;
index 5c7131d2f41b8a518264b52a1c7e18c04b06fffe..1cf2943293cd055ff538f05be2ce14adb6dd7215 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -1785,8 +1785,43 @@ function getSelectedInstances() {
 
 function addInstance() {
        try {
-               alert("TODO: function not implemented.");
+               var query = "backend.php?op=dlg&id=addInstance";
 
+               if (dijit.byId("instanceAddDlg"))
+                       dijit.byId("instanceAddDlg").destroyRecursive();
+
+               dialog = new dijit.Dialog({
+                       id: "instanceAddDlg",
+                       title: __("Link 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_add_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,
+               });
+
+               dialog.show();
 
        } catch (e) {
                exception_error("addInstance", e);
@@ -1853,7 +1888,29 @@ function editInstance(id, event) {
 
 function removeSelectedInstances() {
        try {
-               alert("TODO: function not implemented.");
+               var sel_rows = getSelectedInstances();
+
+               if (sel_rows.length > 0) {
+
+                       var ok = confirm(__("Remove selected instances?"));
+
+                       if (ok) {
+                               notify_progress("Removing selected instances...");
+
+                               var query = "?op=pref-instances&subop=remove&ids="+
+                                       param_escape(sel_rows.toString());
+
+                               new Ajax.Request("backend.php", {
+                                       parameters: query,
+                                       onComplete: function(transport) {
+                                               notify('');
+                                               updateInstanceList();
+                                       } });
+                       }
+
+               } else {
+                       alert(__("No instances are selected."));
+               }
 
        } catch (e) {
                exception_error("removeInstance", e);