Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10352608
enum-multiple-sealious.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
enum-multiple-sealious.ts
View Options
import
{
FieldTypes
as
SealiousFieldTypes
}
from
"sealious"
;
import
{
Context
}
from
"koa"
;
import
{
ExtractedFieldInfo
}
from
"../../utils/extract-fields-from-collection.js"
;
import
{
CheckboxedListField
}
from
"./checkboxed-list.js"
;
import
{
FormControlContext
}
from
"../controls/form-control.js"
;
import
{
FormDataValue
}
from
"../form-types.js"
;
export
class
EnumMultipleSealious
<
Values
extends
string
,
>
extends
CheckboxedListField
<
boolean
,
Values
>
{
public
sealious_field
:
SealiousFieldTypes
.
EnumMultiple
<
Values
>
;
constructor
(
sealious_field
:
SealiousFieldTypes
.
EnumMultiple
<
Values
>
)
{
super
(
sealious_field
.
required
,
async
(
ctx
:
Context
)
=>
(
await
sealious_field
.
getAllowedValues
(
ctx
.
$context
)).
map
(
(
value
:
Values
)
=>
({
value
,
label
:
value
})
)
);
this
.
sealious_field
=
sealious_field
;
}
generateFieldDeclaration
(
field_info
:
ExtractedFieldInfo
,
vars
:
{
form_field_types
:
string
;
sealious_field
:
string
}
)
:
string
{
return
`new
${
vars
.
form_field_types
}
.
${
this
.
constructor
.
name
}
(
${
vars
.
sealious_field
}
)`
;
}
async
getSealiousCreateValue
(
fctx
:
FormControlContext
)
:
Promise
<
Values
[]
>
{
const
{
parsed
}
=
await
this
.
getParsedValue
(
fctx
.
ctx
,
fctx
.
data
.
raw_values
);
const
result
=
Object
.
entries
(
parsed
||
{})
.
filter
(([,
value
])
=>
value
==
"on"
)
.
map
(([
key
])
=>
key
as
Values
);
return
result
;
}
async
sealiousValueToForm
(
ctx
:
Context
,
sealious_value
:
Values
[]
|
null
)
:
Promise
<
FormDataValue
>
{
return
Object
.
fromEntries
(
(
sealious_value
||
[]).
map
((
key
)
=>
[
key
,
"on"
])
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sun, Nov 2, 17:29 (14 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1029174
Default Alt Text
enum-multiple-sealious.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment