Skip to content

Commit b23eb6d

Browse files
authored
Merge pull request #30 from GaziYucel/stable-3_3_0
Update ror api to version 2 for ojs 3.3
2 parents f5c244a + 1ca67ac commit b23eb6d

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

templates/affiliation.tpl

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,41 @@
1515
fieldName: 'affiliation-ROR[]',
1616
allowSpaces: true,
1717
tagLimit: 1,
18-
tagSource: function (search, r) {ldelim}
19-
$.ajax({ldelim}
20-
url: 'https://api.ror.org/v1/organizations',
21-
dataType: 'json',
22-
cache: true,
23-
data: {ldelim}
24-
affiliation: search.term + '*'
25-
{rdelim},
26-
success:
27-
function (data) {ldelim}
28-
results = data.items;
18+
tagSource: function (search, r) {ldelim}
19+
$.ajax({ldelim}
20+
url: 'https://api.ror.org/v2/organizations',
21+
dataType: 'json',
22+
cache: true,
23+
data: {ldelim}
24+
query: search.term
25+
{rdelim},
26+
success:
27+
function (data) {ldelim}
28+
results = data.items;
2929
30-
r($.map(data.items, function (item) {ldelim}
31-
return {ldelim}
32-
label: item.organization.name,
33-
value: item.organization.name + ' [' + item.organization.id + ']'
34-
{rdelim}
35-
{rdelim}));
30+
r($.map(data.items, function (item) {ldelim}
31+
let names = {ldelim}{rdelim};
32+
const noLangCode = 'no_lang_code';
33+
const displayLocale =
34+
item.names?.find((i) => i.types.includes('ror_display'))?.lang !== null
35+
? item.names?.find((i) => i.types.includes('ror_display'))?.lang
36+
: noLangCode;
3637
37-
{rdelim}
38-
{rdelim});
39-
{rdelim},
38+
item.names?.forEach((name) => {ldelim}
39+
if (name.types.includes('label') || name.types.includes('ror_display')) {ldelim}
40+
const locale = name.lang !== null ? name.lang : noLangCode;
41+
names[locale] = name.value;
42+
{rdelim}
43+
{rdelim});
44+
45+
return {ldelim}
46+
label: names[displayLocale],
47+
value: names[displayLocale]
48+
{rdelim};
49+
{rdelim}));
50+
{rdelim}
51+
{rdelim});
52+
{rdelim},
4053
beforeTagAdded: function (event,ui) {ldelim}
4154
{rdelim},
4255
afterTagAdded: function (event, ui) {ldelim}

0 commit comments

Comments
 (0)