Added AJAX wrappers to a few forms
This commit is contained in:
parent
bba35875a3
commit
e3617434e6
12 changed files with 94 additions and 17 deletions
|
@ -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
|
//attach data from submit buttons to forms before .submit() gets called
|
||||||
$('.submit').each(function()
|
$('.submit').each(function()
|
||||||
{
|
{
|
||||||
|
|
|
@ -106,7 +106,6 @@ $(function()
|
||||||
data: fd,
|
data: fd,
|
||||||
processData: false,
|
processData: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
type: 'POST',
|
|
||||||
|
|
||||||
success: function(data)
|
success: function(data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,12 @@ class AbstractController
|
||||||
|
|
||||||
protected function redirect($url)
|
protected function redirect($url)
|
||||||
{
|
{
|
||||||
if (!$this->isAjax())
|
if ($this->isAjax())
|
||||||
|
{
|
||||||
|
Core::getContext()->transport->redirectUrl = $url;
|
||||||
|
$this->renderAjax();
|
||||||
|
}
|
||||||
|
else
|
||||||
\Chibi\Util\Url::forward($url);
|
\Chibi\Util\Url::forward($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -288,8 +288,7 @@ class PostController extends AbstractController
|
||||||
{
|
{
|
||||||
$context->transport->lastSearchQuery = '';
|
$context->transport->lastSearchQuery = '';
|
||||||
list ($prevPostId, $nextPostId) =
|
list ($prevPostId, $nextPostId) =
|
||||||
PostSearchService::getPostIdsAround(
|
PostSearchService::getPostIdsAround($context->transport->lastSearchQuery, $id);
|
||||||
$context->transport->lastSearchQuery, $id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo:
|
//todo:
|
||||||
|
|
|
@ -97,6 +97,9 @@ class TagController extends AbstractController
|
||||||
Messenger::fail($e->getMessage());
|
Messenger::fail($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->isAjax())
|
||||||
|
$this->renderAjax();
|
||||||
|
else
|
||||||
$this->renderViewWithSource('tag-list-wrapper', 'merge');
|
$this->renderViewWithSource('tag-list-wrapper', 'merge');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +127,9 @@ class TagController extends AbstractController
|
||||||
Messenger::fail($e->getMessage());
|
Messenger::fail($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->isAjax())
|
||||||
|
$this->renderAjax();
|
||||||
|
else
|
||||||
$this->renderViewWithSource('tag-list-wrapper', 'rename');
|
$this->renderViewWithSource('tag-list-wrapper', 'rename');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,9 @@ class UserController extends AbstractController
|
||||||
Messenger::fail($e->getMessage());
|
Messenger::fail($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->isAjax())
|
||||||
|
$this->renderAjax();
|
||||||
|
else
|
||||||
$this->renderView('user-view');
|
$this->renderView('user-view');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +114,9 @@ class UserController extends AbstractController
|
||||||
Messenger::fail($e->getMessage());
|
Messenger::fail($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->isAjax())
|
||||||
|
$this->renderAjax();
|
||||||
|
else
|
||||||
$this->renderView('user-view');
|
$this->renderView('user-view');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +142,10 @@ class UserController extends AbstractController
|
||||||
{
|
{
|
||||||
\Chibi\Util\Headers::setCode(400);
|
\Chibi\Util\Headers::setCode(400);
|
||||||
Messenger::fail($e->getMessage());
|
Messenger::fail($e->getMessage());
|
||||||
|
|
||||||
|
if ($this->isAjax())
|
||||||
|
$this->renderAjax();
|
||||||
|
else
|
||||||
$this->renderView('user-view');
|
$this->renderView('user-view');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<div class="form-wrapper">
|
<div class="form-wrapper">
|
||||||
<form method="post" action="<?= \Chibi\Router::linkTo(
|
<form method="post"
|
||||||
|
class="simple-action"
|
||||||
|
action="<?= \Chibi\Router::linkTo(
|
||||||
['PostController', 'listRedirectAction'],
|
['PostController', 'listRedirectAction'],
|
||||||
['source' => 'mass-tag']) ?>">
|
['source' => 'mass-tag']) ?>">
|
||||||
|
|
||||||
<h1>mass tag</h1>
|
<h1>mass tag</h1>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<div class="form-wrapper">
|
<div class="form-wrapper">
|
||||||
<form method="post" action="<?= \Chibi\Router::linkTo(['TagController', 'mergeAction']) ?>">
|
<form method="post"
|
||||||
|
class="simple-action"
|
||||||
|
action="<?= \Chibi\Router::linkTo(['TagController', 'mergeAction']) ?>">
|
||||||
|
|
||||||
<h1>merge tags</h1>
|
<h1>merge tags</h1>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
@ -12,6 +15,7 @@
|
||||||
$context = new StdClass;
|
$context = new StdClass;
|
||||||
$context->name = 'target-tag';
|
$context->name = 'target-tag';
|
||||||
$context->label = 'Target tag';
|
$context->label = 'Target tag';
|
||||||
|
$context->inputClass = 'autocomplete';
|
||||||
$this->renderExternal('input-text', $context);
|
$this->renderExternal('input-text', $context);
|
||||||
|
|
||||||
$this->renderExternal('message');
|
$this->renderExternal('message');
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<div class="form-wrapper">
|
<div class="form-wrapper">
|
||||||
<form method="post" action="<?= \Chibi\Router::linkTo(['TagController', 'renameAction']) ?>">
|
<form method="post"
|
||||||
|
class="simple-action"
|
||||||
|
action="<?= \Chibi\Router::linkTo(['TagController', 'renameAction']) ?>">
|
||||||
|
|
||||||
<h1>rename tags</h1>
|
<h1>rename tags</h1>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
['UserController', 'deleteAction'],
|
['UserController', 'deleteAction'],
|
||||||
['identifier' => $this->context->transport->user->getName()]) ?>"
|
['identifier' => $this->context->transport->user->getName()]) ?>"
|
||||||
method="post"
|
method="post"
|
||||||
class="delete confirmable"
|
class="user-delete simple-action confirmable"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
data-confirm-text="Are you sure you want to delete your account?">
|
data-confirm-text="Are you sure you want to delete your account?">
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ $this->assets->addScript('user-edit.js');
|
||||||
['identifier' => $this->context->transport->user->getName()]) ?>"
|
['identifier' => $this->context->transport->user->getName()]) ?>"
|
||||||
enctype="multipart/form-data"
|
enctype="multipart/form-data"
|
||||||
method="post"
|
method="post"
|
||||||
class="edit"
|
class="edit-user simple-action"
|
||||||
autocomplete="off">
|
autocomplete="off">
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
|
@ -7,7 +7,7 @@ $settings = $this->context->transport->user->getSettings();
|
||||||
['UserController', 'settingsAction'],
|
['UserController', 'settingsAction'],
|
||||||
['identifier' => $this->context->transport->user->getName()]) ?>"
|
['identifier' => $this->context->transport->user->getName()]) ?>"
|
||||||
method="post"
|
method="post"
|
||||||
class="settings">
|
class="user-settings simple-action">
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$safety = array_filter(
|
$safety = array_filter(
|
||||||
|
|
Loading…
Reference in a new issue