forked from pkp/ui-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
177 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<template> | ||
<SideModalBody> | ||
<template #pre-title> | ||
{{ props.submissionId }} | ||
</template> | ||
<template #title> | ||
{{ t('submission.list.changeSubmissionLanguage.title') }} | ||
</template> | ||
<template #description> | ||
{{ store.publicationTitle }} | ||
</template> | ||
<div class="p-4"> | ||
<div class="bg-secondary p-4"> | ||
<div id="changeSubmissionLanguage" aria-live="polite"> | ||
<PkpForm | ||
v-bind="store.form" | ||
@set="store.set" | ||
@success="store.success" | ||
@cancel="store.closeSideModal" | ||
></PkpForm> | ||
</div> | ||
</div> | ||
</div> | ||
</SideModalBody> | ||
</template> | ||
|
||
<script setup> | ||
import {defineProps} from 'vue'; | ||
import PkpForm from '@/components/Form/Form.vue'; | ||
import SideModalBody from '@/components/Modal/SideModalBody.vue'; | ||
import {useChangeSubmissionLanguageStore} from '@/pages/workflow/changeSubmissionLanguageStore'; | ||
const props = defineProps({ | ||
form: { | ||
type: Object, | ||
required: true, | ||
}, | ||
submissionId: { | ||
type: Number, | ||
required: true, | ||
}, | ||
}); | ||
const store = useChangeSubmissionLanguageStore({ | ||
form: props.form, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {inject} from 'vue'; | ||
import {defineComponentStore} from '@/utils/defineComponentStore'; | ||
import {useForm} from '@/composables/useForm'; | ||
import cloneDeep from 'clone-deep'; | ||
|
||
export const useChangeSubmissionLanguageStore = defineComponentStore( | ||
'changeSubmissionLanguage', | ||
(props) => { | ||
/** | ||
* Variables | ||
*/ | ||
|
||
const { | ||
form: {value: form}, | ||
setValue, | ||
} = useForm(cloneDeep(props.form)); | ||
|
||
const publicationTitle = | ||
props.form.fields[2].value[props.form.primaryLocale]; | ||
|
||
// Get multilingual props | ||
const formMProps = form.fields.reduce((pp, f) => { | ||
if (f.isMultilingual) { | ||
pp[f.name] = f.value; | ||
} | ||
return pp; | ||
}, {}); | ||
|
||
const closeModal = inject('closeModal'); | ||
|
||
/** | ||
* Make form monolingual | ||
*/ | ||
form.fields.forEach((f) => { | ||
if (f.isMultilingual) { | ||
f.isMultilingual = false; | ||
f.value = f.value[form.primaryLocale]; | ||
} | ||
}); | ||
|
||
/** | ||
* Functions | ||
*/ | ||
|
||
function closeSideModal() { | ||
closeModal(); | ||
} | ||
|
||
/** | ||
* Set form data | ||
*/ | ||
const set = (_, data) => { | ||
Object.keys(data).forEach((key) => (form[key] = data[key])); | ||
const oldLocale = form.primaryLocale; | ||
const newLocale = data.fields?.[0].value ?? oldLocale; | ||
// Set multilingual form fields when changing language | ||
if (newLocale !== oldLocale) { | ||
form.primaryLocale = newLocale; | ||
form.fields.forEach((f) => { | ||
if (formMProps[f.name]) { | ||
setValue(f.name, formMProps[f.name][newLocale]); | ||
// i18n.js t doesn't seem to support variable as tranlation key | ||
// (i18nExtractKeys.vite.js: uiLocaleKeysBackend.json), using str.replace for now. | ||
f.description = f.description.replace( | ||
getLocaleName(oldLocale), | ||
getLocaleName(newLocale), | ||
); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Change submission language | ||
*/ | ||
const success = () => { | ||
//location.reload(); | ||
}; | ||
|
||
return {closeSideModal, set, success, form, publicationTitle}; | ||
|
||
/** | ||
* Aux functions | ||
*/ | ||
|
||
function getLocaleName(locale) { | ||
return form.fields[0].options.find(({value}) => value === locale).label; | ||
} | ||
}, | ||
); |