Skip to content

Commit

Permalink
Change submission language
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhein committed Nov 15, 2023
1 parent d1d7930 commit 3a7ae36
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
111 changes: 111 additions & 0 deletions src/components/Container/WorkflowPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default {
return {
activityLogLabel: '',
canAccessPublication: false,
canChangeLang: false,
canEditPublication: false,
currentPublication: null,
decisionUrl: '',
Expand All @@ -41,6 +42,7 @@ export default {
submissionFileApiUrl: '',
submissionLibraryLabel: '',
submissionLibraryUrl: '',
submissionSupportedLocales: [],
supportsReferences: false,
statusLabel: '',
unpublishConfirmLabel: '',
Expand All @@ -55,6 +57,7 @@ export default {
workingPublication: null,
isModalOpenedSelectRevisionDecision: false,
isModalOpenedSelectRevisionRecommendation: false,
isModalOpenedChangeSubmissionLanguage: false,
};
},
computed: {
Expand Down Expand Up @@ -104,6 +107,78 @@ export default {
},
},
methods: {
/**
* Change submission language and update contributor props
*/
async changeSubmissionLanguage() {
const oldLocale = this.submission.locale;
const newLocale =
this.components[pkp.const.FORM_CHANGE_SUBMISSION_LANGUAGE_METADATA]
.primaryLocale;
const self = this;
return editContributors().then(
submitLang().then(() => {
this.isModalOpenedChangeSubmissionLanguage = false;
}, $.noop),
$.noop,
);
async function editContributors() {
if (newLocale === oldLocale) return;
return $.when(
...self.workingPublication.authors.map((author) => {
return send(
`${self.submissionApiUrl}/publications/${self.workingPublication.id}/contributors/${author.id}`,
edit(author),
);
}),
);
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}, (r) =>
pkp.eventBus.$emit(
'form-success',
pkp.const.FORM_CHANGE_SUBMISSION_LANGUAGE,
r,
),
);
}
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);
},
});
}
},
/**
* Create a new version of the latest publication
*/
Expand Down Expand Up @@ -509,6 +584,24 @@ export default {
});
},
/**
* Update change submission language metadata form data, and at start add footer element with text
*/
updateSubmissionLangMetadataFormData(formId, data) {
this.set(formId, data);
const form = this.components[formId];
const oldLocale = form.primaryLocale;
const newLocale = data.fields ? data.fields[0].value : oldLocale;
if (newLocale === oldLocale) return;
form.primaryLocale = newLocale;
form.visibleLocales = [newLocale];
Object.keys(data).forEach(function (key) {
form[key] = data[key];
});
},
/**
* Update a publication
*
Expand Down Expand Up @@ -556,6 +649,10 @@ export default {
this.submission.currentPublicationId = newPublication.id;
this.refreshSubmission();
}
if (formId === pkp.const.FORM_CHANGE_SUBMISSION_LANGUAGE) {
window.location.reload();
}
});
/**
Expand Down Expand Up @@ -720,9 +817,23 @@ export default {
}
}
.pkpSubmission__localeNotSupported {
margin: 0 -2rem;
padding: 1rem;
background: @primary;
font-size: @font-sml;
color: #fff;
text-align: center;
}
// Integrate the grids in the publication tab
.pkpWorkflow__contributors,
#representations-grid {
padding-top: 2rem;
}
// Hide formlocales of change language metadata form
#changeSubmissionLanguage form .pkpFormLocales {
display: none;
}
</style>
6 changes: 5 additions & 1 deletion src/components/Container/WorkflowPageOMP.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
const $chaptersEl = $(this.$refs.chapters);
const sourceUrl = this.chaptersGridUrl.replace(
'__publicationId__',
publication.id
publication.id,
);
if (!$.pkp.classes.Handler.hasHandler($chaptersEl)) {
$chaptersEl.pkpHandler('$.pkp.controllers.UrlInDivHandler', {
Expand All @@ -61,9 +61,13 @@ export default {
/**
* Update the work type to be an edited volume
* Update authors' isVolumeEditor to bool if null
*/
setAsEditedVolume() {
this.updateWorkType(this.getConstant('WORK_TYPE_EDITED_VOLUME'));
this.workingPublication.authors.forEach(
(author) => (author.isVolumeEditor = !!author.isVolumeEditor),
);
},
/**
Expand Down
3 changes: 3 additions & 0 deletions src/components/Form/FormPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ export default {
if (typeof group.showWhen === 'string') {
return !!whenField.value;
}
if (Array.isArray(group.showWhen[1])) {
return group.showWhen[1].includes(whenField.value);
}
return whenField.value === group.showWhen[1];
},
Expand Down
1 change: 1 addition & 0 deletions src/docs/components/WorkflowPage/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This is a root component. Learn about [page hydration](#/pages/pages).
| `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. |
Expand Down

0 comments on commit 3a7ae36

Please sign in to comment.