2022-06-27 18:52:48 +02:00
class CCPOutputWidgetEditorController extends HTMLElement {
# output = null
# index = null
# type = null
2024-06-07 17:39:35 +02:00
# messages = {
"en" : {
"output_id_help" : "The Id of the output. This has to be unique accross all the outputs the method" ,
"output_delete_help" : "Delete this output" ,
"output_title_help" : "Title of the output. This is how the output will appear in forms." ,
"output_description_help" : "A description for this output" ,
"min_occurs_help" : "Minimum cardinality" ,
"max_occurs_help" : "Msximum cardinality" ,
"mimetype_help" : "Set MIME type of expected output" ,
"file_path" : "Path to file" ,
"file_path_help" : "Define the path to the file holding the output. This documents the location of the output in the zip archive returned by the execution. Paths in the execution runtime instead are infrastructure dependant."
}
}
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" / >
< / s v g >
`
2024-06-07 17:39:35 +02:00
getLabel ( key , localehint ) {
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 ]
}
2022-06-27 18:52:48 +02:00
constructor ( ) {
super ( )
}
connectedCallback ( controller ) {
}
get index ( ) {
return this . # index
}
render ( output , i ) {
this . # index = i
this . # output = output
this . # type = output . schema . enum ? "enum" : "string"
this . innerHTML = `
< details >
< summary class = "mb-3" >
2024-06-07 17:39:35 +02:00
< input class = "form-control" style = "width:auto;display:inline" required = "required" name = "id" value = "${this.#output.id}" title = "${this.getLabel('output_id_help')}" / >
< button data - index = "${this.#index}" name = "delete-output" title = "${this.getLabel('output_delete_help')}" class = "btn btn-danger ccp-toolbar-button" >
2022-06-27 18:52:48 +02:00
$ { this . # delete _icon }
< / b u t t o n >
< / s u m m a r y >
< 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('output_title_help')}" >
2022-06-27 18:52:48 +02:00
< input name = "title" class = "form-control" placeholder = "title" value = "${this.#output.title}" required = "required" / >
< / d i v >
< / d i v >
< / d i v >
< div class = "mb-3" >
2024-06-07 17:39:35 +02:00
< div class = "form-field" title = "${this.getLabel('output_description_help')}" >
2023-12-13 19:17:04 +01:00
< textarea rows = "1" name = "description" class = "form-control" placeholder = "description" required = "required" > $ { this . # output . description } < / t e x t a r e a >
2022-06-27 18:52:48 +02:00
< / d i v >
< / d i v >
2024-06-07 17:39:35 +02:00
< div class = "row mb-3 d-none" >
2022-06-27 18:52:48 +02:00
< div class = "col" >
2024-06-07 17:39:35 +02:00
< div class = "form-field" title = "${this.getLabel(" min _occurs _help ")}" >
2022-06-27 18:52:48 +02:00
< input value = "${this.#output.minOccurs}" type = "number" min = "0" step = "1" name = "minOccurs" class = "form-control" placeholder = "minOccurs" / >
< / d i v >
< / d i v >
< div class = "col" >
2024-06-07 17:39:35 +02:00
< div class = "form-field" title = "${this.getLabel(" max _occurs _help ")}" >
2022-06-27 18:52:48 +02:00
< input value = "${this.#output.maxOccurs}" type = "number" min = "0" step = "1" name = "maxOccurs" class = "form-control" placeholder = "maxOccurs" / >
< / d i v >
< / d i v >
< / d i v >
< div class = "row mb-3" >
2024-06-07 17:39:35 +02:00
< div class = "col d-none" >
2022-07-18 18:08:53 +02:00
< div class = "form-field" title = "Type" >
2022-06-27 18:52:48 +02:00
< select name = "type" class = "form-control" placeholder = "type" >
< option value = "string" > String < / o p t i o n >
< / s e l e c t >
< / d i v >
< / d i v >
2022-09-13 15:12:26 +02:00
< div class = "col-3" >
2024-06-07 17:39:35 +02:00
< div class = "form-field" title = "${this.getLabel(" mimetype _help ")}" >
2022-06-27 18:52:48 +02:00
< input value = "${this.#output.schema.contentMediaType}" name = "contentMediaType" class = "form-control" placeholder = "mime" / >
< / d i v >
< / d i v >
2022-09-13 15:12:26 +02:00
$ { this . renderMetadata ( ) }
2022-06-27 18:52:48 +02:00
< / d i v >
< / d i v >
< / d e t a i l s >
`
2022-09-13 15:12:26 +02:00
this . addEventListener ( "input" , ev => {
const val = ev . target . value
const ename = ev . target . getAttribute ( "name" )
if ( ename === "id" ) {
this . # output . id = val
}
else if ( ename === "title" ) {
this . # output . title = val
}
else if ( ename === "description" ) {
this . # output . description = val
}
else if ( ename === "minOccurs" ) {
this . # output . minOccurs = val
}
else if ( ename === "maxOccurs" ) {
this . # output . maxOccurs = val
}
else if ( ename === "contentMediaType" ) {
this . # output . schema . contentMediaType = val
}
else if ( ename === "href" ) {
this . # output . metadata [ 0 ] . href = val
this . # output . metadata [ 0 ] . title = val
}
} )
}
renderMetadata ( output ) {
if ( this . # output . metadata && this . # output . metadata . length > 0 ) {
return `
< div class = "col" >
2024-06-07 17:39:35 +02:00
< div class = "form-field" title = "${this.getLabel(" file _path _help ")}" >
< input value = "${this.#output.metadata[0].href}" name = "href" class = "form-control" placeholder = "${this.getLabel(" file _path ")}" / >
2022-09-13 15:12:26 +02:00
< / d i v >
< / d i v >
`
} else return ""
2022-06-27 18:52:48 +02:00
}
}
window . customElements . define ( 'd4s-ccp-output-editor' , CCPOutputWidgetEditorController ) ;