Skip to content

Commit

Permalink
pkp/pkp-lib#10571 WIP: add support for unrestricted templates
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Nov 20, 2024
1 parent cebea01 commit 7a28f83
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 33 deletions.
52 changes: 29 additions & 23 deletions src/components/Container/ManageEmailsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -350,35 +350,16 @@ export default {
this.currentTemplate = template;
const {openSideModal} = useModal();
this.$nextTick(() => {
// Remove use group field if current mailable does not support specifying user group access
if (!this.currentMailable.canAssignUserGroupToTemplates) {
this.currentTemplateForm.fields =
this.currentTemplateForm.value.fields.filter(
(field) => field.name !== 'userGroupIds',
);
} else {
const userGroupField = this.currentTemplateForm.fields.find(
(field) => field.name === 'userGroupIds',
);
userGroupField.assignableUserGroups =
this.currentMailable['assignableTemplateUserGroups'];
userGroupField.assignedUserGroupIds = this.currentTemplate
? this.currentTemplate['assignedUserGroupIds']
: [];
}
return openSideModal(EditTemplateModal, {
this.$nextTick(() =>
openSideModal(EditTemplateModal, {
title: this.currentTemplate
? t('manager.mailables.editTemplate')
: t('manager.emails.addEmail'),
currentTemplateForm: this.currentTemplateForm,
canAssignUserGroups:
this.currentMailable.canAssignUserGroupToTemplates,
onUpdateCurrentTemplateForm: this.updateCurrentTemplateForm,
onTemplateSaved: this.templateSaved,
});
});
}),
);
},
/**
Expand Down Expand Up @@ -428,6 +409,16 @@ export default {
});
}
// Remove user group fields if current mailable does not support specifying user group access
if (!this.currentMailable.canAssignUserGroupToTemplates) {
templateForm.fields = templateForm.fields.filter(
(field) => field.name !== 'userGroupIds',
);
templateForm.fields = templateForm.fields.filter(
(field) => field.name !== 'isUnrestricted',
);
}
templateForm.fields = templateForm.fields.map((field) => {
if (field.name === 'body') {
field.preparedContent = Object.keys(
Expand All @@ -440,6 +431,21 @@ export default {
};
});
}
if (field.name === 'userGroupIds') {
field.assignableUserGroups =
this.currentMailable['assignableTemplateUserGroups'];
field.assignedUserGroupIds =
this.currentTemplate['assignedUserGroupIds'] || [];
field.isUnrestricted =
this.currentTemplate['isUnrestricted'] || false;
}
if (field.name === 'isUnrestricted') {
field.isUnrestricted =
this.currentTemplate['isUnrestricted'] || false;
}
return field;
});
Expand Down
2 changes: 2 additions & 0 deletions src/components/Form/FormGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import FieldUpload from './fields/FieldUpload.vue';
import FieldSlider from './fields/FieldSlider.vue';
import FieldUploadImage from './fields/FieldUploadImage.vue';
import FieldEmailTemplateUserGroupSettings from './fields/FieldEmailTemplateUserGroupSettings.vue';
import FieldEmailTemplateUnrestricted from './fields/FieldEmailTemplateUnrestricted.vue';
import {shouldShowFieldWithinGroup} from './formHelpers';
Expand Down Expand Up @@ -111,6 +112,7 @@ export default {
FieldUpload,
FieldUploadImage,
FieldEmailTemplateUserGroupSettings,
FieldEmailTemplateUnrestricted,
},
props: {
id: String,
Expand Down
52 changes: 52 additions & 0 deletions src/components/Form/fields/FieldEmailTemplateUnrestricted.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<div class="mt-4">
<FormFieldLabel :label="label" />
<span class="mb-4 mt-4 flex gap-2 border-b border-b-light italic">
<input
ref="input"
v-model="currentValue"
class="col-span-1"
name="isUnrestricted"
type="checkbox"
/>
<label>
Mark as unrestricted
<sub>
Unrestricted templates will be accessible to all user groups
associated with this template
</sub>
</label>
</span>

<FormFieldLabel :label="label" />
</div>
</template>

<script>
import FieldBase from '@/components/Form/fields/FieldBase.vue';
import FormFieldLabel from '@/components/Form/FormFieldLabel.vue';
export default {
name: 'FieldEmailTemplateUnrestricted',
components: {FormFieldLabel},
extends: FieldBase,
props: {
isUnrestricted: {
type: Boolean,
},
},
data() {
return {};
},
computed: {},
created() {},
mounted() {
this.currentValue = this.isUnrestricted;
},
methods: {},
};
</script>

<style lang="less">
@import '../../../styles/_import';
</style>
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<template>
<div>
<div class="mt-4">
<FormFieldLabel :label="label" />
<template v-for="group in assignableUserGroups" :key="group.id">
<span class="flex gap-2">
<input
ref="input"
v-model="userGroupIds"
v-model="currentValue"
:value="group.id"
class="col-span-1"
name="userGroupIds"
type="checkbox"
@change="updateCurrentValue(group)"
/>
<label :for="group.id" class="col-span-1">{{ group.name }}</label>
</span>
Expand Down Expand Up @@ -46,14 +45,8 @@ export default {
computed: {},
created() {},
mounted() {
this.userGroupIds = this.assignedUserGroupIds;
this.currentValue = this.assignedUserGroupIds;
},
methods: {
updateCurrentValue(group) {
this.currentValue = this.userGroupIds;
},
},
};
</script>

Expand Down
1 change: 0 additions & 1 deletion src/pages/manageEmails/EditTemplateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import PkpForm from '@/components/Form/Form.vue';
defineProps({
title: {type: String, required: true},
currentTemplateForm: {required: true, type: Object},
canAssignUserGroups: {default: false, type: Boolean},
});
const emit = defineEmits(['updateCurrentTemplateForm', 'templateSaved']);
Expand Down

0 comments on commit 7a28f83

Please sign in to comment.