Skip to content

Commit

Permalink
Merge pull request #11895 from craftcms/feature/disable-preview-butto…
Browse files Browse the repository at this point in the history
…n-during-save

Feature/disable preview button during save
  • Loading branch information
brandonkelly authored Sep 13, 2022
2 parents 4bd7eed + a94d851 commit be7f814
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
- Element index footers now stick to the bottom of the window, and element action triggers are now inserted into the footer rather than replacing the contents of the page’s toolbar. ([#11844](https://github.com/craftcms/cms/pull/11844))
- Notifications are now shown after executing folder actions on the Assets index page. ([#11906/](https://github.com/craftcms/cms/pull/11906))
- Date range condition rules now support “Today”, “This week”, “This month”, “This year”, “Past 7 days”, “Past 30 days”, “Past 30 days”, “Past year”, “Before…”, and “After…” relative range types, in addition to specifyng a custom date range. ([#11888](https://github.com/craftcms/cms/pull/11888))
- If Live Preview is triggered while a draft is saving, it will now wait until the save completes before opening. ([#11858](https://github.com/craftcms/cms/issues/11858), [#11895](https://github.com/craftcms/cms/pull/11895))
- It’s now possible to restore assets that were deleted programmatically with `craft\elements\Asset::$keepFile` set to `true`. ([#11761](https://github.com/craftcms/cms/issues/11761))
- Control panel-defined image transforms can now have custom quality values. ([#9622](https://github.com/craftcms/cms/discussions/9622))
- Name parsing now checks for common German salutations, suffixes, and last name prefixes.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `resave/*` commands now have a `--touch` option. When passed, elements’ `dateUpdated` timestamps will be updated as they’re resaved. ([#11849](https://github.com/craftcms/cms/discussions/11849))
- Underscores within query param values that begin/end with `*` are now escaped, so they aren’t treated as wildcard characters by the `like` condition. ([#11898](https://github.com/craftcms/cms/issues/11898))
- `craft\services\Elements::resaveElements()` now has a `$touch` argument.
- Disable the preview button while drafts are saving ([#11858](https://github.com/craftcms/cms/issues/11858))

### Fixed
- Fixed an error that could occur when upgrading to Craft 4, if any Matrix blocks contained null `sortOrder` values. ([#11843](https://github.com/craftcms/cms/issues/11843))
Expand Down
8 changes: 6 additions & 2 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,16 @@ private function _additionalButtons(
'class' => ['preview-btn-container', 'btngroup'],
]) .
($enablePreview
? Html::button(Craft::t('app', 'Preview'), [
? Html::beginTag('button', [
'type' => 'button',
'class' => ['preview-btn', 'btn'],
'aria' => [
'label' => Craft::t('app', 'Preview'),
],
])
]) .
Html::tag('span', Craft::t('app', 'Preview'), ['class' => 'label']) .
Html::tag('span', options: ['class' => ['spinner', 'spinner-absolute']]) .
Html::endTag('button')
: '') .
Html::endTag('div');
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/src/css/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ ul.icons {
}
}

&:not(.disabled):not(.loading):not(.dashed) {
&:not(.disabled):not(.loading):not(.dashed):not([aria-disabled]) {
&:focus,
&.focus,
&:hover {
Expand Down
32 changes: 22 additions & 10 deletions src/web/assets/cp/src/js/ElementEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,17 +996,29 @@ Craft.ElementEditor = Garnish.Base.extend(
},

openPreview: function () {
return new Promise((resolve, reject) => {
this.openingPreview = true;
this.ensureIsDraftOrRevision(true)
.then(() => {
this.scrollY = window.scrollY;
this.getPreview().open();
this.openingPreview = false;
resolve();
if (Garnish.hasAttr(this.$previewBtn, 'aria-disabled')) {
return;
}

this.$previewBtn.attr('aria-disabled', true);
this.$previewBtn.addClass('loading');

this.queue.push(
() =>
new Promise((resolve, reject) => {
this.openingPreview = true;
this.ensureIsDraftOrRevision(true)
.then(() => {
this.scrollY = window.scrollY;
this.$previewBtn.removeAttr('aria-disabled');
this.$previewBtn.removeClass('loading');
this.getPreview().open();
this.openingPreview = false;
resolve();
})
.catch(reject);
})
.catch(reject);
});
);
},

ensureIsDraftOrRevision: function (onlyIfChanged) {
Expand Down

0 comments on commit be7f814

Please sign in to comment.