scinote-web/app/javascript/vue/shared/share_modal.vue

117 lines
4.3 KiB
Vue
Raw Normal View History

2024-01-06 01:58:12 +08:00
<template>
<div ref="modal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="sn-icon sn-icon-close"></i>
</button>
<h4 class="modal-title truncate !block">
{{ i18n.t('modal_share.title', {object_name: object.name }) }}
2024-01-06 01:58:12 +08:00
</h4>
</div>
<div class="modal-body">
<div class="grid grid-cols-3 gap-2">
<div class="col-span-2">
{{ i18n.t("modal_share.share_with_team") }}
2024-01-06 01:58:12 +08:00
</div>
<div class="text-center">
{{ i18n.t("modal_share.can_edit") }}
2024-01-06 01:58:12 +08:00
</div>
<div v-if="globalShareEnabled" class="col-span-2 flex items-center h-9 gap-1">
2024-01-06 01:58:12 +08:00
<span class="sci-checkbox-container">
<input type="checkbox" class="sci-checkbox" v-model="sharedWithAllRead" />
<span class="sci-checkbox-label"></span>
</span>
{{ i18n.t("modal_share.all_teams") }}
2024-01-06 01:58:12 +08:00
</div>
<div v-if="globalShareEnabled" class="flex justify-center items-center">
2024-01-06 01:58:12 +08:00
<span v-if="sharedWithAllRead" class="sci-toggle-checkbox-container">
<input type="checkbox"
class="sci-toggle-checkbox"
:disabled="!object.shareable_write"
2024-01-06 01:58:12 +08:00
v-model="sharedWithAllWrite" />
<span class="sci-toggle-checkbox-label"></span>
</span>
</div>
<template v-for="team in shareableTeams">
<div class="col-span-2 flex items-center h-9 gap-1">
<span class="sci-checkbox-container" :class="{'opacity-0 pointer-events-none': sharedWithAllRead}">
<input type="checkbox" class="sci-checkbox" v-model="team.attributes.private_shared_with" />
<span class="sci-checkbox-label"></span>
</span>
{{ team.attributes.name }}
</div>
<div class="flex justify-center items-center">
<span v-if="team.attributes.private_shared_with"
:class="{'opacity-0 pointer-events-none': sharedWithAllRead}"
class="sci-toggle-checkbox-container">
<input type="checkbox"
class="sci-toggle-checkbox"
:disabled="!object.shareable_write"
2024-01-06 01:58:12 +08:00
v-model="team.attributes.private_shared_with_write" />
<span class="sci-toggle-checkbox-label"></span>
</span>
</div>
</template>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{ i18n.t('general.cancel') }}</button>
<button class="btn btn-primary" @click="submit" type="submit">
{{ i18n.t('modal_share.submit') }}
2024-01-06 01:58:12 +08:00
</button>
</div>
</div>
</div>
</div>
</template>
<script>
/* global HelperModule */
import axios from '../../packs/custom_axios.js';
import modalMixin from './modal_mixin';
2024-01-06 01:58:12 +08:00
export default {
name: 'ShareObjectModal',
2024-01-06 01:58:12 +08:00
props: {
object: Object,
globalShareEnabled: { type: Boolean, default: false }
2024-01-06 01:58:12 +08:00
},
mixins: [modalMixin],
data() {
return {
sharedWithAllRead: this.object.shared_read || this.object.shared_write,
sharedWithAllWrite: this.object.shared_write,
2024-01-06 01:58:12 +08:00
shareableTeams: [],
permission_changes: {}
};
},
mounted() {
this.getTeams();
},
methods: {
getTeams() {
axios.get(this.object.urls.shareable_teams).then((response) => {
2024-01-06 01:58:12 +08:00
this.shareableTeams = response.data.data;
});
},
submit() {
const data = {
select_all_teams: this.sharedWithAllRead,
select_all_write_permission: this.sharedWithAllWrite,
team_share_params: this.shareableTeams.map((team) => { return { id: team.id, ...team.attributes } })
2024-01-06 01:58:12 +08:00
};
axios.post(this.object.urls.share, data).then(() => {
2024-01-06 01:58:12 +08:00
HelperModule.flashAlertMsg(this.i18n.t(
'modal_share.success_message',
{ object_name: this.object.name }
2024-01-06 01:58:12 +08:00
), 'success');
this.$emit('share');
});
}
}
};
</script>