implement instance adding and deleting
This commit is contained in:
parent
9104a3e65a
commit
323103323b
|
@ -990,6 +990,59 @@
|
|||
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>";
|
||||
|
|
|
@ -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;
|
||||
|
|
61
prefs.js
61
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);
|
||||
|
|
Loading…
Reference in New Issue