diff --git a/src/packages/com_mokowaas/admin/src/Controller/DisplayController.php b/src/packages/com_mokowaas/admin/src/Controller/DisplayController.php index dd77f61f..6664b77a 100644 --- a/src/packages/com_mokowaas/admin/src/Controller/DisplayController.php +++ b/src/packages/com_mokowaas/admin/src/Controller/DisplayController.php @@ -580,12 +580,40 @@ class DisplayController extends BaseController return; } - $input = Factory::getApplication()->getInput(); - $model = new \Moko\Component\MokoWaaS\Administrator\Model\PrivacyModel(); + $input = Factory::getApplication()->getInput(); + $model = new \Moko\Component\MokoWaaS\Administrator\Model\PrivacyModel(); + $action = $input->getString('action', 'deny'); + + if ($action === 'create') + { + $result = $model->createRequest( + $input->getInt('user_id', 0), + $input->getString('type', 'export') + ); + $this->jsonResponse($result); + return; + } + + if ($action === 'approve' && !$input->getInt('request_id', 0) && $input->getInt('user_id', 0)) + { + // Auto-process: create then immediately approve + $result = $model->createRequest( + $input->getInt('user_id', 0), + $input->getString('type', 'export') + ); + + if ($result['success'] && !empty($result['id'])) + { + $result = $model->processRequest((int) $result['id'], 'approve'); + } + + $this->jsonResponse($result); + return; + } $this->jsonResponse($model->processRequest( $input->getInt('request_id', 0), - $input->getString('action', 'deny') + $action )); } diff --git a/src/packages/com_mokowaas/admin/tmpl/privacy/default.php b/src/packages/com_mokowaas/admin/tmpl/privacy/default.php index 0b6f6f72..9fd993e6 100644 --- a/src/packages/com_mokowaas/admin/tmpl/privacy/default.php +++ b/src/packages/com_mokowaas/admin/tmpl/privacy/default.php @@ -53,6 +53,63 @@ $typeBadge = [ + +
+
+ Create Data Request + +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
@@ -158,6 +215,32 @@ document.addEventListener('DOMContentLoaded', function() { }); }); + // Create new request + var form = document.getElementById('formNewRequest'); + if (form) { + form.addEventListener('submit', function(e) { + e.preventDefault(); + var btn = document.getElementById('btnCreateRequest'); + var userId = document.getElementById('req_user_id').value; + var type = document.getElementById('req_type').value; + var auto = document.getElementById('req_auto').value; + if (!userId) { Joomla.renderMessages({warning:['Please select a user.']}); return; } + btn.disabled = true; + var fd = new FormData(); + fd.append('user_id', userId); + fd.append('type', type); + fd.append('action', auto === '1' ? 'approve' : 'create'); + fd.append(btn.dataset.token, '1'); + fetch(btn.dataset.url, {method:'POST', body:fd, headers:{'X-Requested-With':'XMLHttpRequest'}}) + .then(function(r){return r.json()}) + .then(function(d){ + if (d.success) { Joomla.renderMessages({message:[d.message || 'Request created.']}); location.reload(); } + else { Joomla.renderMessages({error:[d.message || 'Failed.']}); btn.disabled = false; } + }) + .catch(function(){ btn.disabled = false; }); + }); + } + // Export download document.querySelectorAll('.btn-export-download').forEach(function(btn) { btn.addEventListener('click', function() {