Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F12660394
field_type.single_reference.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
field_type.single_reference.js
View Options
var
Sealious
=
require
(
"sealious"
);
module
.
exports
=
new
Sealious
.
FieldType
({
name
:
"single_reference"
,
is_proper_value
:
function
(
accept
,
reject
,
context
,
params
,
new_value
){
var
resource_type
=
new
Sealious
.
ResourceType
(
params
.
resource_type
);
var
resource_id
;
if
(
typeof
new_value
===
"string"
){
resource_id
=
new_value
;
}
else
if
(
typeof
new_value
===
"object"
){
resource_id
=
new_value
.
id
;
}
var
action
=
new
Sealious
.
Action
([
"resources"
,
resource_type
.
name
,
resource_id
],
"show"
);
action
.
perform
(
context
).
then
(
accept
)
.
catch
({
type
:
"not_found"
},
(
error
)
=>
reject
(
error
));
},
encode
:
function
(
context
,
params
,
value_in_code
){
var
resource_id
;
if
(
typeof
value_in_code
===
"string"
){
resource_id
=
value_in_code
;
}
else
if
(
typeof
value_in_code
===
"object"
){
resource_id
=
value_in_code
.
id
;
}
return
resource_id
;
},
format
:
function
(
context
,
params
,
decoded_value
,
format_params
){
if
(
format_params
===
"expand"
){
if
(
decoded_value
===
undefined
){
return
undefined
;
}
var
resource_type
=
new
Sealious
.
ResourceType
(
params
.
resource_type
);
var
resource_id
=
decoded_value
;
var
action
=
new
Sealious
.
Action
([
"resources"
,
resource_type
.
name
,
resource_id
],
"show"
);
return
action
.
perform
(
context
);
}
else
{
return
decoded_value
;
}
}
})
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 28, 15:39 (5 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1086302
Default Alt Text
field_type.single_reference.js (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment