-
Notifications
You must be signed in to change notification settings - Fork 47
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
5 changed files
with
252 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<template> | ||
<p>{{ t('submission.list.changeLangDescription') }}</p> | ||
<div class="pkpPublication" aria-live="polite"> | ||
<pkp-form | ||
v-bind="form" | ||
@set="updateFormData" | ||
@success="changeLanguage" | ||
></pkp-form> | ||
</div> | ||
</template> | ||
|
||
<script type="text/javascript"> | ||
import PkpForm from '@/components/Form/Form.vue'; | ||
import ajaxError from '@/mixins/ajaxError'; | ||
export default { | ||
name: 'ChangeSubmissionLanguage', | ||
components: { | ||
PkpForm, | ||
}, | ||
mixins: [ajaxError], | ||
props: { | ||
contributors: { | ||
type: Array, | ||
required: true, | ||
}, | ||
contributorsApiUrl: { | ||
type: String, | ||
required: true, | ||
}, | ||
form: { | ||
type: Object, | ||
required: true, | ||
}, | ||
submissionApiUrl: { | ||
type: String, | ||
required: true, | ||
}, | ||
submissionLocale: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
emits: ['set', 'updated:contributors', 'updated:locale'], | ||
data() { | ||
return { | ||
isSubmit: false, | ||
}; | ||
}, | ||
methods: { | ||
/** | ||
* Change submission language and update contributor props | ||
*/ | ||
async changeLanguage() { | ||
const oldLocale = this.submissionLocale; | ||
const newLocale = this.form.primaryLocale; | ||
if (newLocale === oldLocale) { | ||
return Promise.resolve(); | ||
} | ||
this.isSubmit = true; | ||
const self = this; | ||
return editContributors().then(submitLang(), $.noop); | ||
async function editContributors() { | ||
const editedContributors = self.contributors | ||
.map((a) => [a.id, edit(a)]) | ||
.filter((a) => Object.keys(a[1]).length > 0); | ||
if (editedContributors.length > 0) { | ||
return $.when( | ||
...editedContributors.map(([id, contributor]) => { | ||
return send(`${self.contributorsApiUrl}/${id}`, contributor); | ||
}), | ||
).then(() => { | ||
self.$emit( | ||
'updated:contributors', | ||
self.contributors.map((c) => | ||
Object.assign( | ||
c, | ||
editedContributors.find(([id]) => id === c.id)[1], | ||
), | ||
), | ||
); | ||
}); | ||
} | ||
return Promise.resolve(); | ||
function edit(author) { | ||
// Only edit if given name empty | ||
if (author['givenName'][newLocale] !== '') return {}; | ||
return ['givenName', 'familyName', 'preferredPublicName'].reduce( | ||
(editedProps, prop) => { | ||
if (author[prop][newLocale] === '') { | ||
editedProps[prop] = {[newLocale]: author[prop][oldLocale]}; | ||
} | ||
return editedProps; | ||
}, | ||
{}, | ||
); | ||
} | ||
} | ||
async function submitLang() { | ||
return send(self.submissionApiUrl, {locale: newLocale}, (_) => | ||
self.$emit('updated:locale', newLocale), | ||
); | ||
} | ||
async function send(url, data, success = $.noop) { | ||
return $.ajax({ | ||
url: url, | ||
method: 'POST', | ||
headers: { | ||
'X-Csrf-Token': pkp.currentUser.csrfToken, | ||
'X-Http-Method-Override': 'PUT', | ||
}, | ||
data: data, | ||
success(r) { | ||
success(r); | ||
}, | ||
error(r) { | ||
self.ajaxErrorCallback(r); | ||
}, | ||
}); | ||
} | ||
}, | ||
/** | ||
* Update form data | ||
*/ | ||
updateFormData(formId, data) { | ||
this.$emit('set', formId, data); | ||
const newLocale = data.fields?.[0].value ?? this.form.primaryLocale; | ||
if (newLocale !== this.form.primaryLocale && !this.isSubmit) { | ||
this.$emit('set', formId, { | ||
primaryLocale: newLocale, | ||
visibleLocales: [newLocale], | ||
}); | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> | ||
<style lang="less"> | ||
// Hide formlocales of change language metadata form | ||
#changeSubmissionLanguage form .pkpFormLocales { | ||
display: none; | ||
} | ||
</style> |
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,38 @@ | ||
## Data | ||
|
||
This is a root component. Learn about [page hydration](#/pages/pages). | ||
|
||
| Key | Description | | ||
| --- | --- | | ||
| `activityLogLabel` | Label for the activity log | | ||
| `canAccessPublication` | Can the current user access the publication details? Default: `false` | | ||
| `canEditPublication` | Can the current user edit the publication details? Default: `false` | | ||
| `components` | Key/value map of nested components, such as forms. | | ||
| `currentPublication` | The submission's current publication. | | ||
| `editorialHistoryUrl` | URL to get the activity log modal. | | ||
| `publicationFormIds` | Array containing all of the keys in `components` that match a publication form. These forms will be updated when changing versions. | | ||
| `publicationList` | Array containing the `id`, `datePublished`, `status` and `version` of every publication for this submission. | | ||
| `publicationTabsLabel` | Label for the publication details tabs. | | ||
| `publishLabel` | Label for the publish button. | | ||
| `publishUrl` | URL to get the publish modal. | | ||
| `representationsGridUrl` | URL to get the galley/publication formats grid. | | ||
| `schedulePublicationLabel` | Label for the schedule for publication button. | | ||
| `statusLabel` | Label for the working publication's current status. | | ||
| `submission` | Object containing details about this submission. | | ||
| `submissionApiUrl` | URL for the submissions REST API endpoint. | | ||
| `submissionLibraryLabel` | Label for the submission library button. | | ||
| `submissionLibraryUrl` | URL to get the submission library. | | ||
| `submissionSupportedLocales` | Array containing supported submission locale keys | | ||
| `supportsReferences` | Should the form for references be shown? | | ||
| `unpublishConfirmLabel` | Confirmation message before unpublishing a publication. | | ||
| `unpublishLabel` | Label for the unpublish button. | | ||
| `unscheduleConfirmLabel` | Confirmation message before scheduling for publication. | | ||
| `versionLabel` | Label for the current version. | | ||
| `versionConfirmMessage` | Confirmation message before creating a new version. | | ||
| `versionConfirmTitle` | Title of the confirmation modal before creating a new version. | | ||
| `workingPublication` | Object representing the working publication. This is the version that is currently being shown. | | ||
|
||
## Usage | ||
|
||
The `WorkflowPage` extends the [Page](#/component/Page) component. Use this app to show the submission workflow. | ||
|