Compare commits

..

No commits in common. "0ba69e41d08b07a1e39f1a238965626b28b69be0" and "b6c8d64c476825bd1c3a803f51e36b5dee94ffee" have entirely different histories.

9 changed files with 53 additions and 57 deletions

View file

@ -180,8 +180,9 @@ export default class Browser {
],
['options.inBbox', { handler: 'Switch', label: translate('Current map view') }],
]
const builder = new Form(this, fields)
builder.on('set', () => this.onFormChange())
const builder = new Form(this, fields, {
callback: () => this.onFormChange(),
})
let filtersBuilder
this.formContainer.appendChild(builder.build())
DomEvent.on(builder.form, 'reset', () => {
@ -189,8 +190,9 @@ export default class Browser {
})
if (this._umap.properties.facetKey) {
fields = this._umap.facets.build()
filtersBuilder = new Form(this._umap.facets, fields)
filtersBuilder.on('set', () => this.onFormChange())
filtersBuilder = new Form(this._umap.facets, fields, {
callback: () => this.onFormChange(),
})
DomEvent.on(filtersBuilder.form, 'reset', () => {
window.setTimeout(filtersBuilder.syncAll.bind(filtersBuilder))
})

View file

@ -226,11 +226,15 @@ class Feature {
`icon-${this.getClassName()}`
)
let builder = new MutatingForm(this, [
['datalayer', { handler: 'DataLayerSwitcher' }],
])
// removeLayer step will close the edit panel, let's reopen it
builder.on('set', () => this.edit(event))
let builder = new MutatingForm(
this,
[['datalayer', { handler: 'DataLayerSwitcher' }]],
{
callback() {
this.edit(event)
}, // removeLayer step will close the edit panel, let's reopen it
}
)
container.appendChild(builder.build())
const properties = []
@ -730,8 +734,8 @@ export class Point extends Feature {
['ui._latlng.lat', { handler: 'FloatInput', label: translate('Latitude') }],
['ui._latlng.lng', { handler: 'FloatInput', label: translate('Longitude') }],
]
const builder = new MutatingForm(this, coordinatesOptions)
builder.on('set', () => {
const builder = new MutatingForm(this, coordinatesOptions, {
callback: () => {
if (!this.ui._latlng.isValid()) {
Alert.error(translate('Invalid latitude or longitude'))
builder.restoreField('ui._latlng.lat')
@ -739,6 +743,7 @@ export class Point extends Feature {
}
this.pullGeometry()
this.zoomTo({ easing: false })
},
})
const fieldset = DomUtil.createFieldset(container, translate('Coordinates'))
fieldset.appendChild(builder.build())

View file

@ -667,12 +667,14 @@ export class DataLayer extends ServerStored {
],
]
DomUtil.createTitle(container, translate('Layer properties'), 'icon-layers')
let builder = new MutatingForm(this, metadataFields)
builder.on('set', (helper) => {
let builder = new MutatingForm(this, metadataFields, {
callback: (helper) => {
console.log(helper)
this._umap.onDataLayersChanged()
if (helper.field === 'options.type') {
this.edit()
}
},
})
container.appendChild(builder.build())

View file

@ -3,9 +3,8 @@ import * as Utils from '../utils.js'
import { SCHEMA } from '../schema.js'
import { translate } from '../i18n.js'
export class Form extends Utils.WithEvents {
export class Form {
constructor(obj, fields, properties) {
super()
this.setProperties(properties)
this.defaultProperties = {}
this.obj = obj

View file

@ -97,7 +97,7 @@ class BaseElement {
sync() {
this.set()
this.builder.fire('set', this)
this.onPostSync()
}
set() {
@ -116,6 +116,13 @@ class BaseElement {
finish() {}
onPostSync() {
if (this.properties.callback) {
this.properties.callback(this)
}
this.builder.onPostSync(this)
}
undefine() {
this.root.classList.add('undefined')
this.clear()

View file

@ -126,8 +126,9 @@ export default class Share {
exportUrl.value = window.location.protocol + iframeExporter.buildUrl()
}
buildIframeCode()
const builder = new MutatingForm(iframeExporter, UIFields)
builder.on('set', buildIframeCode)
const builder = new MutatingForm(iframeExporter, UIFields, {
callback: buildIframeCode,
})
const iframeOptions = DomUtil.createFieldset(
this.container,
translate('Embed and link options')

View file

@ -1029,6 +1029,13 @@ export default class Umap extends ServerStored {
],
]
const slideshowBuilder = new MutatingForm(this, slideshowFields, {
callback: () => {
this.slideshow.load()
// FIXME when we refactor formbuilder: this callback is called in a 'postsync'
// event, which comes after the call of `setter` method, which will call the
// map.render method, which should do this redraw.
this.bottomBar.redraw()
},
umap: this,
})
slideshow.appendChild(slideshowBuilder.build())
@ -1344,10 +1351,6 @@ export default class Umap extends ServerStored {
}
this.topBar.redraw()
},
'properties.slideshow.active': () => {
this.slideshow.load()
this.bottomBar.redraw()
},
numberOfConnectedPeers: () => {
Utils.eachElement('.connected-peers span', (el) => {
if (this.sync.websocketConnected) {

View file

@ -449,29 +449,6 @@ export function eachElement(selector, callback) {
}
}
export class WithEvents {
constructor() {
this._callbacks = {}
}
on(eventType, callback) {
if (typeof callback !== 'function') return
if (this._callbacks[eventType] === undefined) {
this._callbacks[eventType] = []
}
this._callbacks[eventType].push(callback)
}
fire(eventType, ...args) {
if (this._callbacks[eventType] === undefined) return
for (const callback of this._callbacks[eventType]) {
callback(...args)
}
}
}
export const COLORS = [
'Black',
'Navy',

View file

@ -280,7 +280,7 @@ def test_websocket_connection_can_sync_cloned_polygons(
peerB.locator("path").nth(1).drag_to(b_map_el, target_position={"x": 400, "y": 400})
peerB.locator("path").nth(1).click()
peerB.locator("summary").filter(has_text="Shape properties").click()
peerB.locator(".umap-field-color button.define").first.click()
peerB.locator(".header > a:nth-child(2)").first.click()
peerB.get_by_title("Orchid", exact=True).first.click()
peerB.locator("#map").press("Escape")
peerB.get_by_role("button", name="Save").click()