diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js index d029c3e4..0e0db0c1 100644 --- a/public_html/media/js/core.js +++ b/public_html/media/js/core.js @@ -120,6 +120,54 @@ $(function() }); + //simple action forms + $('form.simple-action').bindOnce('simple-action', 'submit', function(e) + { + e.preventDefault(); + rememberLastSearchQuery(); + + var formDom = $(this); + if (formDom.hasClass('inactive')) + return; + formDom.addClass('inactive'); + formDom.find(':input').attr('readonly', true); + + var url = formDom.attr('action'); + var fd = new FormData(formDom[0]); + + var ajaxData = + { + url: url, + data: fd, + processData: false, + contentType: false, + }; + + postJSON(ajaxData) + .success(function(data) + { + if (data.message) + alert(data.message); + console.log(data); + disableExitConfirmation(); + formDom.find(':input').attr('readonly', false); + formDom.removeClass('inactive'); + if (data.redirectUrl) + window.location.href = data.redirectUrl; + else + window.location.reload(); + }) + .error(function(xhr) + { + alert(xhr.responseJSON + ? xhr.responseJSON.message + : 'Fatal error'); + formDom.find(':input').attr('readonly', false); + formDom.removeClass('inactive'); + }); + }); + + //attach data from submit buttons to forms before .submit() gets called $('.submit').each(function() { diff --git a/public_html/media/js/post-view.js b/public_html/media/js/post-view.js index f8eeaa81..8938a835 100644 --- a/public_html/media/js/post-view.js +++ b/public_html/media/js/post-view.js @@ -106,7 +106,6 @@ $(function() data: fd, processData: false, contentType: false, - type: 'POST', success: function(data) { diff --git a/src/Controllers/AbstractController.php b/src/Controllers/AbstractController.php index 5b60b809..9235ff4d 100644 --- a/src/Controllers/AbstractController.php +++ b/src/Controllers/AbstractController.php @@ -48,7 +48,12 @@ class AbstractController protected function redirect($url) { - if (!$this->isAjax()) + if ($this->isAjax()) + { + Core::getContext()->transport->redirectUrl = $url; + $this->renderAjax(); + } + else \Chibi\Util\Url::forward($url); } diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 00d9b816..6e5750db 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -288,8 +288,7 @@ class PostController extends AbstractController { $context->transport->lastSearchQuery = ''; list ($prevPostId, $nextPostId) = - PostSearchService::getPostIdsAround( - $context->transport->lastSearchQuery, $id); + PostSearchService::getPostIdsAround($context->transport->lastSearchQuery, $id); } //todo: diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 99baa4ce..41b33f6f 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -97,7 +97,10 @@ class TagController extends AbstractController Messenger::fail($e->getMessage()); } - $this->renderViewWithSource('tag-list-wrapper', 'merge'); + if ($this->isAjax()) + $this->renderAjax(); + else + $this->renderViewWithSource('tag-list-wrapper', 'merge'); } public function renameView() @@ -124,7 +127,10 @@ class TagController extends AbstractController Messenger::fail($e->getMessage()); } - $this->renderViewWithSource('tag-list-wrapper', 'rename'); + if ($this->isAjax()) + $this->renderAjax(); + else + $this->renderViewWithSource('tag-list-wrapper', 'rename'); } public function massTagRedirectView() diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 428205d9..767b3ff4 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -57,7 +57,10 @@ class UserController extends AbstractController Messenger::fail($e->getMessage()); } - $this->renderView('user-view'); + if ($this->isAjax()) + $this->renderAjax(); + else + $this->renderView('user-view'); } public function editAction($identifier) @@ -111,7 +114,10 @@ class UserController extends AbstractController Messenger::fail($e->getMessage()); } - $this->renderView('user-view'); + if ($this->isAjax()) + $this->renderAjax(); + else + $this->renderView('user-view'); } public function deleteAction($identifier) @@ -136,7 +142,11 @@ class UserController extends AbstractController { \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); - $this->renderView('user-view'); + + if ($this->isAjax()) + $this->renderAjax(); + else + $this->renderView('user-view'); } } diff --git a/src/Views/tag/tag-mass-tag.phtml b/src/Views/tag/tag-mass-tag.phtml index 4817cfc0..4e1db0c7 100644 --- a/src/Views/tag/tag-mass-tag.phtml +++ b/src/Views/tag/tag-mass-tag.phtml @@ -1,7 +1,10 @@