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(
|
||||||
callback: function () {
|
this,
|
||||||
this.edit(e)
|
[['datalayer', { handler: 'DataLayerSwitcher' }]],
|
||||||
}, // removeLayer step will close the edit panel, let's reopen it
|
{
|
||||||
})
|
callback: function () {
|
||||||
|
this.edit(e)
|
||||||
|
}, // removeLayer step will close the edit panel, let's reopen it
|
||||||
|
}
|
||||||
|
)
|
||||||
container.appendChild(builder.build())
|
container.appendChild(builder.build())
|
||||||
|
|
||||||
const properties = []
|
const properties = []
|
||||||
|
|
|
@ -977,37 +977,44 @@ 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.type === Boolean) {
|
||||||
if (!schema.handler) {
|
if (schema.nullable) schema.handler = 'NullableChoices'
|
||||||
if (schema.type === Boolean) {
|
else schema.handler = 'Switch'
|
||||||
if (schema.nullable) schema.handler = 'NullableChoices'
|
} else if (schema.type === 'Text') {
|
||||||
else schema.handler = 'Switch'
|
schema.handler = 'Textarea'
|
||||||
} else if (schema.type === 'Text') {
|
} else if (schema.type === Number) {
|
||||||
schema.handler = 'Textarea'
|
if (schema.step) schema.handler = 'Range'
|
||||||
} else if (schema.type === Number) {
|
else schema.handler = 'IntInput'
|
||||||
if (schema.step) schema.handler = 'Range'
|
} else if (schema.choices) {
|
||||||
else schema.handler = 'IntInput'
|
const text_length = schema.choices.reduce(
|
||||||
} else if (schema.choices) {
|
(acc, [value, label]) => acc + label.length,
|
||||||
const text_length = schema.choices.reduce((acc, [value, label]) => acc + label.length, 0)
|
0
|
||||||
// Try to be smart and use MultiChoice only
|
)
|
||||||
// for choices where labels are shorts…
|
// Try to be smart and use MultiChoice only
|
||||||
if (text_length < 40) {
|
// for choices where labels are shorts…
|
||||||
schema.handler = 'MultiChoice'
|
if (text_length < 40) {
|
||||||
} else {
|
schema.handler = 'MultiChoice'
|
||||||
schema.handler = 'Select'
|
} else {
|
||||||
schema.selectOptions = schema.choices
|
schema.handler = 'Select'
|
||||||
}
|
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