list dns entries after add/delete action handling so the table of entries always shows the current state withouth reloading the page; fixes #887

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann 2020-10-12 09:50:48 +02:00
parent a5dc7b93a2
commit 0dfb4bdcdb
No known key found for this signature in database
GPG Key ID: 55284EC83A4823B8

View File

@ -19,7 +19,6 @@ if (! defined('AREA')) {
*
*/
use Froxlor\Database\Database;
use Froxlor\Api\Commands\DomainZones as DomainZones;
// This file is being included in admin_domains and customer_domains
@ -36,18 +35,6 @@ $ttl = isset($_POST['record']['ttl']) ? (int) $_POST['record']['ttl'] : 18000;
// get domain-name
$domain = \Froxlor\Dns\Dns::getAllowedDomainEntry($domain_id, AREA, $userinfo);
// select all entries
try {
// get list
$json_result = DomainZones::getLocal($userinfo, [
'id' => $domain_id
])->listing();
} catch (Exception $e) {
\Froxlor\UI\Response::dynamic_error($e->getMessage());
}
$result = json_decode($json_result, true)['data'];
$dom_entries = $result['list'];
$errors = "";
$success_message = "";
@ -63,8 +50,9 @@ if ($action == 'add_record' && ! empty($_POST)) {
'ttl' => $ttl
))->add();
$success_message = $lng['success']['dns_record_added'];
$record = $prio = $content = "";
} catch (Exception $e) {
\Froxlor\UI\Response::dynamic_error($e->getMessage());
$errors = str_replace("\n", "<br>", $e->getMessage());
}
} elseif ($action == 'delete') {
// remove entry
@ -75,26 +63,26 @@ if ($action == 'add_record' && ! empty($_POST)) {
'entry_id' => $entry_id,
'id' => $domain_id
))->delete();
// success message (inline)
$success_message = $lng['success']['dns_record_deleted'];
} catch (Exception $e) {
$errors = str_replace("\n", "<br>", $e->getMessage());
}
if (empty($errors)) {
// remove deleted entry from internal data array (no reread of DB necessary)
$_t = $dom_entries;
foreach ($_t as $idx => $entry) {
if ($entry['id'] == $entry_id) {
unset($dom_entries[$idx]);
break;
}
}
unset($_t);
// success message (inline)
$success_message = $lng['success']['dns_record_deleted'];
}
}
}
// select all entries
try {
// get list
$json_result = DomainZones::getLocal($userinfo, [
'id' => $domain_id
])->listing();
} catch (Exception $e) {
\Froxlor\UI\Response::dynamic_error($e->getMessage());
}
$result = json_decode($json_result, true)['data'];
$dom_entries = $result['list'];
// show editor
$record_list = "";
$existing_entries = "";