mirror of
https://github.com/umap-project/umap.git
synced 2025-04-30 20:12:37 +02:00
fix: django cannot run collectstatic with circular imports in modules
alert.js was importing request.js which then imports alert.js In the process, we moved the post to send the email out of the alert.js file, and thus tried another pattern to communicate data between an alert and its caller.
This commit is contained in:
parent
99595e3e2f
commit
c144c9d958
3 changed files with 37 additions and 26 deletions
|
@ -1,5 +1,4 @@
|
|||
import { translate } from '../../modules/i18n.js'
|
||||
import { ServerRequest } from '../../modules/request.js'
|
||||
import { uMapElement } from '../base.js'
|
||||
|
||||
class uMapAlert extends uMapElement {
|
||||
|
@ -77,9 +76,14 @@ class uMapAlertCreation extends uMapAlert {
|
|||
// biome-ignore lint/style/useNumberNamespace: Number.Infinity returns undefined by default
|
||||
duration = Infinity,
|
||||
editLink = undefined,
|
||||
sendLink = undefined
|
||||
sendCallback = undefined
|
||||
) {
|
||||
uMapAlertCreation.emit('alertCreation', { message, duration, editLink, sendLink })
|
||||
uMapAlertCreation.emit('alertCreation', {
|
||||
message,
|
||||
duration,
|
||||
editLink,
|
||||
sendCallback,
|
||||
})
|
||||
}
|
||||
|
||||
constructor() {
|
||||
|
@ -94,7 +98,7 @@ class uMapAlertCreation extends uMapAlert {
|
|||
duration = 5000,
|
||||
message = '',
|
||||
editLink = undefined,
|
||||
sendLink = undefined,
|
||||
sendCallback = undefined,
|
||||
} = event.detail
|
||||
uMapAlert.prototype.onAlert.call(this, { detail: { level, duration, message } })
|
||||
this.linkWrapper.querySelector('input[type="url"]').value = editLink
|
||||
|
@ -104,15 +108,14 @@ class uMapAlertCreation extends uMapAlert {
|
|||
L.Util.copyToClipboard(editLink)
|
||||
event.target.value = translate('✅ Copied!')
|
||||
})
|
||||
if (sendLink) {
|
||||
if (sendCallback) {
|
||||
this.formWrapper.removeAttribute('hidden')
|
||||
const form = this.formWrapper.querySelector('form')
|
||||
form.addEventListener('submit', async (event) => {
|
||||
event.preventDefault()
|
||||
const formData = new FormData(form)
|
||||
const server = new ServerRequest()
|
||||
sendCallback(formData)
|
||||
this.removeAttribute('open')
|
||||
await server.post(sendLink, {}, formData)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -124,12 +127,8 @@ class uMapAlertCreation extends uMapAlert {
|
|||
}
|
||||
|
||||
class uMapAlertConflict extends uMapAlert {
|
||||
static error(
|
||||
message,
|
||||
// biome-ignore lint/style/useNumberNamespace: Number.Infinity returns undefined by default
|
||||
duration = Infinity
|
||||
) {
|
||||
uMapAlertConflict.emit('alertConflict', { level: 'error', message, duration })
|
||||
static error(message, forceCallback) {
|
||||
uMapAlertConflict.emit('alertConflict', { level: 'error', message, forceCallback })
|
||||
}
|
||||
|
||||
constructor() {
|
||||
|
@ -138,14 +137,20 @@ class uMapAlertConflict extends uMapAlert {
|
|||
}
|
||||
|
||||
onAlertConflict(event) {
|
||||
const { level = 'info', duration = 5000, message = '' } = event.detail
|
||||
// biome-ignore lint/style/useNumberNamespace: Number.Infinity returns undefined by default
|
||||
const {
|
||||
level = 'info',
|
||||
duration = Infinity,
|
||||
message = '',
|
||||
forceCallback = undefined,
|
||||
} = event.detail
|
||||
uMapAlert.prototype.onAlert.call(this, { detail: { level, duration, message } })
|
||||
const form = this.conflictWrapper.querySelector('form')
|
||||
form.addEventListener('submit', (event) => {
|
||||
event.preventDefault()
|
||||
switch (event.submitter.id) {
|
||||
case 'your-changes':
|
||||
uMapAlertConflict.emit('alertConflictOverride')
|
||||
forceCallback()
|
||||
break
|
||||
case 'their-changes':
|
||||
window.location.reload()
|
||||
|
|
|
@ -13,7 +13,7 @@ L.Map.mergeOptions({
|
|||
// we cannot rely on this because of the y is overriden by Leaflet
|
||||
// See https://github.com/Leaflet/Leaflet/pull/9201
|
||||
// And let's remove this -y when this PR is merged and released.
|
||||
demoTileInfos: { s: 'a', z: 9, x: 265, y: 181, '-y': 181, r: '' },
|
||||
demoTileInfos: { 's': 'a', 'z': 9, 'x': 265, 'y': 181, '-y': 181, 'r': '' },
|
||||
licences: [],
|
||||
licence: '',
|
||||
enableMarkerDraw: true,
|
||||
|
@ -1063,17 +1063,14 @@ U.Map = L.Map.extend({
|
|||
this.permissions.setOptions(data.permissions)
|
||||
this.permissions.commit()
|
||||
if (data?.permissions?.anonymous_edit_url) {
|
||||
const send_edit_link_url =
|
||||
this.options.urls.map_send_edit_link &&
|
||||
this.urls.get('map_send_edit_link', {
|
||||
map_id: this.options.umap_id,
|
||||
})
|
||||
this.once('saved', () => {
|
||||
U.AlertCreation.info(
|
||||
L._('Your map has been created with an anonymous account!'),
|
||||
Number.Infinity,
|
||||
data.permissions.anonymous_edit_url,
|
||||
send_edit_link_url
|
||||
this.options.urls.map_send_edit_link
|
||||
? this.sendEditLinkEmail.bind(this)
|
||||
: null
|
||||
)
|
||||
})
|
||||
} else {
|
||||
|
@ -1887,4 +1884,13 @@ U.Map = L.Map.extend({
|
|||
})
|
||||
return bounds
|
||||
},
|
||||
|
||||
sendEditLinkEmail: async function (formData) {
|
||||
const sendLink =
|
||||
this.options.urls.map_send_edit_link &&
|
||||
this.urls.get('map_send_edit_link', {
|
||||
map_id: this.options.umap_id,
|
||||
})
|
||||
await this.server.post(sendLink, {}, formData)
|
||||
},
|
||||
})
|
||||
|
|
|
@ -1708,11 +1708,11 @@ U.DataLayer = L.Evented.extend({
|
|||
L._(
|
||||
'Whoops! Other contributor(s) changed some of the same map elements as you. ' +
|
||||
'This situation is tricky, you have to choose carefully which version is pertinent.'
|
||||
)
|
||||
),
|
||||
async () => {
|
||||
await this._trySave(url, {}, formData)
|
||||
}
|
||||
)
|
||||
document.addEventListener('umap:alertConflictOverride', async (event) => {
|
||||
await this._trySave(url, {}, formData)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// Response contains geojson only if save has conflicted and conflicts have
|
||||
|
|
Loading…
Reference in a new issue