kopia lustrzana https://github.com/wagtail/wagtail
Consistently use edit_url in the state representation of choosers
Previously we were using edit_link in dicts handled by JS, and edit_url in dicts handled by Python, meaning that ChooserBlock.get_form_state had to rewrite itpull/8934/head
rodzic
0077183682
commit
90e91e0e4a
|
@ -4,7 +4,7 @@ export class Chooser {
|
|||
modalOnloadHandlers = chooserModalOnloadHandlers;
|
||||
|
||||
titleStateKey = 'title'; // key used in the 'state' dictionary to hold the human-readable title
|
||||
editLinkStateKey = 'edit_link'; // key used in the 'state' dictionary to hold the URL of the edit page
|
||||
editUrlStateKey = 'edit_url'; // key used in the 'state' dictionary to hold the URL of the edit page
|
||||
chosenResponseName = 'chosen'; // identifier for the ModalWorkflow response that indicates an item was chosen
|
||||
|
||||
constructor(id) {
|
||||
|
@ -34,7 +34,7 @@ export class Chooser {
|
|||
getStateFromHTML() {
|
||||
/*
|
||||
Construct initial state of the chooser from the rendered (static) HTML.
|
||||
State is either null (= no item chosen) or a dict of id, title and edit_link.
|
||||
State is either null (= no item chosen) or a dict of id, title and edit_url.
|
||||
|
||||
The result returned from the chooser modal (see get_chosen_response_data in
|
||||
wagtail.admin.views.generic.chooser.ChosenView) is a superset of this, and can therefore be
|
||||
|
@ -47,8 +47,8 @@ export class Chooser {
|
|||
if (this.titleElement && this.titleStateKey) {
|
||||
state[this.titleStateKey] = this.titleElement.textContent;
|
||||
}
|
||||
if (this.editLink && this.editLinkStateKey) {
|
||||
state[this.editLinkStateKey] = this.editLink.getAttribute('href');
|
||||
if (this.editLink && this.editUrlStateKey) {
|
||||
state[this.editUrlStateKey] = this.editLink.getAttribute('href');
|
||||
}
|
||||
return state;
|
||||
} else {
|
||||
|
@ -89,7 +89,7 @@ export class Chooser {
|
|||
}
|
||||
this.chooserElement.classList.remove('blank');
|
||||
if (this.editLink) {
|
||||
const editUrl = newState[this.editLinkStateKey];
|
||||
const editUrl = newState[this.editUrlStateKey];
|
||||
if (editUrl) {
|
||||
this.editLink.setAttribute('href', editUrl);
|
||||
this.editLink.classList.remove('u-hidden');
|
||||
|
|
|
@ -156,7 +156,7 @@ describe('ModalWorkflowSource', () => {
|
|||
title: 'Test',
|
||||
alt: 'Test',
|
||||
class: 'richtext-image right',
|
||||
edit_link: '/admin/images/53/',
|
||||
edit_url: '/admin/images/53/',
|
||||
format: 'right',
|
||||
preview: {
|
||||
url: '/media/images/test.width-500.jpg',
|
||||
|
@ -183,7 +183,7 @@ describe('ModalWorkflowSource', () => {
|
|||
it('DOCUMENT', () => {
|
||||
expect(
|
||||
documentSource.filterEntityData({
|
||||
edit_link: '/admin/documents/edit/1/',
|
||||
edit_url: '/admin/documents/edit/1/',
|
||||
filename: 'test.pdf',
|
||||
id: 1,
|
||||
title: 'Test',
|
||||
|
|
|
@ -4,7 +4,7 @@ class PageChooser extends Chooser {
|
|||
// eslint-disable-next-line no-undef
|
||||
modalOnloadHandlers = PAGE_CHOOSER_MODAL_ONLOAD_HANDLERS;
|
||||
titleStateKey = 'adminTitle';
|
||||
editLinkStateKey = 'editUrl';
|
||||
editUrlStateKey = 'editUrl';
|
||||
chosenResponseName = 'pageChosen';
|
||||
|
||||
constructor(id, parentId, options) {
|
||||
|
|
|
@ -12,7 +12,7 @@ class ImageChooser extends Chooser {
|
|||
getStateFromHTML() {
|
||||
/*
|
||||
Construct initial state of the chooser from the rendered (static) HTML.
|
||||
State is either null (= no image chosen) or a dict of id, edit_link, title
|
||||
State is either null (= no image chosen) or a dict of id, edit_url, title
|
||||
and preview (= a dict of url, width, height).
|
||||
*/
|
||||
const state = super.getStateFromHTML();
|
||||
|
|
|
@ -347,7 +347,7 @@ class ChosenResponseMixin:
|
|||
return {
|
||||
"id": str(self.get_object_id(item)),
|
||||
self.response_data_title_key: self.get_display_title(item),
|
||||
"edit_link": self.get_edit_item_url(item),
|
||||
"edit_url": self.get_edit_item_url(item),
|
||||
}
|
||||
|
||||
def get_chosen_response(self, item):
|
||||
|
|
|
@ -24,7 +24,7 @@ class DocumentChooserBlock(ChooserBlock):
|
|||
else:
|
||||
return {
|
||||
"id": value_data["id"],
|
||||
"edit_link": value_data["edit_url"],
|
||||
"edit_url": value_data["edit_url"],
|
||||
"title": value_data["title"],
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class ImageChooserBlock(ChooserBlock):
|
|||
else:
|
||||
return {
|
||||
"id": value_data["id"],
|
||||
"edit_link": value_data["edit_url"],
|
||||
"edit_url": value_data["edit_url"],
|
||||
"title": value_data["title"],
|
||||
"preview": value_data["preview"],
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class SnippetChooserBlock(ChooserBlock):
|
|||
else:
|
||||
return {
|
||||
"id": value_data["id"],
|
||||
"edit_link": value_data["edit_url"],
|
||||
"edit_url": value_data["edit_url"],
|
||||
"string": value_data["string"],
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue