diff options
author | Andrew Dolgov <[email protected]> | 2011-04-20 14:25:02 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2011-04-20 14:25:02 +0400 |
commit | 323103323b5ca370bd64e96b77b49f0b48bc05ed (patch) | |
tree | ee2aa64bf9ed0c295238179dbebdbb0f11f0ebbc | |
parent | 9104a3e65afdb884dd2a6289ac62161d8176c555 (diff) |
implement instance adding and deleting
-rw-r--r-- | modules/popup-dialog.php | 53 | ||||
-rw-r--r-- | modules/pref-instances.php | 34 | ||||
-rw-r--r-- | prefs.js | 61 |
3 files changed, 145 insertions, 3 deletions
diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php index 2eb63af9d..906e89f4f 100644 --- a/modules/popup-dialog.php +++ b/modules/popup-dialog.php @@ -992,6 +992,59 @@ 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>"; } ?> diff --git a/modules/pref-instances.php b/modules/pref-instances.php index c57b46f35..ab3d78c44 100644 --- a/modules/pref-instances.php +++ b/modules/pref-instances.php @@ -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; @@ -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); |