Skip to content

Commit

Permalink
pkp/pkp-lib#10571 WIP: Allow admins and managers to assign user group…
Browse files Browse the repository at this point in the history
…s to email templates within a mailable
  • Loading branch information
taslangraham committed Nov 6, 2024
1 parent f6a05ec commit c46d9cc
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/components/Container/ManageEmailsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,35 @@ export default {
template = template || {};
this.currentTemplate = template;
const {openSideModal} = useModal();
this.$nextTick(() =>
openSideModal(EditTemplateModal, {
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.fileds.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['assignedUserGroupIds'];
}
return 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
2 changes: 2 additions & 0 deletions src/components/Form/FormGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import FieldTextarea from './fields/FieldTextarea.vue';
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 {shouldShowFieldWithinGroup} from './formHelpers';
Expand Down Expand Up @@ -109,6 +110,7 @@ export default {
FieldSlider,
FieldUpload,
FieldUploadImage,
FieldEmailTemplateUserGroupSettings,
},
props: {
id: String,
Expand Down
55 changes: 55 additions & 0 deletions src/components/Form/fields/FieldEmailTemplateUserGroupSettings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<template>
<div>
<FormFieldLabel :label="label" />
<template v-for="group in assignableUserGroups" :key="group.id">
<span class="grid grid-cols-2">
<input
ref="input"
v-model="userGroupIds"
: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>
</template>
</div>
</template>

<script>
import FieldBase from '@/components/Form/fields/FieldBase.vue';
import FormFieldLabel from '@/components/Form/FormFieldLabel.vue';
export default {
name: 'UserGroupIds',
components: {FormFieldLabel},
extends: FieldBase,
props: {
assignedUserGroupIds: {
type: Array,
required: true,
},
assignableUserGroups: {
type: Array,
required: true,
},
},
data() {
return {
userGroupIds: [],
};
},
computed: {},
watch: {
userGroupIds(newValue) {
this.currentValue = newValue; // Update currentValue whenever userGroupIds changes
},
},
mounted() {
this.userGroupIds = this.assignedUserGroupIds;
},
};
</script>
1 change: 1 addition & 0 deletions src/pages/manageEmails/EditTemplateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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 c46d9cc

Please sign in to comment.