Skip to content

Commit

Permalink
reorganise js a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Mar 14, 2024
1 parent e82fbb3 commit aa7f70a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
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.

90 changes: 46 additions & 44 deletions src/web/assets/cp/src/js/EntryMover.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,58 +78,60 @@ Craft.EntryMover = Garnish.Base.extend({
this.getCompatibleSections();
},

async getCompatibleSections() {
const listHtml = await this.loadSections();
this.$sectionsList.html(listHtml);
this.addListener(
this.$sectionsList.find('.entry-mover-modal--item'),
'activate',
(ev) => {
let $button = $(ev.target);
// reset all the links
this.$sectionsList
.find('a')
.removeClass('sel')
.attr('aria-pressed', 'false');
// mark as selected
$button.addClass('sel').attr('aria-pressed', 'true');
// enable submit btn
if (this.$selectBtn.hasClass('disabled')) {
this.$selectBtn
.removeClass('disabled')
.attr('aria-disabled', 'false');
}
}
);
},

async loadSections() {
getCompatibleSections() {
if (this.cancelToken) {
this.cancelToken.cancel();
}

this.$sectionsListContainer.addClass('loading');
this.cancelToken = axios.CancelToken.source();

try {
const response = await Craft.sendActionRequest(
'POST',
'entries/move-to-section-modal-data',
{
data: {
entryIds: this.entryIds,
siteId: this.elementIndex.siteId,
currentSectionUid: this.currentSectionUid,
},
cancelToken: this.cancelToken.token,
Craft.sendActionRequest('POST', 'entries/move-to-section-modal-data', {
data: {
entryIds: this.entryIds,
siteId: this.elementIndex.siteId,
currentSectionUid: this.currentSectionUid,
},
cancelToken: this.cancelToken.token,
})
.then(({data}) => {
const listHtml = data?.listHtml;
if (listHtml) {
this.$sectionsList.html(listHtml);

this.addListener(
this.$sectionsList.find('.entry-mover-modal--item'),
'activate',
(ev) => {
let $button = $(ev.target);

// reset all the links
this.$sectionsList
.find('a')
.removeClass('sel')
.attr('aria-pressed', 'false');

// mark as selected
$button.addClass('sel').attr('aria-pressed', 'true');

// enable submit btn
if (this.$selectBtn.hasClass('disabled')) {
this.$selectBtn
.removeClass('disabled')
.attr('aria-disabled', 'false');
}
}
);
}
);
const listHtml = response.data.listHtml;
return listHtml;
} finally {
this.$sectionsListContainer.removeClass('loading');
this.cancelToken = null;
}
})
.catch(({response}) => {
Craft.cp.displayError(response?.data?.message);
this.modal.hide();
})
.finally(() => {
this.$sectionsListContainer.removeClass('loading');
this.cancelToken = null;
});
},

selectSection() {
Expand Down

0 comments on commit aa7f70a

Please sign in to comment.