wip(forms): remove defaultOptions from builder
This commit is contained in:
parent
4cdf682706
commit
5295e931a5
2 changed files with 45 additions and 34 deletions
|
@ -103,11 +103,15 @@ U.FeatureMixin = {
|
||||||
L._('Feature properties')
|
L._('Feature properties')
|
||||||
)
|
)
|
||||||
|
|
||||||
let builder = new U.FormBuilder(this, ['datalayer'], {
|
let builder = new U.FormBuilder(
|
||||||
|
this,
|
||||||
|
[['datalayer', { handler: 'DataLayerSwitcher' }]],
|
||||||
|
{
|
||||||
callback: function () {
|
callback: function () {
|
||||||
this.edit(e)
|
this.edit(e)
|
||||||
}, // removeLayer step will close the edit panel, let's reopen it
|
}, // removeLayer step will close the edit panel, let's reopen it
|
||||||
})
|
}
|
||||||
|
)
|
||||||
container.appendChild(builder.build())
|
container.appendChild(builder.build())
|
||||||
|
|
||||||
const properties = []
|
const properties = []
|
||||||
|
|
|
@ -977,19 +977,8 @@ U.FormBuilder = L.FormBuilder.extend({
|
||||||
className: 'umap-form',
|
className: 'umap-form',
|
||||||
},
|
},
|
||||||
|
|
||||||
defaultOptions: {
|
|
||||||
color: { handler: 'ColorPicker' },
|
|
||||||
fillColor: { handler: 'ColorPicker' },
|
|
||||||
iconUrl: { handler: 'IconUrl' },
|
|
||||||
datalayer: { handler: 'DataLayerSwitcher' },
|
|
||||||
datalayersControl: { handler: 'DataLayersControl' },
|
|
||||||
licence: { handler: 'LicenceChooser' },
|
|
||||||
},
|
|
||||||
|
|
||||||
computeDefaultOptions: function () {
|
computeDefaultOptions: function () {
|
||||||
for (let [key, schema] of Object.entries(U.SCHEMA)) {
|
for (let [key, schema] of Object.entries(U.SCHEMA)) {
|
||||||
schema = L.Util.extend({}, schema, this.defaultOptions[key])
|
|
||||||
if (!schema.handler) {
|
|
||||||
if (schema.type === Boolean) {
|
if (schema.type === Boolean) {
|
||||||
if (schema.nullable) schema.handler = 'NullableChoices'
|
if (schema.nullable) schema.handler = 'NullableChoices'
|
||||||
else schema.handler = 'Switch'
|
else schema.handler = 'Switch'
|
||||||
|
@ -999,7 +988,10 @@ U.FormBuilder = L.FormBuilder.extend({
|
||||||
if (schema.step) schema.handler = 'Range'
|
if (schema.step) schema.handler = 'Range'
|
||||||
else schema.handler = 'IntInput'
|
else schema.handler = 'IntInput'
|
||||||
} else if (schema.choices) {
|
} else if (schema.choices) {
|
||||||
const text_length = schema.choices.reduce((acc, [value, label]) => acc + label.length, 0)
|
const text_length = schema.choices.reduce(
|
||||||
|
(acc, [value, label]) => acc + label.length,
|
||||||
|
0
|
||||||
|
)
|
||||||
// Try to be smart and use MultiChoice only
|
// Try to be smart and use MultiChoice only
|
||||||
// for choices where labels are shorts…
|
// for choices where labels are shorts…
|
||||||
if (text_length < 40) {
|
if (text_length < 40) {
|
||||||
|
@ -1008,6 +1000,21 @@ U.FormBuilder = L.FormBuilder.extend({
|
||||||
schema.handler = 'Select'
|
schema.handler = 'Select'
|
||||||
schema.selectOptions = schema.choices
|
schema.selectOptions = schema.choices
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
switch (key) {
|
||||||
|
case 'color':
|
||||||
|
case 'fillColor':
|
||||||
|
schema.handler = 'ColorPicker'
|
||||||
|
break
|
||||||
|
case 'iconUrl':
|
||||||
|
schema.handler = 'IconUrl'
|
||||||
|
break
|
||||||
|
case 'datalayersControl':
|
||||||
|
schema.handler = 'DataLayersControl'
|
||||||
|
break
|
||||||
|
case 'licence':
|
||||||
|
schema.handler = 'LicenceChooser'
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FormBuilder use this key for the input type itself
|
// FormBuilder use this key for the input type itself
|
||||||
|
|
Loading…
Reference in a new issue