chore: replace native confirm by our styled ones

This commit is contained in:
Yohan Boniface 2024-10-04 17:05:32 +02:00
parent 4940f6c329
commit ebd3896e91
4 changed files with 33 additions and 28 deletions

View file

@ -874,7 +874,9 @@ export class DataLayer {
async restore(version) { async restore(version) {
if (!this.map.editEnabled) return if (!this.map.editEnabled) return
if (!confirm(translate('Are you sure you want to restore this version?'))) return this.map.dialog
.confirm(translate('Are you sure you want to restore this version?'))
.then(async () => {
const [geojson, response, error] = await this.map.server.get( const [geojson, response, error] = await this.map.server.get(
this.getVersionUrl(version) this.getVersionUrl(version)
) )
@ -886,6 +888,7 @@ export class DataLayer {
else this.addData(geojson) else this.addData(geojson)
this.isDirty = true this.isDirty = true
} }
})
} }
featuresToGeoJSON() { featuresToGeoJSON() {
@ -1160,8 +1163,11 @@ export class DataLayer {
'click', 'click',
function () { function () {
if (!this.isVisible()) return if (!this.isVisible()) return
if (!confirm(translate('Are you sure you want to delete this layer?'))) return this.map.dialog
.confirm(translate('Are you sure you want to delete this layer?'))
.then(() => {
this._delete() this._delete()
})
}, },
this this
) )

View file

@ -13,7 +13,7 @@ L.Map.mergeOptions({
// we cannot rely on this because of the y is overriden by Leaflet // we cannot rely on this because of the y is overriden by Leaflet
// See https://github.com/Leaflet/Leaflet/pull/9201 // See https://github.com/Leaflet/Leaflet/pull/9201
// And let's remove this -y when this PR is merged and released. // 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: [], licences: [],
licence: '', licence: '',
enableMarkerDraw: true, enableMarkerDraw: true,
@ -1658,13 +1658,13 @@ U.Map = L.Map.extend({
}, },
clone: async function () { clone: async function () {
if ( this.dialog
confirm(L._('Are you sure you want to clone this map and all its datalayers?')) .confirm(L._('Are you sure you want to clone this map and all its datalayers?'))
) { .then(async () => {
const url = this.urls.get('map_clone', { map_id: this.options.umap_id }) const url = this.urls.get('map_clone', { map_id: this.options.umap_id })
const [data, response, error] = await this.server.post(url) const [data, response, error] = await this.server.post(url)
if (data.redirect) window.location = data.redirect if (data.redirect) window.location = data.redirect
} })
}, },
removeDataLayers: function () { removeDataLayers: function () {

View file

@ -60,12 +60,11 @@ def test_cancel_deleting_datalayer_should_restore(
expect(layers).to_have_count(1) expect(layers).to_have_count(1)
expect(markers).to_have_count(1) expect(markers).to_have_count(1)
page.get_by_role("link", name="Manage layers").click() page.get_by_role("link", name="Manage layers").click()
page.once("dialog", lambda dialog: dialog.accept())
page.locator(".panel.right").get_by_title("Delete layer").click() page.locator(".panel.right").get_by_title("Delete layer").click()
page.get_by_role("button", name="OK").click()
expect(markers).to_have_count(0) expect(markers).to_have_count(0)
page.get_by_role("button", name="Open browser").click() page.get_by_role("button", name="Open browser").click()
expect(page.get_by_text("test datalayer")).to_be_hidden() expect(page.get_by_text("test datalayer")).to_be_hidden()
page.once("dialog", lambda dialog: dialog.accept())
page.get_by_role("button", name="Cancel edits").click() page.get_by_role("button", name="Cancel edits").click()
page.locator("dialog").get_by_role("button", name="OK").click() page.locator("dialog").get_by_role("button", name="OK").click()
expect(markers).to_have_count(1) expect(markers).to_have_count(1)
@ -174,8 +173,8 @@ def test_can_restore_version(live_server, openmap, page, datalayer):
page.get_by_role("link", name="Manage layers").click() page.get_by_role("link", name="Manage layers").click()
page.locator(".panel.right").get_by_title("Edit", exact=True).click() page.locator(".panel.right").get_by_title("Edit", exact=True).click()
page.get_by_text("Versions").click() page.get_by_text("Versions").click()
page.once("dialog", lambda dialog: dialog.accept())
page.get_by_role("button", name="Restore this version").last.click() page.get_by_role("button", name="Restore this version").last.click()
page.get_by_role("button", name="OK").click()
expect(marker).to_have_class(re.compile(".*umap-ball-icon.*")) expect(marker).to_have_class(re.compile(".*umap-ball-icon.*"))
@ -196,8 +195,8 @@ def test_deleting_datalayer_should_remove_from_browser_and_layers_list(
page.get_by_role("link", name="Manage layers").click() page.get_by_role("link", name="Manage layers").click()
expect(panel.get_by_text("test datalayer")).to_be_visible() expect(panel.get_by_text("test datalayer")).to_be_visible()
expect(edit_panel.get_by_text("test datalayer")).to_be_visible() expect(edit_panel.get_by_text("test datalayer")).to_be_visible()
page.once("dialog", lambda dialog: dialog.accept())
page.locator(".panel.right").get_by_title("Delete layer").click() page.locator(".panel.right").get_by_title("Delete layer").click()
page.get_by_role("button", name="OK").click()
expect(panel.get_by_text("test datalayer")).to_be_hidden() expect(panel.get_by_text("test datalayer")).to_be_hidden()
expect(edit_panel.get_by_text("test datalayer")).to_be_hidden() expect(edit_panel.get_by_text("test datalayer")).to_be_hidden()
@ -210,6 +209,6 @@ def test_deleting_datalayer_should_remove_from_caption(
page.get_by_role("button", name="About").click() page.get_by_role("button", name="About").click()
page.get_by_role("link", name="Manage layers").click() page.get_by_role("link", name="Manage layers").click()
expect(panel.get_by_text("test datalayer")).to_be_visible() expect(panel.get_by_text("test datalayer")).to_be_visible()
page.once("dialog", lambda dialog: dialog.accept())
page.locator(".panel.right").get_by_title("Delete layer").click() page.locator(".panel.right").get_by_title("Delete layer").click()
page.get_by_role("button", name="OK").click()
expect(panel.get_by_text("test datalayer")).to_be_hidden() expect(panel.get_by_text("test datalayer")).to_be_hidden()

View file

@ -234,8 +234,8 @@ def test_can_delete_datalayer(live_server, map, login, datalayer):
expect(layers).to_have_count(1) expect(layers).to_have_count(1)
expect(markers).to_have_count(1) expect(markers).to_have_count(1)
page.get_by_role("link", name="Manage layers").click() page.get_by_role("link", name="Manage layers").click()
page.once("dialog", lambda dialog: dialog.accept())
page.locator(".panel.right").get_by_title("Delete layer").click() page.locator(".panel.right").get_by_title("Delete layer").click()
page.get_by_role("button", name="OK").click()
with page.expect_response(re.compile(r".*/datalayer/delete/.*")): with page.expect_response(re.compile(r".*/datalayer/delete/.*")):
page.get_by_role("button", name="Save").click() page.get_by_role("button", name="Save").click()
expect(markers).to_have_count(0) expect(markers).to_have_count(0)