Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better feedback when Records can't be saved. #5801

Merged
merged 3 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/resources/translations/en_GB/messages.en_GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ general.phrase.published-on-colon: "Published on:"
general.phrase.read-more: "Read more"
general.phrase.record-related-to-variable: "This record is related to the following %CTNAME%:"
general.phrase.records: "Records"
general.phrase.redirect-detected: "Redirect detected. Check if you are still logged on."
general.phrase.related-content: "Related content"
general.phrase.relationships: "Relationships"
general.phrase.rename-foldername: "Rename %foldername%"
Expand Down
9 changes: 5 additions & 4 deletions app/resources/translations/nl_NL/messages.nl_NL.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# app/resources/translations/nl_NL/messages.nl_NL.yml – generated on 2016-05-09 07:28:29 Europe/Amsterdam

# Warning: Translations are in the process of being moved to a new keyword-based translation
# at the moment. This is an ongoing process. Translations currently in the
# repository are automatically mapped to the new scheme. Be aware that there
# can be a race condition between that process and your PR so that it's
# eventually necessary to remap your translations. If you're planning on
# at the moment. This is an ongoing process. Translations currently in the
# repository are automatically mapped to the new scheme. Be aware that there
# can be a race condition between that process and your PR so that it's
# eventually necessary to remap your translations. If you're planning on
# updating your translations, it's best to ask on IRC to time your contribution
# in order to prevent merge conflicts.

Expand Down Expand Up @@ -388,6 +388,7 @@ general.phrase.published-on-colon: "Gepubliceerd op:"
general.phrase.read-more: "Lees verder"
general.phrase.record-related-to-variable: "Deze record heeft betrekking op de volgende %CTNAME%:"
general.phrase.records: "Records"
general.phrase.redirect-detected: "Redirect gedetecteerd. Controleer of je nog steeds ingelogd bent."
general.phrase.relationships: "Relaties"
general.phrase.rename-foldername: "Hernoem %foldername%"
general.phrase.required-character-count: "Tenminste %NUM% tekens zijn vereist"
Expand Down
30 changes: 24 additions & 6 deletions app/src/js/modules/editcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
window.onbeforeunload = null;

$('p.lastsaved')
.removeClass('alert alert-danger')
.html(savedon)
.find('strong')
.text(moment(data.datechanged).format('MMM D, HH:mm'))
Expand All @@ -298,6 +299,10 @@
'<i class="fa fa-circle status-' + $('#statusselect option:selected').val() + '"></i> ' +
$('#statusselect option:selected').text()
);
// Display the 'save succeeded' icon in the buttons
$('#sidebarsavecontinuebutton i, #savecontinuebutton i')
.removeClass('fa-flag fa-spin fa-spinner fa-exclamation-triangle')
.addClass('fa-check');

// Update anything changed by POST_SAVE handlers
if ($.type(data) === 'object') {
Expand Down Expand Up @@ -344,20 +349,33 @@

watchChanges();
})
.fail(function(){
.fail(function(data){
bolt.events.fire('Bolt.Content.Save.Fail');

$('p.lastsaved').text(msgNotSaved);
var response = $.parseJSON(data.responseText);
var message = '<b>' + msgNotSaved + '</b><br><small>' + response.error.message + '</small>';

$('p.lastsaved')
.html(message)
.addClass('alert alert-danger');

// Display the 'save failed' icon in the buttons
$('#sidebarsavecontinuebutton i, #savecontinuebutton i')
.removeClass('fa-flag fa-spin fa-spinner')
.addClass('fa-exclamation-triangle');
})
.always(function(){
bolt.events.fire('Bolt.Content.Save.Always');

// Re-enable buttons
window.setTimeout(function(){
$('#sidebarsavecontinuebutton, #savecontinuebutton').removeClass('disabled');
$('#sidebarsavecontinuebutton i, #savecontinuebutton i').removeClass('fa-spin fa-spinner');
}, 300);
});
$('#sidebarsavecontinuebutton, #savecontinuebutton').removeClass('disabled').blur();
}, 1000);
window.setTimeout(function(){
$('#sidebarsavecontinuebutton i, #savecontinuebutton i').addClass('fa-flag');
}, 5000);

});
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/view/twig/editcontent/_aside-save.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<ul class="dropdown-menu" role="menu">
<li>
<button type="submit" class="btn btn-link" id="sidebarsavebutton">
<i class="fa fa-flag"></i> {{ __('general.phrase.save-and-return-overview') }}
<i class="fa fa-fw fa-flag"></i> {{ __('general.phrase.save-and-return-overview') }}
</button>
</li>

<li>
<button type="submit" class="btn btn-link" id="sidebarsavenewbutton">
<i class="fa fa-flag"></i> {{ __('general.phrase.save-and-create-new-record') }}
<i class="fa fa-fw fa-flag"></i> {{ __('general.phrase.save-and-create-new-record') }}
</button>
</li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions app/view/twig/editcontent/_buttons.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{# Save Contentype #}
<div class="btn-group">
<button type="button" class="btn btn-primary" id="savecontinuebutton">
<i class="fa fa-flag"></i> {{ __('contenttypes.generic.save', {'%contenttype%': context.contenttype.slug}) }}
<i class="fa fa-fw fa-flag"></i> {{ __('contenttypes.generic.save', {'%contenttype%': context.contenttype.slug}) }}
</button>
{# Dropdown #}
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
Expand All @@ -16,12 +16,12 @@
<ul class="dropdown-menu" role="menu">
<li>
<button type="submit" class="btn btn-link" id="savebutton">
<i class="fa fa-flag"></i> {{ __('general.phrase.save-and-return-overview') }}
<i class="fa fa-fw fa-flag"></i> {{ __('general.phrase.save-and-return-overview') }}
</button>
</li>
<li>
<button type="submit" class="btn btn-link" id="savenewbutton">
<i class="fa fa-flag"></i> {{ __('general.phrase.save-and-create-new-record') }}
<i class="fa fa-fw fa-flag"></i> {{ __('general.phrase.save-and-create-new-record') }}
</button>
</li>
</ul>
Expand Down
10 changes: 9 additions & 1 deletion src/Controller/Backend/BackendBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Bolt\Version;
use Silex\Application;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -48,7 +49,7 @@ protected function render($template, array $variables = [], array $globals = [])
* @param Application $app The application/container
* @param string $roleRoute An overriding value for the route name in permission checks
*
* @return null|\Symfony\Component\HttpFoundation\RedirectResponse
* @return null|\Symfony\Component\HttpFoundation\RedirectResponse|Symfony\Component\HttpFoundation\JsonResponse
*/
public function before(Request $request, Application $app, $roleRoute = null)
{
Expand Down Expand Up @@ -116,6 +117,13 @@ public function before(Request $request, Application $app, $roleRoute = null)
// Most of the 'check if user is allowed' happens here: match the current route to the 'allowed' settings.
$authCookie = $request->cookies->get($this->app['token.authentication.name']);
if ($authCookie === null || !$this->accessControl()->isValidSession($authCookie)) {
// Don't redirect on ajaxy requests (eg. when Saving a record), but send an error
// message with a `500` status code instead.
if ($request->isXmlHttpRequest()) {
$response = ['error' => ['message' => Trans::__('general.phrase.redirect-detected')] ];
return new JsonResponse($response, 500);
}

$app['logger.flash']->info(Trans::__('general.phrase.please-logon'));

return $this->redirectToRoute('login');
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Backend/Records.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function edit(Request $request, $contenttypeslug, $id)
// Set the editreferrer in twig if it was not set yet.
$this->setEditReferrer($request);

// Get the Contenttype obejct
// Get the Contenttype object
$contenttype = $this->getContentType($contenttypeslug);

// Save the POSTed record
Expand Down