2024-09-24 18:22:25 +02:00
|
|
|
class CCPInputWidgetEditorController extends HTMLElement {
|
|
|
|
|
2022-06-27 18:52:48 +02:00
|
|
|
#input = null
|
|
|
|
#index = null
|
|
|
|
#type = null
|
2024-06-07 17:39:35 +02:00
|
|
|
#messages = {
|
2024-09-24 18:22:25 +02:00
|
|
|
"en": {
|
|
|
|
"input_id_help": "The Id of the input. This has to be unique accross all the inputs the method. This is used as variable expansion in scripts.",
|
|
|
|
"input_delete_help": "Delete this input",
|
|
|
|
"title": "Title",
|
|
|
|
"title_help": "Title of the input. This is how the input will appear in forms.",
|
|
|
|
"description": "Description",
|
|
|
|
"description_help": "A description for this input",
|
|
|
|
"min_occurs": "Min. count",
|
|
|
|
"max_occurs": "Max. count",
|
|
|
|
"min_occurs_help": "Minimum cardinality of this input",
|
|
|
|
"max_occurs_help": "Maximum cardinality of this input",
|
|
|
|
"type": "Type",
|
|
|
|
"type_help": "Set the type of the input. Either String or Enumeration",
|
|
|
|
"mime": "Mime",
|
|
|
|
"mime_help": "Set MIME type of expected input",
|
|
|
|
"format": "Format",
|
|
|
|
"format_help": "Set specific format to tune the widget that will be used in forms",
|
|
|
|
"readonly": "Read only",
|
|
|
|
"readonly_help": "If enabled this input will not be editable in forms",
|
|
|
|
"string": "String",
|
|
|
|
"enum": "Enumerated",
|
|
|
|
"options": "Options",
|
|
|
|
"options_help": "A comma separated list of options for this enumerated input",
|
|
|
|
"options_ext_help": "Comma separated list of options",
|
|
|
|
"choice": "Single choice",
|
|
|
|
"multichoice": "Multiple choices",
|
|
|
|
"default": "Default value",
|
|
|
|
"default_help": "The default value applied for this input when nothing is set explicitly"
|
2024-06-07 17:39:35 +02:00
|
|
|
}
|
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
|
2022-06-27 18:52:48 +02:00
|
|
|
#delete_icon = `
|
|
|
|
<svg style="width:24px;height:24px;pointer-events: none;" viewBox="0 0 24 24">
|
|
|
|
<path d="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z" />
|
|
|
|
</svg>
|
|
|
|
`
|
2024-09-24 18:22:25 +02:00
|
|
|
|
|
|
|
constructor() {
|
2022-06-27 18:52:48 +02:00
|
|
|
super();
|
2024-09-24 18:22:25 +02:00
|
|
|
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
|
|
|
|
connectedCallback() {
|
|
|
|
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
|
|
|
|
getLabel(key, localehint) {
|
2024-06-07 17:39:35 +02:00
|
|
|
const locale = localehint ? localehint : navigator.language
|
|
|
|
const actlocale = this.#messages[locale] ? locale : "en"
|
|
|
|
const msg = this.#messages[actlocale][key]
|
|
|
|
return msg == null || msg == undefined ? key : this.#messages[actlocale][key]
|
|
|
|
}
|
|
|
|
|
2024-09-24 18:22:25 +02:00
|
|
|
get index() {
|
2022-06-27 18:52:48 +02:00
|
|
|
return this.#index
|
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
|
|
|
|
isSelectedFormat(fmt) {
|
2024-04-16 13:07:23 +02:00
|
|
|
return this.#input.schema.format === fmt
|
2022-11-04 18:22:39 +01:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
|
|
|
|
renderDefaultByType() {
|
2024-11-15 15:24:35 +01:00
|
|
|
return `<d4s-ccp-input name="default" input="${base64EncodeUnicode(JSON.stringify(this.#input))}"></d4s-ccp-input>`
|
2023-02-06 13:54:09 +01:00
|
|
|
}
|
|
|
|
|
2024-09-24 18:22:25 +02:00
|
|
|
renderDeleteButton() {
|
|
|
|
return `<button data-index="${this.#index}" name="delete-input" title="${this.getLabel("input_delete_help")}" class="btn btn-danger ccp-toolbar-button">
|
2023-03-07 12:38:24 +01:00
|
|
|
${this.#delete_icon}
|
2023-03-07 12:40:03 +01:00
|
|
|
</button>`
|
2023-03-07 12:38:24 +01:00
|
|
|
}
|
|
|
|
|
2024-09-24 18:22:25 +02:00
|
|
|
render(input, i, reopen) {
|
2022-06-27 18:52:48 +02:00
|
|
|
this.#index = i
|
|
|
|
this.#input = input
|
|
|
|
this.#type = input.schema.enum ? "enum" : "string"
|
2024-04-16 13:07:23 +02:00
|
|
|
const minOccurs = input.minOccurs = Number(input.minOccurs) ? Number(input.minOccurs) : 0
|
|
|
|
const maxOccurs = input.maxOccurs = Number(input.maxOccurs) ? Number(input.maxOccurs) : 0
|
2022-06-27 18:52:48 +02:00
|
|
|
this.innerHTML = `
|
2024-09-24 18:22:25 +02:00
|
|
|
<details ${reopen ? 'open' : ''}>
|
2024-10-11 13:12:30 +02:00
|
|
|
<style>
|
|
|
|
details:not([open]) p[name=static_default] {
|
|
|
|
display: block !important;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<summary class="mb-3" style="position:relative">
|
2024-09-24 18:22:25 +02:00
|
|
|
<input class="form-control" style="width:auto;display:inline" required="required" name="id" value="${input.id}" title="${this.getLabel("input_id_help")}" ${input.id === 'ccpimage' ? 'readonly' : ''}/>
|
|
|
|
${input.id !== 'ccpimage' ? this.renderDeleteButton() : ''}
|
2024-10-11 13:12:30 +02:00
|
|
|
<p title="${input.schema.format === "secret" ? "*****" : input.schema.default}" name="static_default" class="m-1 px-2 d-none small text-truncate text-muted font-italic" style="user-select:none;max-width:30rem">${input.schema.format === "secret" ? "*****" : input.schema.default}</p>
|
2022-06-27 18:52:48 +02:00
|
|
|
</summary>
|
|
|
|
<div style="padding-left: 1rem;border-left: 1px solid gray;">
|
|
|
|
<div class="row mb-3">
|
|
|
|
<div class="col">
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="form-field" title="${this.getLabel("title_help")}">
|
2024-09-24 18:22:25 +02:00
|
|
|
<input name="title" class="form-control" placeholder="${this.getLabel("title")}" value="${input.title}" required="required" ${input.id === 'ccpimage' ? 'readonly' : ''}/>
|
2022-06-27 18:52:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="form-field" title="${this.getLabel("description_help")}">
|
2024-10-11 13:12:30 +02:00
|
|
|
<textarea rows="2" name="description" class="form-control" placeholder="${this.getLabel("description")}" required="required" ${input.id === 'ccpimage' ? 'readonly' : ''}>${input.description}</textarea>
|
2022-06-27 18:52:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row mb-3">
|
|
|
|
<div class="col-3">
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="form-field" title="${this.getLabel("type_help")}">
|
|
|
|
<label>${this.getLabel("type")}</label>
|
|
|
|
<select name="type" class="form-control" placeholder="${this.getLabel("type")}" value="${this.#type}">
|
|
|
|
<option value="string" ${this.#type === "string" ? "selected" : ""}>${this.getLabel("string")}</option>
|
2024-09-24 18:22:25 +02:00
|
|
|
${input.id === 'ccpimage' ? '' : `<option value="enum" ${this.#type === "enum" ? "selected" : ""}>${this.getLabel("enum")}</option>`}
|
2022-06-27 18:52:48 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="col">
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="form-field" title="${this.getLabel("min_occurs_help")}">
|
|
|
|
<label>${this.getLabel("min_occurs")}</label>
|
2024-09-24 18:22:25 +02:00
|
|
|
<input value="${minOccurs}" type="number" min="0" step="1" name="minOccurs" value="${minOccurs}" required="required" class="form-control" placeholder="${this.getLabel("min_occurs")}" ${input.id === 'ccpimage' ? 'readonly' : ''}/>
|
2022-06-27 18:52:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="col">
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="form-field" title="${this.getLabel("max_occurs_help")}">
|
|
|
|
<label>${this.getLabel("max_occurs")}</label>
|
2024-09-24 18:22:25 +02:00
|
|
|
<input value="${maxOccurs}" type="number" min="0" step="1" name="maxOccurs" value="${maxOccurs}" required="required" class="form-control" placeholder="${this.getLabel("max_occurs")}" ${input.id === 'ccpimage' ? 'readonly' : ''}/>
|
2023-09-27 12:14:35 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="col" title="${this.getLabel("readonly_help")}">
|
|
|
|
<label>${this.getLabel("readonly")}</label>
|
2023-09-27 12:14:35 +02:00
|
|
|
<div class="form-field">
|
|
|
|
<input type="checkbox" ${input.schema.readOnly ? 'checked' : ''} name="readonly" class="form-check-input">
|
2022-06-27 18:52:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div name="string-input" class="${this.#type === 'enum' ? 'd-none' : ''} row mb-3">
|
|
|
|
<div class="col-3">
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="form-field" title="${this.getLabel("format_help")}">
|
|
|
|
<label>${this.getLabel("format")}</label>
|
2024-09-24 18:22:25 +02:00
|
|
|
<select value="${input.schema.format}" name="format" class="form-control" ${input.id === 'ccpimage' ? 'readonly' : ''}>
|
2023-02-06 12:08:33 +01:00
|
|
|
<option value="none" ${this.isSelectedFormat('none') ? "selected" : ""}>None</option>
|
|
|
|
<option value="date" ${this.isSelectedFormat('date') ? "selected" : ""}>Date</option>
|
|
|
|
<option value="time" ${this.isSelectedFormat('time') ? "selected" : ""}>Time</option>
|
|
|
|
<option value="dateTime" ${this.isSelectedFormat('dateTime') ? "selected" : ""}>Date time</option>
|
2024-10-25 15:09:45 +02:00
|
|
|
<option value="number" ${this.isSelectedFormat('number') ? "selected" : ""}>Integer Number</option>
|
2023-10-09 13:25:47 +02:00
|
|
|
<option value="boolean" ${this.isSelectedFormat('boolean') ? "selected" : ""}>True/False</option>
|
2023-02-06 12:08:33 +01:00
|
|
|
<option value="code" ${this.isSelectedFormat('code') ? "selected" : ""}>Code</option>
|
|
|
|
<option value="file" ${this.isSelectedFormat('file') ? "selected" : ""}>File</option>
|
2024-04-16 13:07:23 +02:00
|
|
|
<option value="remotefile" ${this.isSelectedFormat('remotefile') ? "selected" : ""}>Workspace file</option>
|
2024-06-03 16:22:08 +02:00
|
|
|
<option value="geo" ${this.isSelectedFormat('geo') ? "selected" : ""}>Geography</option>
|
2023-02-06 12:08:33 +01:00
|
|
|
<option value="secret" ${this.isSelectedFormat('secret') ? "selected" : ""}>Secret</option>
|
2023-09-27 12:14:35 +02:00
|
|
|
<option value="url" ${this.isSelectedFormat('url') ? "selected" : ""}>Url</option>
|
2022-06-27 18:52:48 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="col" title="${this.getLabel("mime_help")}">
|
|
|
|
<label>${this.getLabel("mime")}</label>
|
2022-06-27 18:52:48 +02:00
|
|
|
<div class="form-field">
|
2024-09-24 18:22:25 +02:00
|
|
|
<input value="${input.schema.contentMediaType}" name="contentMediaType" class="form-control" placeholder="mime" ${input.id === 'ccpimage' ? 'readonly' : ''}/>
|
2022-06-27 18:52:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div name="enum-input" class="${this.#type !== 'enum' ? 'd-none' : ''} mb-3">
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="form-field" title="${this.getLabel("options_help")}">
|
|
|
|
<input name="options" class="form-control" type="text" placeholder="${this.getLabel("options")}" value="${input.schema.enum ? input.schema.enum.join(',') : ''}"/>
|
|
|
|
<small class="form-text text-muted">${this.getLabel("options_ext_help")}</small>
|
2022-06-27 18:52:48 +02:00
|
|
|
</div>
|
2024-06-07 17:39:35 +02:00
|
|
|
<div class="form-field" title="${this.getLabel("format_help")}">
|
|
|
|
<label>${this.getLabel("format")}</label>
|
2023-09-27 12:14:35 +02:00
|
|
|
<select value="${input.schema.format}" name="format" class="form-control">
|
2024-06-07 17:39:35 +02:00
|
|
|
<option value="select" ${this.isSelectedFormat('select') ? "selected" : ""}>${this.getLabel("choice")}</option>
|
2024-09-24 18:22:25 +02:00
|
|
|
<option value="checklist" ${this.isSelectedFormat('checklist') ? "selected" : ""}>${this.getLabel("multi_choice")}</option>
|
2023-09-27 12:14:35 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
2022-06-27 18:52:48 +02:00
|
|
|
</div>
|
2022-11-04 16:37:15 +01:00
|
|
|
<div name="input-default" class="mb-3">
|
2024-06-07 17:39:35 +02:00
|
|
|
<label>${this.getLabel("default")}</label>
|
|
|
|
<div class="form-field border border-info px-2 py-1" style="background-color:#0dcaf022" title="${this.getLabel("default_help")}">
|
2024-04-16 13:07:23 +02:00
|
|
|
<div name="default-container">${this.renderDefaultByType()}</div>
|
2023-09-27 12:14:35 +02:00
|
|
|
<span style="user-select:none;position:relative;top:-1.6rem;float:right;cursor:pointer" name="password_toggle" class="${this.isSelectedFormat('secret') ? 'inline' : 'd-none'}">👁</span>
|
2022-06-27 18:52:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</details>
|
2024-09-24 18:22:25 +02:00
|
|
|
`
|
|
|
|
this.addEventListener("click", ev => {
|
2022-11-04 17:43:02 +01:00
|
|
|
const ename = ev.target.getAttribute("name")
|
2024-09-24 18:22:25 +02:00
|
|
|
if (ename === "password_toggle") {
|
2022-11-04 17:43:02 +01:00
|
|
|
const w = this.querySelector("div[name=input-default] input[name=default]")
|
|
|
|
w.type = (w.type === "password" ? "" : "password")
|
|
|
|
ev.preventDefault()
|
|
|
|
}
|
|
|
|
})
|
2024-04-16 13:07:23 +02:00
|
|
|
|
|
|
|
const defaultinp = this.querySelector("div[name='input-default']")
|
2024-09-24 18:22:25 +02:00
|
|
|
defaultinp.addEventListener("input", ev => {
|
2024-04-16 13:07:23 +02:00
|
|
|
const inp = this.querySelector("d4s-ccp-input")
|
|
|
|
this.#input.schema.default = inp.value
|
2024-10-11 13:12:30 +02:00
|
|
|
const p = this.querySelector("p[name=static_default]")
|
|
|
|
p.innerHTML = p.title = inp.value
|
2024-04-16 13:07:23 +02:00
|
|
|
})
|
|
|
|
|
2024-09-24 18:22:25 +02:00
|
|
|
defaultinp.addEventListener("change", ev => {
|
2024-04-16 13:07:23 +02:00
|
|
|
const inp = this.querySelector("d4s-ccp-input")
|
|
|
|
this.#input.schema.default = inp.value
|
2024-10-11 13:12:30 +02:00
|
|
|
const p = this.querySelector("p[name=static_default]")
|
|
|
|
p.innerHTML = p.title = inp.value
|
2024-04-16 13:07:23 +02:00
|
|
|
})
|
|
|
|
|
2024-09-24 18:22:25 +02:00
|
|
|
defaultinp.addEventListener("click", ev => {
|
2024-04-16 13:07:23 +02:00
|
|
|
const src = ev.target.getAttribute("name")
|
|
|
|
if (src === "plus" || src === "minus") {
|
|
|
|
const inp = this.querySelector("d4s-ccp-input")
|
|
|
|
this.#input.schema.default = inp.value
|
2024-10-11 13:12:30 +02:00
|
|
|
const p = this.querySelector("p[name=static_default]")
|
|
|
|
p.innerHTML = p.title = inp.value
|
2024-04-16 13:07:23 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-09-24 18:22:25 +02:00
|
|
|
this.addEventListener("input", ev => {
|
2022-06-27 18:52:48 +02:00
|
|
|
const val = ev.target.value
|
|
|
|
const ename = ev.target.getAttribute("name")
|
2024-04-16 13:07:23 +02:00
|
|
|
const display = this.querySelector("div[name='default-container']")
|
2024-09-24 18:22:25 +02:00
|
|
|
if (ename === "id") {
|
2022-06-27 18:52:48 +02:00
|
|
|
this.#input.id = val
|
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
else if (ename === "title") {
|
2022-06-27 18:52:48 +02:00
|
|
|
this.#input.title = val
|
2024-09-24 18:22:25 +02:00
|
|
|
display.innerHTML = this.renderDefaultByType()
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
else if (ename === "description") {
|
2022-07-18 18:26:27 +02:00
|
|
|
this.#input.description = val
|
2024-04-16 13:07:23 +02:00
|
|
|
display.innerHTML = this.renderDefaultByType()
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
else if (ename === "minOccurs") {
|
2024-04-16 13:07:23 +02:00
|
|
|
this.#input.minOccurs = Number(val) ? Number(val) : 0
|
|
|
|
display.innerHTML = this.renderDefaultByType()
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
else if (ename === "maxOccurs") {
|
2024-04-16 13:07:23 +02:00
|
|
|
this.#input.maxOccurs = Number(val) ? Number(val) : 0
|
|
|
|
display.innerHTML = this.renderDefaultByType()
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
else if (ename === "format") {
|
|
|
|
this.#input.schema.default = this.formatConversion(this.#input.schema.format, this.#input.schema.default, val)
|
2022-06-27 18:52:48 +02:00
|
|
|
this.#input.schema.format = val
|
2024-04-16 13:07:23 +02:00
|
|
|
display.innerHTML = this.renderDefaultByType()
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
else if (ename === "contentMediaType") {
|
2022-06-27 18:52:48 +02:00
|
|
|
this.#input.schema.contentMediaType = val
|
2024-04-16 13:07:23 +02:00
|
|
|
display.innerHTML = this.renderDefaultByType()
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
else if (ename === "options") {
|
2022-06-27 18:52:48 +02:00
|
|
|
this.#input.schema.enum = val.split(",")
|
2024-09-24 18:22:25 +02:00
|
|
|
if (this.#input.schema.enum.indexOf(this.#input.schema.default) === -1) {
|
|
|
|
this.#input.schema.default = this.#input.schema.enum[0]
|
|
|
|
}
|
2024-04-16 13:07:23 +02:00
|
|
|
display.innerHTML = this.renderDefaultByType()
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
else if (ename === "readonly") {
|
2023-06-07 18:02:17 +02:00
|
|
|
this.#input.schema.readOnly = ev.target.checked
|
2024-04-16 13:07:23 +02:00
|
|
|
display.innerHTML = this.renderDefaultByType()
|
2023-06-07 18:02:17 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
else if (ename === "type") {
|
2022-06-27 18:52:48 +02:00
|
|
|
this.#type = ev.target.value
|
2024-09-24 18:22:25 +02:00
|
|
|
if (this.#type === "enum") {
|
2022-06-27 18:52:48 +02:00
|
|
|
this.querySelector("div[name=string-input]").classList.add("d-none")
|
|
|
|
this.querySelector("div[name=enum-input]").classList.remove("d-none")
|
2024-09-24 18:22:25 +02:00
|
|
|
this.querySelector("div[name=enum-input] select[name=format]").value = "select"
|
|
|
|
this.#input.schema.format = "select"
|
2022-06-27 18:52:48 +02:00
|
|
|
this.#input.schema.enum = this.querySelector("input[name=options]").value.split(",")
|
2024-09-24 18:22:25 +02:00
|
|
|
if (this.#input.schema.enum.indexOf(this.#input.schema.default) === -1) {
|
|
|
|
this.#input.schema.default = this.#input.schema.enum[0]
|
|
|
|
}
|
|
|
|
} else if (this.#type === "string") {
|
2022-06-27 18:52:48 +02:00
|
|
|
this.querySelector("div[name=enum-input]").classList.add("d-none")
|
|
|
|
this.querySelector("div[name=string-input]").classList.remove("d-none")
|
2024-09-24 18:22:25 +02:00
|
|
|
this.#input.schema.format = "none"
|
2022-06-27 18:52:48 +02:00
|
|
|
delete this.#input.schema['enum']
|
2024-04-16 13:07:23 +02:00
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
display.innerHTML = this.renderDefaultByType()
|
2024-04-16 13:07:23 +02:00
|
|
|
}
|
2022-06-27 18:52:48 +02:00
|
|
|
})
|
|
|
|
}
|
2024-09-24 18:22:25 +02:00
|
|
|
|
|
|
|
boolean2number(prev){
|
|
|
|
if(Array.isArray(prev)){
|
|
|
|
return prev.map(v=>(v === "true" || v === true ? "1" : "0"))
|
|
|
|
} else return prev === "true" || prev === true ? "1" : "0"
|
|
|
|
}
|
|
|
|
|
|
|
|
none2number(prev){
|
|
|
|
if(Array.isArray(prev)){
|
|
|
|
return prev.map(v=>(isNaN(Number(v)) ? "0" : v))
|
|
|
|
} else return isNaN(Number(prev)) ? "0" : prev
|
|
|
|
}
|
|
|
|
|
|
|
|
number2boolean(prev){
|
|
|
|
if(Array.isArray(prev)){
|
|
|
|
return prev.map(v=>(Number(v) !== 0 ? "true" : "false"))
|
|
|
|
} else return Number(prev) !== 0 ? "true" : "false"
|
|
|
|
}
|
|
|
|
|
|
|
|
none2boolean(prev){
|
|
|
|
if(Array.isArray(prev)){
|
|
|
|
return prev.map(v=>(["true", "false"].indexOf(v.toLowerCase()) !== -1 ? v.toLowerCase() : "false"))
|
|
|
|
} else return ["true", "false"].indexOf(prev.toLowerCase()) !== -1 ? prev.toLowerCase() : "false"
|
|
|
|
}
|
|
|
|
|
|
|
|
any2boolean(prev){
|
|
|
|
if(Array.isArray(prev)){
|
|
|
|
return prev.map(v=>String(!!v))
|
|
|
|
} else return String(!!v);
|
|
|
|
}
|
|
|
|
|
|
|
|
any2empty(prev){
|
|
|
|
if(Array.isArray(prev)){
|
|
|
|
return prev.map(v=>"")
|
|
|
|
} else return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
formatConversion(prevformat, prevvalue, format){
|
|
|
|
if(format === "none"){
|
|
|
|
return prevvalue;
|
|
|
|
}
|
|
|
|
if(format === "number"){
|
|
|
|
if(prevformat === "boolean") return this.boolean2number(prevvalue);
|
|
|
|
if(!prevformat || prevformat === "none") return this.none2number(prevvalue);
|
|
|
|
return "0";
|
|
|
|
}
|
|
|
|
if(format === "boolean"){
|
|
|
|
if(prevformat === "number") return this.number2boolean(prevvalue)
|
|
|
|
if(!prevformat || prevformat === "none") return this.none2boolean(prevvalue)
|
|
|
|
return this.any2boolean(prevvalue)
|
|
|
|
}
|
|
|
|
return this.any2empty(prevvalue)
|
|
|
|
}
|
|
|
|
|
2022-06-27 18:52:48 +02:00
|
|
|
}
|
2023-02-06 12:08:33 +01:00
|
|
|
window.customElements.define('d4s-ccp-input-editor', CCPInputWidgetEditorController);
|