Skip to content

Commit 2ba0c9f

Browse files
committed
supportedFormLocales; refactoring
1 parent b943488 commit 2ba0c9f

File tree

2 files changed

+58
-38
lines changed

2 files changed

+58
-38
lines changed

src/components/Form/fields/FieldAffiliations.vue

+49-38
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<TableCell>
2525
<span class="text-lg-semibold">
2626
{{
27-
row.name[currentLocale]
28-
? row.name[currentLocale]
27+
row.name[primaryLocale]
28+
? row.name[primaryLocale]
2929
: getAlternativeDisplayName(row.name)
3030
}}
3131
</span>
@@ -50,7 +50,7 @@
5050
>
5151
<div>
5252
<label
53-
v-if="supportedLocales.includes(localeName)"
53+
v-if="supportedFormLocalesKeys.includes(localeName)"
5454
:for="
5555
'contributors-affiliations-' +
5656
indexRow +
@@ -71,7 +71,7 @@
7171
</div>
7272
<div>
7373
<input
74-
v-if="supportedLocales.includes(localeName)"
74+
v-if="supportedFormLocalesKeys.includes(localeName)"
7575
:id="
7676
'contributors-affiliations-' +
7777
indexRow +
@@ -83,7 +83,7 @@
8383
class="pkpFormField__input pkpFormField--text__input"
8484
type="text"
8585
name="searchPhraseInput"
86-
aria-invalid="0"
86+
aria-invalid="false"
8787
/>
8888
</div>
8989
</div>
@@ -131,7 +131,7 @@
131131
class="pkpFormField__input pkpFormField--text__input"
132132
type="text"
133133
name="affiliationsSearchPhraseInput"
134-
aria-invalid="0"
134+
aria-invalid="false"
135135
@keyup="searchPhraseChanged"
136136
/>
137137
&nbsp;
@@ -158,8 +158,8 @@
158158
@click="selectRorOrganization(organization)"
159159
>
160160
{{
161-
organization.name[currentLocale]
162-
? organization.name[currentLocale]
161+
organization.name[primaryLocale]
162+
? organization.name[primaryLocale]
163163
: organization.name[organization.displayLocale] +
164164
' [' +
165165
getLocaleDisplayName(organization.displayLocale) +
@@ -203,7 +203,7 @@
203203
>
204204
<div>
205205
<span
206-
v-if="supportedLocales.includes(localeAddMode)"
206+
v-if="supportedFormLocalesKeys.includes(localeAddMode)"
207207
class="text-lg-normal"
208208
>
209209
{{
@@ -218,7 +218,7 @@
218218
</div>
219219
<div>
220220
<input
221-
v-if="supportedLocales.includes(localeAddMode)"
221+
v-if="supportedFormLocalesKeys.includes(localeAddMode)"
222222
:id="
223223
'contributors-affiliations-newAffiliation' +
224224
'-' +
@@ -229,7 +229,7 @@
229229
class="pkpFormField__input pkpFormField--text__input"
230230
type="text"
231231
name="affiliationsNewAffiliationPendingInput"
232-
aria-invalid="0"
232+
aria-invalid="false"
233233
/>
234234
</div>
235235
</div>
@@ -275,31 +275,44 @@ import {useFetch} from '@/composables/useFetch';
275275
import {useModal} from '@/composables/useModal';
276276
277277
const props = defineProps({
278-
currentLocale: {type: String, default: 'en'},
279-
supportedLocales: {type: Object, default: () => {}},
280-
localeDisplayNames: {type: Object, default: () => {}},
281-
value: {type: Array, default: () => []},
282-
authorId: {type: Number, default: null},
278+
authorId: {
279+
type: Number,
280+
default: null,
281+
},
282+
primaryLocale: {
283+
type: String,
284+
default: 'en',
285+
},
286+
supportedFormLocales: {
287+
type: Array,
288+
default: () => {},
289+
},
290+
value: {
291+
type: Array,
292+
default: () => [],
293+
},
283294
});
284295
285-
const localeDisplayNames = props.localeDisplayNames;
286-
const currentLocale = props.currentLocale;
287-
const supportedLocales = props.supportedLocales;
288-
const currentValue = props.value;
289296
const authorId = props.authorId;
297+
const primaryLocale = props.primaryLocale;
298+
const supportedFormLocales = props.supportedFormLocales;
299+
const supportedFormLocalesKeys = supportedFormLocales.map(function (language) {
300+
return language.key;
301+
});
302+
const currentValue = props.value;
290303
const apiResponse = ref([]);
291304
const newAffiliationPending = ref({});
292305
const searchPhrase = ref('');
293306
294307
const selectCustomOrganization = function () {
295308
newAffiliationPending.value = getNewItemTemplate();
296-
newAffiliationPending.value.name[currentLocale] = searchPhrase.value;
309+
newAffiliationPending.value.name[primaryLocale] = searchPhrase.value;
297310
apiResponse.value = [];
298311
};
299312
const selectRorOrganization = function (item) {
300313
newAffiliationPending.value = getNewItemTemplate();
301314
newAffiliationPending.value.ror = item.ror;
302-
supportedLocales.forEach((locale) => {
315+
supportedFormLocalesKeys.forEach((locale) => {
303316
if (typeof item.name[locale] !== 'undefined') {
304317
newAffiliationPending.value.name[locale] = item.name[locale];
305318
}
@@ -320,7 +333,7 @@ const deleteAffiliation = function (index) {
320333
name: 'sendAuthorEmail',
321334
title: t('user.affiliations.deleteModal.title', {}),
322335
message: t('user.affiliations.deleteModal.message', {
323-
institution: currentValue[index]['name'][currentLocale],
336+
institution: currentValue[index]['name'][primaryLocale],
324337
}),
325338
actions: [
326339
{
@@ -407,11 +420,11 @@ const closeEditMode = function () {
407420
};
408421
const translations = function (row) {
409422
let names = row.name;
410-
let total = supportedLocales.length;
423+
let total = supportedFormLocalesKeys.length;
411424
let translated = 0;
412425
413426
for (let key in names) {
414-
if (supportedLocales.includes(key) && names[key].length > 0) {
427+
if (supportedFormLocalesKeys.includes(key) && names[key].length > 0) {
415428
translated++;
416429
}
417430
}
@@ -444,7 +457,7 @@ async function searchPhraseChanged() {
444457
445458
if (searchPhrase.value.length >= 3) {
446459
const {apiUrl} = useApiUrl(`rors/?searchPhrase=${searchPhrase.value}`);
447-
const {data, isSuccess, fetch} = useFetch(apiUrl, {method: 'GET'});
460+
const {data, isSuccess, fetch} = useFetch(apiUrl.value, {method: 'GET'});
448461
449462
await fetch();
450463
@@ -461,7 +474,7 @@ async function searchPhraseChanged() {
461474
462475
function makeCurrentValueCompatible() {
463476
Object.keys(currentValue).forEach((index) => {
464-
supportedLocales.forEach((locale) => {
477+
supportedFormLocalesKeys.forEach((locale) => {
465478
if (!(locale in currentValue[index].name)) {
466479
currentValue[index].name[locale] = '';
467480
}
@@ -477,24 +490,22 @@ function getNewItemTemplate() {
477490
name: {},
478491
};
479492
480-
supportedLocales.forEach((locale) => {
493+
supportedFormLocalesKeys.forEach((locale) => {
481494
newItem.name[locale] = '';
482495
});
483496
484497
return newItem;
485498
}
486499
487500
function getLocaleDisplayName(locale) {
488-
return typeof localeDisplayNames[locale] !== 'undefined'
489-
? localeDisplayNames[locale]
490-
: locale;
491-
492-
// Gives sometimes errors
493-
// if (typeof Intl === 'undefined') {
494-
// return locale;
495-
// }
496-
// const localeNames = new Intl.DisplayNames([currentLocale], {type: 'language'});
497-
// return localeNames.of(locale.replace('_', '-'));
501+
let displayName = locale;
502+
supportedFormLocales.forEach((language) => {
503+
if (language['key'] === locale) {
504+
displayName = language['label'];
505+
}
506+
});
507+
508+
return displayName;
498509
}
499510
500511
function getAlternativeDisplayName(names) {

src/components/ListPanel/contributors/ContributorsListPanel.vue

+9
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@ export default {
294294
let activeForm = cloneDeep(this.form);
295295
activeForm.action = this.contributorsApiUrl;
296296
activeForm.method = 'POST';
297+
activeForm.fields = activeForm.fields.map((field) => {
298+
if (field.name === 'affiliations') {
299+
field.primaryLocale = activeForm.primaryLocale;
300+
field.supportedFormLocales = activeForm.supportedFormLocales;
301+
}
302+
return field;
303+
});
297304
this.activeForm = activeForm;
298305
this.activeFormTitle = this.t('grid.action.addContributor');
299306
const {openSideModal} = useModal();
@@ -396,6 +403,8 @@ export default {
396403
author['orcidVerificationRequested'];
397404
} else if (field.name === 'affiliations') {
398405
field.authorId = author['id'];
406+
field.primaryLocale = activeForm.primaryLocale;
407+
field.supportedFormLocales = activeForm.supportedFormLocales;
399408
field.value = author[field.name];
400409
} else if (Object.keys(author).includes(field.name)) {
401410
field.value = author[field.name];

0 commit comments

Comments
 (0)