Skip to content

Commit

Permalink
Unlock object on dialog close (cancel)
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Nov 23, 2023
1 parent 7c413ae commit 6f0b364
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/midcom/config/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ resolve_permalink:
path: /midcom-permalink-{guid}
defaults: { _controller: 'midcom_core_urlmethods::process_permalink' }

unlock:
path: /midcom-unlock-{guid}
defaults: { _controller: 'midcom_core_urlmethods::process_unlock' }

cache:
path: /midcom-cache-invalidate
defaults: { _controller: 'midcom_core_urlmethods::invalidate_cache' }
Expand Down
9 changes: 9 additions & 0 deletions lib/midcom/core/urlmethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;

/**
* MidCOM URL methods.
Expand Down Expand Up @@ -121,6 +122,14 @@ public function process_login(Request $request, string $url) : Response
return new midcom_response_login;
}

public function process_unlock(string $guid) : Response
{
$object = midcom::get()->dbfactory->get_object_by_guid($guid);
return new JsonResponse([
'success' => $object->unlock()
]);
}

private function redirect(Request $request, string $redirect_to) : Response
{
if (!empty($request->server->get('QUERY_STRING'))) {
Expand Down
5 changes: 5 additions & 0 deletions src/midcom/workflow/datamanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use midcom\datamanager\controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use midcom\datamanager\storage\container\dbacontainer;

/**
* @package midcom.workflow
Expand Down Expand Up @@ -80,6 +81,10 @@ public function run(Request $request) : Response
midcom::get()->style->show($style);
};
} else {
$storage = $this->controller->get_datamanager()->get_storage();
if ($storage instanceof dbacontainer) {
midcom::get()->head->add_jscript('var DM_OBJECT_GUID = "' . $storage->get_value()->guid . '";');
}
$callback = [$this->controller, 'display_form'];
}
$context->set_key(MIDCOM_CONTEXT_SHOWCALLBACK, $callback);
Expand Down
13 changes: 13 additions & 0 deletions static/midcom.workflow/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ function attach_to_parent_dialog(dialog) {

window.addEventListener('DOMContentLoaded', function() {
if (dialog) {

if (window.hasOwnProperty('DM_OBJECT_GUID') && DM_OBJECT_GUID) {
let unlocker = function() {
window.parent.$.get(MIDCOM_PAGE_PREFIX + 'midcom-unlock-' + DM_OBJECT_GUID);
dialog.off('dialogclose', unlocker);
};
window.addEventListener("unload", function () {
dialog.off('dialogclose', unlocker);
});
dialog.on('dialogclose', unlocker);
}


dialog.find(' > .spinner').hide();
if (window.hasOwnProperty('$')) {
$('body').on('submit', '.midcom-dialog-delete-form', function(e) {
Expand Down

0 comments on commit 6f0b364

Please sign in to comment.