Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
6e27a481
Commit
6e27a481
authored
5 years ago
by
Bekerle, Patrizio
Committed by
Reiter, Christoph
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Allow presetting of value
parent
0f3d9a69
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/person-select/src/person-select.js
+33
-0
33 additions, 0 deletions
packages/person-select/src/person-select.js
with
33 additions
and
0 deletions
packages/person-select/src/person-select.js
+
33
−
0
View file @
6e27a481
...
@@ -9,6 +9,7 @@ import {i18n} from './i18n.js';
...
@@ -9,6 +9,7 @@ import {i18n} from './i18n.js';
import
VPULitElementJQuery
from
'
vpu-common/vpu-lit-element-jquery
'
;
import
VPULitElementJQuery
from
'
vpu-common/vpu-lit-element-jquery
'
;
import
*
as
commonUtils
from
'
vpu-common/utils
'
;
import
*
as
commonUtils
from
'
vpu-common/utils
'
;
import
select2CSSPath
from
'
select2/dist/css/select2.min.css
'
;
import
select2CSSPath
from
'
select2/dist/css/select2.min.css
'
;
import
{
send
as
notify
}
from
"
vpu-common/notification
"
;
select2
(
window
,
$
);
select2
(
window
,
$
);
...
@@ -24,6 +25,7 @@ class PersonSelect extends VPULitElementJQuery {
...
@@ -24,6 +25,7 @@ class PersonSelect extends VPULitElementJQuery {
this
.
active
=
false
;
this
.
active
=
false
;
// For some reason using the same ID on the whole page twice breaks select2 (regardless if they are in different custom elements)
// For some reason using the same ID on the whole page twice breaks select2 (regardless if they are in different custom elements)
this
.
selectId
=
'
person-select-
'
+
commonUtils
.
makeId
(
24
);
this
.
selectId
=
'
person-select-
'
+
commonUtils
.
makeId
(
24
);
this
.
value
=
''
;
}
}
static
get
properties
()
{
static
get
properties
()
{
...
@@ -31,6 +33,7 @@ class PersonSelect extends VPULitElementJQuery {
...
@@ -31,6 +33,7 @@ class PersonSelect extends VPULitElementJQuery {
lang
:
{
type
:
String
},
lang
:
{
type
:
String
},
active
:
{
type
:
Boolean
,
attribute
:
false
},
active
:
{
type
:
Boolean
,
attribute
:
false
},
entryPointUrl
:
{
type
:
String
,
attribute
:
'
entry-point-url
'
},
entryPointUrl
:
{
type
:
String
,
attribute
:
'
entry-point-url
'
},
value
:
{
type
:
String
},
};
};
}
}
...
@@ -139,6 +142,36 @@ class PersonSelect extends VPULitElementJQuery {
...
@@ -139,6 +142,36 @@ class PersonSelect extends VPULitElementJQuery {
}));
}));
});
});
// preset a person
if
(
this
.
value
!==
''
)
{
const
apiUrl
=
this
.
entryPointUrl
+
this
.
value
;
fetch
(
apiUrl
,
{
headers
:
{
'
Content-Type
'
:
'
application/ld+json
'
,
'
Authorization
'
:
'
Bearer
'
+
window
.
VPUAuthToken
,
},
})
.
then
(
result
=>
{
if
(
!
result
.
ok
)
throw
result
;
return
result
.
json
();
})
.
then
((
person
)
=>
{
const
identifier
=
person
[
"
@id
"
];
const
option
=
new
Option
(
person
.
name
,
identifier
,
true
,
true
);
$this
.
attr
(
"
data-object
"
,
JSON
.
stringify
(
person
));
that
.
$select
.
append
(
option
).
trigger
(
'
change
'
);
// fire a change event
that
.
dispatchEvent
(
new
CustomEvent
(
'
change
'
,
{
detail
:
{
value
:
identifier
,
},
bubbles
:
true
}));
}).
catch
(()
=>
{});
}
return
this
.
$select
;
return
this
.
$select
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment