Skip to content

Commit

Permalink
Merge pull request #1414 from bolt/feature/adding-spinners-on-certain…
Browse files Browse the repository at this point in the history
…-buttons

Adding spinners and disabling buttons to indicate the user might have to wait a few seconds
  • Loading branch information
bobdenotter committed May 31, 2020
2 parents 08ce81a + bcd9f17 commit abef7b3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 5 deletions.
6 changes: 6 additions & 0 deletions assets/js/app/editor/Components/File.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
class="btn dropdown-item"
type="button"
:readonly="readonly"
data-patience="virtue"
@click="selectServerFile"
>
<i class="fas fa-fw fa-th"></i>
Expand All @@ -77,6 +78,9 @@
>
<i class="fas fa-fw fa-info-circle"></i>
{{ labels.button_edit_attributes }}
<small class="dim"
><i class="fas fa-external-link-square-alt"></i
></small>
</a>
</div>
</div>
Expand Down Expand Up @@ -223,9 +227,11 @@ export default {
},
});
window.$('.bootbox-input').attr('name', 'bootbox-input');
window.reEnablePatientButtons();
})
.catch(err => {
console.warn(err);
window.reEnablePatientButtons();
});
},
onDragEnter(e) {
Expand Down
6 changes: 6 additions & 0 deletions assets/js/app/editor/Components/Image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
class="btn dropdown-item"
type="button"
:disabled="readonly"
data-patience="virtue"
@click="selectServerFile"
>
<i class="fas fa-fw fa-th"></i>
Expand All @@ -76,6 +77,9 @@
>
<i class="fas fa-fw fa-info-circle"></i>
{{ labels.button_edit_attributes }}
<small class="dim"
><i class="fas fa-external-link-square-alt"></i
></small>
</a>
</div>
</div>
Expand Down Expand Up @@ -263,9 +267,11 @@ export default {
},
});
window.$('.bootbox-input').attr('name', 'bootbox-input');
window.reEnablePatientButtons();
})
.catch(err => {
console.warn(err);
window.reEnablePatientButtons();
});
},
onDragEnter(e) {
Expand Down
1 change: 1 addition & 0 deletions assets/js/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import './listing';
import './editor';
import './login';
import './confirmation.js';
import './patience-is-a-virtue.js';
import './common.js';
1 change: 1 addition & 0 deletions assets/js/app/listing/Components/Table/Row/_Actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<a
class="btn btn-secondary btn-block btn-sm text-nowrap"
:href="record.extras.editLink"
data-patience="virtue"
>
<i class="far fa-edit mr-1"></i> {{ labels.button_edit }}
</a>
Expand Down
27 changes: 27 additions & 0 deletions assets/js/app/patience-is-a-virtue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import $ from 'jquery';

$('*[data-patience]').on('click', function() {
const thisElement = $(this);
const thisIcon = thisElement.find('i');

// Bootstrap padding / margin like `mx-2` or `pt-3`
const addedPadding = thisIcon.attr('class').match(/[mp][tblrxy]-[0-5]/i);
const newClass =
'fas fa-w fa-cog fa-spin ' + (addedPadding ? addedPadding : '');

$(this).attr('data-original-class', thisIcon.attr('class'));
thisIcon.attr('class', newClass);

window.setTimeout(function() {
thisElement.attr('disabled', true);
}, 50);
});

window.reEnablePatientButtons = function() {
$('*[data-patience]').each(function() {
const thisIcon = $(this).find('i');

$(this).attr('disabled', false);
thisIcon.attr('class', $(this).attr('data-original-class'));
});
};
6 changes: 3 additions & 3 deletions assets/js/app/sidebar/Components/Menu/_SubMenu.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<ul class="link--menu">
<li v-if="item.link_new !== null" class="link--actions">
<a :href="item.link_new">
<a :href="item.link_new" data-patience="virtue">
<i class="fas fa-fw fa-magic mr-2"></i
><span>New {{ item.singular_name }}</span>
</a>
<a :href="item.link_listing">
<a :href="item.link_listing" data-patience="virtue">
<i class="fas fa-fw" :class="item.icon"></i>
<span>View {{ item.name }}</span>
</a>
Expand All @@ -17,7 +17,7 @@
:key="index"
>
<!-- eslint-enable -->
<a :href="subitem.editLink">
<a :href="subitem.editLink" data-patience="virtue">
<i class="fas fa-fw mr-2" :class="subitem.icon"></i>
<!-- eslint-disable-next-line vue/no-v-html -->
<span v-if="subitem.name" v-html="subitem.name"></span>
Expand Down
2 changes: 1 addition & 1 deletion templates/content/_buttons.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="record-actions">

{{ macro.button('action.save', 'fa-save', 'success', {'type': 'submit', 'form': 'editcontent'}) }}
{{ macro.button('action.save', 'fa-save', 'success', {'type': 'submit', 'form': 'editcontent', 'data-patience': 'virtue'}) }}

{% if record.id %}
<div class="btn-group">
Expand Down
2 changes: 1 addition & 1 deletion templates/content/listing.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</div>
<div class="card-body">
<p>
<a class="btn btn-primary" href="{{ path('bolt_content_new', { contentType: contentType.slug }) }}">
<a class="btn btn-primary" href="{{ path('bolt_content_new', { contentType: contentType.slug }) }}" data-patience="virtue">
{{ macro.icon('magic') }} {{ __('action.create_new') }} {{ contentType.singular_name }}
</a>
</p>
Expand Down

0 comments on commit abef7b3

Please sign in to comment.