mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-02 12:13:54 +01:00
Added calendars plugin and improved used part
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import repository from './repository'
|
||||
|
||||
export default {
|
||||
getUserCalendars() {
|
||||
return repository.get('/user-calendars/')
|
||||
},
|
||||
getUserCalendar(pk) {
|
||||
return repository.get(`/user-calendars/${pk}/`)
|
||||
},
|
||||
createUserCalendar(data) {
|
||||
return repository.post('/user-calendars/', data)
|
||||
},
|
||||
updateUserCalendar(pk, data) {
|
||||
return repository.put(`/user-calendars/${pk}/`, data)
|
||||
},
|
||||
deleteUserCalendar(pk) {
|
||||
return repository.delete(`/user-calendars/${pk}/`)
|
||||
},
|
||||
|
||||
getAccessRules(calendarPk) {
|
||||
return repository.get('/accessrules/')
|
||||
},
|
||||
createAccessRule(data) {
|
||||
return repository.post('/accessrules/', data)
|
||||
},
|
||||
updateAccessRule(ruleId, data) {
|
||||
return repository.put(`/accessrules/${ruleId}/`, data)
|
||||
},
|
||||
deleteAccessRule(ruleId) {
|
||||
return repository.delete(`/accessrules/${ruleId}/`)
|
||||
},
|
||||
|
||||
getUserCalendarEvents(calendarPk, params) {
|
||||
return repository.get(`/user-calendars/${calendarPk}/events/`, { params })
|
||||
},
|
||||
getUserEvent(calendarPk, eventId) {
|
||||
return repository.get(`/user-calendars/${calendarPk}/events/${eventId}/`)
|
||||
},
|
||||
createUserEvent(calendarPk, data) {
|
||||
return repository.post(`/user-calendars/${calendarPk}/events/`, data)
|
||||
},
|
||||
patchUserEvent(calendarPk, eventId, data) {
|
||||
return repository.patch(
|
||||
`/user-calendars/${calendarPk}/events/${eventId}/`,
|
||||
data
|
||||
)
|
||||
},
|
||||
importUserEvents(calendarPk, data) {
|
||||
return repository.post(
|
||||
`/user-calendars/${calendarPk}/events/import_from_file/`,
|
||||
data
|
||||
)
|
||||
},
|
||||
|
||||
getAttendees() {
|
||||
return repository.get('/attendees/')
|
||||
},
|
||||
}
|
||||
@@ -1,6 +1,15 @@
|
||||
import repository from './repository'
|
||||
|
||||
export default {
|
||||
getDefaultAddressBook() {
|
||||
return repository.get('/address-books/default/')
|
||||
},
|
||||
synchronizeToAddressBook() {
|
||||
return repository.get('/address-books/sync_to_cdav/')
|
||||
},
|
||||
synchronizeFromAddressBook() {
|
||||
return repository.get('/address-books/sync_from_cdav/')
|
||||
},
|
||||
getContacts(params) {
|
||||
return repository.get('/contacts/', { params })
|
||||
},
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import repository from './repository'
|
||||
|
||||
const resource = 'mailboxes'
|
||||
|
||||
export default {
|
||||
getAll() {
|
||||
return repository.get(`${resource}/`)
|
||||
},
|
||||
}
|
||||
@@ -3,16 +3,29 @@ import repository from './repository'
|
||||
const resource = 'parameters'
|
||||
|
||||
export default {
|
||||
getApplications() {
|
||||
return repository.get(`/${resource}/applications/`)
|
||||
getGlobalApplications() {
|
||||
return repository.get(`/${resource}/global/applications/`)
|
||||
},
|
||||
getApplication(app) {
|
||||
return repository.get(`/${resource}/${app}/`)
|
||||
getGlobalApplication(app) {
|
||||
return repository.get(`/${resource}/global/${app}/`)
|
||||
},
|
||||
getApplicationStructure(app) {
|
||||
return repository.get(`/${resource}/structure/?app=${app}`)
|
||||
getGlobalApplicationStructure(app) {
|
||||
return repository.get(`/${resource}/global/structure/?app=${app}`)
|
||||
},
|
||||
saveApplication(app, data) {
|
||||
return repository.put(`/${resource}/${app}/`, data)
|
||||
saveGlobalApplication(app, data) {
|
||||
return repository.put(`/${resource}/global/${app}/`, data)
|
||||
},
|
||||
|
||||
getUserApplications() {
|
||||
return repository.get(`/${resource}/user/applications/`)
|
||||
},
|
||||
getUserApplication(app) {
|
||||
return repository.get(`/${resource}/user/${app}/`)
|
||||
},
|
||||
getUserApplicationStructure(app) {
|
||||
return repository.get(`/${resource}/user/structure/?app=${app}`)
|
||||
},
|
||||
saveUserApplication(app, data) {
|
||||
return repository.put(`/${resource}/user/${app}/`, data)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ const domain = ref(defaultDomain)
|
||||
|
||||
onMounted(() => {
|
||||
//TODO : Store this in Pinia
|
||||
ParametersApi.getApplication('admin').then((resp) => {
|
||||
ParametersApi.getGlobalApplication('admin').then((resp) => {
|
||||
const params = resp.data.params
|
||||
domain.value.quota = params.default_domain_quota
|
||||
domain.value.default_mailbox_quota = params.default_mailbox_quota
|
||||
|
||||
@@ -261,7 +261,7 @@ async function save() {
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
parametersApi.getApplication('limits').then((resp) => {
|
||||
parametersApi.getGlobalApplication('limits').then((resp) => {
|
||||
limitsConfig.value.data = resp.data
|
||||
})
|
||||
})
|
||||
|
||||
@@ -316,7 +316,7 @@ onMounted(() => {
|
||||
.getAccount(route.params.id)
|
||||
.then((response) => (editedAccount.value = { ...response.data }))
|
||||
|
||||
parametersApi.getApplication('limits').then((response) => {
|
||||
parametersApi.getGlobalApplication('limits').then((response) => {
|
||||
limitsConfig.value = response.data
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="headline">{{ $gettext('Calendar sharing') }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-form ref="formRef" @submit.prevent="submit">
|
||||
<div class="d-flex">
|
||||
<v-select
|
||||
v-model="currentRule.mailbox"
|
||||
:label="$gettext('Full address')"
|
||||
:form-errors="formErrors['mailbox']"
|
||||
:items="mailboxes"
|
||||
item-title="full_address"
|
||||
return-object
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
/>
|
||||
<v-checkbox
|
||||
v-model="currentRule.read"
|
||||
:label="$gettext('Read')"
|
||||
class="ml-4"
|
||||
/>
|
||||
<v-checkbox
|
||||
v-model="currentRule.write"
|
||||
:label="$gettext('Write')"
|
||||
class="ml-4"
|
||||
/>
|
||||
<v-spacer />
|
||||
<v-btn
|
||||
color="primary"
|
||||
icon="mdi-content-save-outline"
|
||||
type="submit"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
</v-form>
|
||||
<br />
|
||||
<v-table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $gettext('Account') }}</th>
|
||||
<th>{{ $gettext('Read') }}</th>
|
||||
<th>{{ $gettext('Write') }}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="rule in accessRules" :key="rule.pk">
|
||||
<td>{{ rule.mailbox.full_address }}</td>
|
||||
<td>
|
||||
<v-icon :icon="rule.read ? 'mdi-check' : 'mdi-close'" />
|
||||
</td>
|
||||
<td>
|
||||
<v-icon :icon="rule.write ? 'mdi-check' : 'mdi-close'" />
|
||||
</td>
|
||||
<td>
|
||||
<v-btn
|
||||
icon="mdi-pencil"
|
||||
size="x-small"
|
||||
variant="flat"
|
||||
@click="editRule(rule)"
|
||||
/>
|
||||
<v-btn
|
||||
icon="mdi-trash-can"
|
||||
size="x-small"
|
||||
variant="flat"
|
||||
@click="deleteRule(rule)"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</v-table>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer />
|
||||
<v-btn @click="close">{{ $gettext('Close') }}</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import api from '@/api/calendars'
|
||||
import mailboxesApi from '@/api/mailboxes'
|
||||
|
||||
const props = defineProps({
|
||||
calendarPk: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
})
|
||||
const emit = defineEmits(['close'])
|
||||
|
||||
const accessRules = ref([])
|
||||
const mailboxes = ref([])
|
||||
const currentRule = ref({})
|
||||
const formErrors = ref({})
|
||||
|
||||
api.getAccessRules(props.calendarPk).then((response) => {
|
||||
accessRules.value = response.data
|
||||
if (!accessRules.value.length) {
|
||||
accessRules.value = []
|
||||
}
|
||||
})
|
||||
mailboxesApi.getAll().then((response) => {
|
||||
mailboxes.value = response.data
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (!currentRule.value.pk) {
|
||||
currentRule.value.calendar = props.calendarPk
|
||||
api.createAccessRule(currentRule.value).then((response) => {
|
||||
accessRules.value.push(response.data)
|
||||
resetForm()
|
||||
}, onError)
|
||||
} else {
|
||||
api.updateAccessRule(currentRule.value.pk, currentRule.value).then(() => {
|
||||
accessRules.value.filter((item, pos) => {
|
||||
if (item.pk === currentRule.value.pk) {
|
||||
accessRules.value[pos] = currentRule.value
|
||||
}
|
||||
})
|
||||
resetForm()
|
||||
}, onError)
|
||||
}
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
currentRule.value = {}
|
||||
formErrors.value = {}
|
||||
}
|
||||
function onError(response) {
|
||||
formErrors.value = response.data
|
||||
}
|
||||
function editRule(rule) {
|
||||
currentRule.value = JSON.parse(JSON.stringify(rule))
|
||||
}
|
||||
function deleteRule(rule) {
|
||||
api.deleteAccessRule(rule.pk).then(() => {
|
||||
accessRules.value = accessRules.value.filter((localRule) => {
|
||||
return localRule.pk !== rule.pk
|
||||
})
|
||||
})
|
||||
}
|
||||
function close() {
|
||||
formErrors.value = {}
|
||||
emit('close')
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,50 @@
|
||||
<template>
|
||||
<v-card v-if="calendar">
|
||||
<v-card-title>
|
||||
<span class="headline">{{ $gettext('Calendar information') }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<p>
|
||||
{{
|
||||
$gettext(
|
||||
'To access this calendar from the outside (such as Mozilla Thunderbird or your smartphone), use the following URL:'
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
<v-alert type="info" class="my-4" variant="tonal">
|
||||
{{ calendar.full_url }}
|
||||
</v-alert>
|
||||
<p>
|
||||
{{
|
||||
$gettext(
|
||||
'The credentials are the same than the ones you use to access Modoboa.'
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
<p>
|
||||
{{
|
||||
$gettext(
|
||||
'You can also share a read-only version of this calendar using the following URL: '
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
<v-alert type="info" class="my-4" variant="tonal">
|
||||
{{ calendar.share_url }}
|
||||
</v-alert>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer />
|
||||
<v-btn @click="$emit('close')">{{ $gettext('Close') }}</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
calendar: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
})
|
||||
const emit = defineEmits(['close'])
|
||||
</script>
|
||||
@@ -0,0 +1,111 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-form ref="formRef" @submit.prevent="submit">
|
||||
<v-card-title>
|
||||
<span v-if="calendar.pk" class="headline">{{
|
||||
$gettext('Edit calendar')
|
||||
}}</span>
|
||||
<span v-else class="modal-title">{{ $gettext('New calendar') }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text class="py-4">
|
||||
<v-row no-gutters>
|
||||
<v-col cols="12">
|
||||
<v-text-field
|
||||
v-model="calendar.name"
|
||||
:label="$gettext('Name')"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
:rules="[rules.required]"
|
||||
:error-messages="formErrors.name"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="12">
|
||||
<v-color-picker
|
||||
v-model="calendar.color"
|
||||
:label="$gettext('Color')"
|
||||
class="ma-2"
|
||||
swatches-max-height="200px"
|
||||
show-swatches
|
||||
hide-inputs
|
||||
:rules="[rules.required]"
|
||||
></v-color-picker>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer />
|
||||
<v-btn @click="close">{{ $gettext('Close') }}</v-btn>
|
||||
<v-btn color="primary" type="submit">
|
||||
{{ submitLabel }}
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-form>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useBusStore } from '@/stores'
|
||||
import rules from '@/plugins/rules'
|
||||
import calendarsApi from '@/api/calendars'
|
||||
|
||||
const emit = defineEmits(['close', 'colorChanged'])
|
||||
const props = defineProps({
|
||||
initialCalendar: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return { color: '' }
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const { $gettext } = useGettext()
|
||||
const busStore = useBusStore()
|
||||
|
||||
onMounted(() => {
|
||||
calendar.value = { ...props.initialCalendar }
|
||||
shared.value = props.initialCalendar.domain !== undefined
|
||||
})
|
||||
|
||||
const calendar = ref({})
|
||||
const shared = ref(false)
|
||||
const formErrors = ref({})
|
||||
const formRef = ref()
|
||||
|
||||
const submitLabel = computed(() => {
|
||||
if (calendar.value.pk) {
|
||||
return $gettext('Update')
|
||||
}
|
||||
return $gettext('Create')
|
||||
})
|
||||
|
||||
function close() {
|
||||
calendar.value = {}
|
||||
shared.value = false
|
||||
formErrors.value = {}
|
||||
emit('close')
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
const { valid } = await formRef.value.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
let msg
|
||||
if (calendar.value.pk) {
|
||||
await calendarsApi.updateUserCalendar(calendar.value.pk, calendar.value)
|
||||
msg = $gettext('Calendar updated')
|
||||
} else {
|
||||
await calendarsApi.createUserCalendar(calendar.value)
|
||||
msg = $gettext('Calendar created')
|
||||
}
|
||||
if (props.initialCalendar.color !== calendar.value.color) {
|
||||
emit('colorChanged', calendar.value)
|
||||
}
|
||||
close()
|
||||
busStore.displayNotification({
|
||||
msg,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,186 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-form ref="formRef" @submit.prevent="saveEvent">
|
||||
<v-card-title>
|
||||
<span class="headline">{{ title }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text class="py-4">
|
||||
<v-row class="mb-2">
|
||||
<v-col cols="12">
|
||||
<v-text-field
|
||||
v-model="form.title"
|
||||
:label="$gettext('Title')"
|
||||
:rules="[rules.required]"
|
||||
:error-messages="formErrors.title"
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<div class="d-flex mb-3">
|
||||
<v-icon icon="mdi-clock-outline" class="mr-4" />
|
||||
<v-text-field
|
||||
v-model="form.start"
|
||||
:label="$gettext('From')"
|
||||
:rules="[rules.required]"
|
||||
:error-messages="formErrors.start"
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
type="datetime-local"
|
||||
class="mr-4"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="form.end"
|
||||
:label="$gettext('To')"
|
||||
:rules="[rules.required]"
|
||||
:error-messages="formErrors.end"
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
type="datetime-local"
|
||||
/>
|
||||
</div>
|
||||
<div class="d-flex mb-3">
|
||||
<v-icon icon="mdi-calendar" class="mr-4" />
|
||||
<v-select
|
||||
v-model="form.calendar"
|
||||
:items="userCalendars"
|
||||
item-title="name"
|
||||
item-value="pk"
|
||||
:label="$gettext('Calendar')"
|
||||
:rules="[rules.required]"
|
||||
:error-messages="formErrors.calendar"
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
/>
|
||||
</div>
|
||||
<template v-if="event">
|
||||
<div class="d-flex mb-3">
|
||||
<v-icon icon="mdi-account-multiple-outline" class="mr-4" />
|
||||
<v-select
|
||||
v-model="form.attendees"
|
||||
:label="$gettext('Attendees')"
|
||||
:items="attendees"
|
||||
item-title="display_name"
|
||||
item-value="email"
|
||||
return-object
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
multiple
|
||||
chips
|
||||
/>
|
||||
</div>
|
||||
<v-textarea
|
||||
v-model="form.description"
|
||||
:label="$gettext('Description')"
|
||||
auto-grow
|
||||
rows="2"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
class="mb-3"
|
||||
/>
|
||||
</template>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer />
|
||||
<v-btn @click="close">{{ $gettext('Close') }}</v-btn>
|
||||
<v-btn color="primary" type="submit">
|
||||
{{ $gettext('Save') }}
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-form>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { DateTime } from 'luxon'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useBusStore } from '@/stores'
|
||||
import api from '@/api/calendars'
|
||||
import rules from '@/plugins/rules'
|
||||
|
||||
const props = defineProps({
|
||||
info: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
event: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
})
|
||||
const emit = defineEmits(['close'])
|
||||
|
||||
const { $gettext } = useGettext()
|
||||
const busStore = useBusStore()
|
||||
|
||||
const attendees = ref([])
|
||||
const userCalendars = ref([])
|
||||
const form = ref({})
|
||||
const formErrors = ref({})
|
||||
const formRef = ref()
|
||||
|
||||
const title = computed(() => {
|
||||
return props.event ? $gettext('Edit event') : $gettext('New event')
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.info,
|
||||
(value) => {
|
||||
if (value) {
|
||||
form.value = {
|
||||
start: DateTime.fromISO(value.startStr).toFormat('yyyy-MM-dd HH:mm'),
|
||||
end: DateTime.fromISO(value.endStr).toFormat('yyyy-MM-dd HH:mm'),
|
||||
allDay: value.allDay,
|
||||
}
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.event,
|
||||
(value) => {
|
||||
if (value) {
|
||||
form.value = { ...value }
|
||||
form.value.calendar = form.value.calendar.pk
|
||||
form.value.start = DateTime.fromISO(value.start).toFormat(
|
||||
'yyyy-MM-dd HH:mm'
|
||||
)
|
||||
form.value.end = DateTime.fromISO(value.end).toFormat('yyyy-MM-dd HH:mm')
|
||||
console.log(form.value)
|
||||
api.getAttendees().then((resp) => {
|
||||
attendees.value = resp.data
|
||||
})
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
function close() {
|
||||
formErrors.value = {}
|
||||
emit('close')
|
||||
}
|
||||
async function saveEvent() {
|
||||
const { valid } = await formRef.value.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
var data = JSON.parse(JSON.stringify(form.value))
|
||||
if (!props.event) {
|
||||
api.createUserEvent(form.value.calendar, data).then(() => {
|
||||
busStore.displayNotification({ msg: $gettext('Event added') })
|
||||
close()
|
||||
})
|
||||
} else {
|
||||
api.patchUserEvent(form.value.calendar, props.event.id, data).then(() => {
|
||||
busStore.displayNotification({ msg: $gettext('Event updated') })
|
||||
close()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
api.getUserCalendars().then((resp) => {
|
||||
userCalendars.value = resp.data
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,94 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-form ref="formRef" @submit.prevent="sendFile">
|
||||
<v-card-title>
|
||||
<span class="headline">{{ $gettext('Import events') }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-alert type="info" variant="tonal" class="my-4">
|
||||
{{
|
||||
$gettext(
|
||||
'Select an ICS file to import and click on the Send button'
|
||||
)
|
||||
}}
|
||||
</v-alert>
|
||||
<v-file-input
|
||||
v-model="file"
|
||||
:label="$gettext('Select an ICS file')"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
:rules="[rules.required]"
|
||||
:error-messages="formErrors['ics_file']"
|
||||
/>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer />
|
||||
<v-btn :disabled="runningUpload" @click="close">{{
|
||||
$gettext('Close')
|
||||
}}</v-btn>
|
||||
<v-btn type="submit" color="primary" :disabled="runningUpload">
|
||||
{{ $gettext('Send') }}
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-form>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useBusStore } from '@/stores'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import api from '@/api/calendars'
|
||||
import rules from '@/plugins/rules'
|
||||
|
||||
const props = defineProps({
|
||||
calendar: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
})
|
||||
const emit = defineEmits(['close', 'eventsImported'])
|
||||
|
||||
const { $ngettext } = useGettext()
|
||||
const busStore = useBusStore()
|
||||
|
||||
const file = ref(null)
|
||||
const formErrors = ref({})
|
||||
const formRef = ref()
|
||||
const runningUpload = ref(false)
|
||||
|
||||
function close() {
|
||||
formErrors.value = {}
|
||||
emit('close')
|
||||
}
|
||||
|
||||
function onSendError(response) {
|
||||
formErrors.value = response.data
|
||||
runningUpload.value = false
|
||||
}
|
||||
|
||||
async function sendFile() {
|
||||
const { valid } = await formRef.value.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
let data = new FormData()
|
||||
data.append('ics_file', file.value)
|
||||
runningUpload.value = true
|
||||
try {
|
||||
const response = await api.importUserEvents(props.calendar, data)
|
||||
close()
|
||||
var msg = $ngettext(
|
||||
'%{ n } event imported',
|
||||
'%{ n } events imported',
|
||||
response.data.counter
|
||||
)
|
||||
busStore.displayNotification({ msg })
|
||||
emit('eventsImported', props.calendar)
|
||||
} catch (err) {
|
||||
onSendError(err.response)
|
||||
} finally {
|
||||
runningUpload.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,40 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="headline">{{ $gettext('Address book information') }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<p>
|
||||
{{
|
||||
$gettext(
|
||||
'To access this address book from the outside (such as Mozilla Thunderbird or your smartphone), use the following URL:'
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
<v-alert type="info" class="my-4" variant="tonal">
|
||||
{{ addressBookUrl }}
|
||||
</v-alert>
|
||||
<p>
|
||||
{{
|
||||
$gettext(
|
||||
'The credentials are the same than the ones you use to access Modoboa.'
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer />
|
||||
<v-btn @click="$emit('close')">{{ $gettext('Close') }}</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
addressBookUrl: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
})
|
||||
const emit = defineEmits(['close'])
|
||||
</script>
|
||||
@@ -33,6 +33,7 @@
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useBusStore } from '@/stores'
|
||||
import contactsApi from '@/api/contacts'
|
||||
import rules from '@/plugins/rules'
|
||||
|
||||
@@ -42,10 +43,11 @@ const props = defineProps({
|
||||
default: null,
|
||||
},
|
||||
})
|
||||
const emit = defineEmits(['close', 'added', 'updated'])
|
||||
const emit = defineEmits(['close', 'updated'])
|
||||
|
||||
const router = useRouter()
|
||||
const { $gettext } = useGettext()
|
||||
const { displayNotification } = useBusStore()
|
||||
|
||||
const form = ref({})
|
||||
const formRef = ref()
|
||||
@@ -69,14 +71,12 @@ async function submit() {
|
||||
}
|
||||
working.value = true
|
||||
try {
|
||||
let resp
|
||||
if (props.category) {
|
||||
resp = await contactsApi.updateCategory(props.category.pk, form.value)
|
||||
emit('updated', resp.data)
|
||||
await contactsApi.updateCategory(props.category.pk, form.value)
|
||||
} else {
|
||||
resp = await contactsApi.addCategory(form.value)
|
||||
emit('added', resp.data)
|
||||
await contactsApi.addCategory(form.value)
|
||||
}
|
||||
emit('updated')
|
||||
emit('close')
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
@@ -88,6 +88,8 @@ async function submit() {
|
||||
function deleteCategory() {
|
||||
contactsApi.deleteCategory(props.category.pk).then(() => {
|
||||
close()
|
||||
emit('updated')
|
||||
displayNotification({ msg: $gettext('Category deleted') })
|
||||
router.push({ name: 'ContactList' })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -14,19 +14,24 @@
|
||||
density="compact"
|
||||
class="flex-grow-0 w-33 mr-4"
|
||||
></v-text-field>
|
||||
|
||||
<v-menu location="bottom">
|
||||
<template #activator>
|
||||
<v-btn
|
||||
color="primary"
|
||||
variant="outlined"
|
||||
@click="showForm = true"
|
||||
>
|
||||
{{ $gettext('Add') }}
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-list density="compact"> </v-list>
|
||||
</v-menu>
|
||||
<v-btn color="primary" variant="outlined" @click="showForm = true">
|
||||
{{ $gettext('Add') }}
|
||||
</v-btn>
|
||||
<template v-if="preferences.enable_carddav_sync">
|
||||
<v-btn
|
||||
icon="mdi-information-outline"
|
||||
:title="$gettext('Display address book information')"
|
||||
class="ml-2"
|
||||
@click="showAddressBookInfo = true"
|
||||
/>
|
||||
<v-btn
|
||||
v-if="!addressBook.last_sync"
|
||||
icon="mdi-sync"
|
||||
color="success"
|
||||
:title="$gettext('Synchronize contacts with address book')"
|
||||
@click="syncToAddressBook"
|
||||
/>
|
||||
</template>
|
||||
<v-chip
|
||||
v-if="$route.params.category"
|
||||
class="my-2 mx-4"
|
||||
@@ -75,13 +80,22 @@
|
||||
@close="closeCategoriesForm"
|
||||
/>
|
||||
</v-dialog>
|
||||
<v-dialog v-model="showAddressBookInfo" persistent max-width="800px">
|
||||
<AddressBookInfo
|
||||
:address-book-url="addressBook.url"
|
||||
@close="showAddressBookInfo = false"
|
||||
/>
|
||||
</v-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import { onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useBusStore } from '@/stores'
|
||||
import contactsApi from '@/api/contacts'
|
||||
import parametersApi from '@/api/parameters'
|
||||
import AddressBookInfo from './AddressBookInfo.vue'
|
||||
import ContactForm from './ContactForm.vue'
|
||||
import ContactCategoriesForm from './ContactCategoriesForm.vue'
|
||||
import MenuItems from '@/components/tools/MenuItems'
|
||||
@@ -90,12 +104,16 @@ const emit = defineEmits(['editCategory'])
|
||||
|
||||
const route = useRoute()
|
||||
const { $gettext } = useGettext()
|
||||
const { displayNotification } = useBusStore()
|
||||
|
||||
const addressBook = ref({})
|
||||
const contacts = ref([])
|
||||
const search = ref('')
|
||||
const selectedContact = ref(null)
|
||||
const showAddressBookInfo = ref(false)
|
||||
const showForm = ref(false)
|
||||
const showCategoriesForm = ref(false)
|
||||
const preferences = ref({})
|
||||
|
||||
const headers = [
|
||||
{ key: 'display_name', title: $gettext('Display name') },
|
||||
@@ -123,6 +141,12 @@ const contactActions = [
|
||||
},
|
||||
]
|
||||
|
||||
let intervalId
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (intervalId) clearInterval(intervalId)
|
||||
})
|
||||
|
||||
function closeForm() {
|
||||
showForm.value = false
|
||||
selectedContact.value = null
|
||||
@@ -152,7 +176,7 @@ function editCategories(contact) {
|
||||
|
||||
function closeCategoriesForm() {
|
||||
showCategoriesForm.value = false
|
||||
selectedContact.value = false
|
||||
selectedContact.value = null
|
||||
}
|
||||
|
||||
function deleteContact(contact) {
|
||||
@@ -167,8 +191,29 @@ function fetchContacts() {
|
||||
})
|
||||
}
|
||||
|
||||
function syncToAddressBook() {
|
||||
contactsApi.synchronizeToAddressBook().then(() => {
|
||||
displayNotification({ msg: $gettext('Synchronization started') })
|
||||
})
|
||||
}
|
||||
|
||||
contactsApi.getDefaultAddressBook().then((resp) => {
|
||||
addressBook.value = resp.data
|
||||
})
|
||||
parametersApi.getUserApplication('contacts').then((resp) => {
|
||||
preferences.value = resp.data.params
|
||||
})
|
||||
fetchContacts()
|
||||
|
||||
watch(preferences, (value) => {
|
||||
if (value) {
|
||||
intervalId = setInterval(
|
||||
contactsApi.synchronizeFromAddressBook,
|
||||
value.sync_frequency * 1000
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => route.params.category,
|
||||
() => {
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
errors: {
|
||||
type: Object,
|
||||
|
||||
@@ -61,13 +61,23 @@
|
||||
</v-list-item>
|
||||
</template>
|
||||
<template v-for="subitem in item.children" :key="subitem.text">
|
||||
<v-list-item
|
||||
v-if="displayMenuItem(subitem)"
|
||||
:to="subitem.to"
|
||||
link
|
||||
:title="subitem.text"
|
||||
:value="subitem"
|
||||
></v-list-item>
|
||||
<template v-if="displayMenuItem(subitem)">
|
||||
<v-list-item
|
||||
v-if="subitem.action"
|
||||
:title="subitem.text"
|
||||
:value="subitem"
|
||||
:prepend-icon="subitem.icon"
|
||||
@click="subitem.action"
|
||||
></v-list-item>
|
||||
<v-list-item
|
||||
v-else
|
||||
:to="subitem.to"
|
||||
link
|
||||
:title="subitem.text"
|
||||
:value="subitem"
|
||||
:prepend-icon="subitem.icon"
|
||||
></v-list-item>
|
||||
</template>
|
||||
</template>
|
||||
</v-list-group>
|
||||
</template>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="top-menu">
|
||||
<div v-if="user" class="top-menu">
|
||||
<v-menu activator="parent" location="bottom">
|
||||
<template #activator="{ props }">
|
||||
<v-btn icon="mdi-apps" flat class="mr-4" v-bind="props"></v-btn>
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
<template>
|
||||
<v-tabs v-model="active" bg-color="white">
|
||||
<v-tab
|
||||
v-for="(element, index) in displayableElements"
|
||||
:key="index"
|
||||
color="primary"
|
||||
:class="tab_error.includes(index) ? 'error_tab' : ''"
|
||||
>
|
||||
{{ element.label }}
|
||||
</v-tab>
|
||||
</v-tabs>
|
||||
<v-tabs-window v-model="active">
|
||||
<v-tabs-window-item
|
||||
v-for="element in displayableElements"
|
||||
:key="element.label"
|
||||
>
|
||||
<v-container fluid class="pa-0">
|
||||
<v-card>
|
||||
<v-card-text>
|
||||
<template
|
||||
v-for="param in displayableParams(element.parameters)"
|
||||
:key="param.name"
|
||||
>
|
||||
<div class="my-4">
|
||||
<template v-if="param.widget === 'SeparatorField'">
|
||||
<h2>{{ param.label }}</h2>
|
||||
</template>
|
||||
<template v-else-if="param.widget === 'BooleanField'">
|
||||
<v-switch
|
||||
v-if="param.widget === 'BooleanField'"
|
||||
v-model="parameters[param.name]"
|
||||
:label="param.label"
|
||||
:hint="param.help_text"
|
||||
:error="formErrors[param.name] !== undefined"
|
||||
color="primary"
|
||||
density="compact"
|
||||
:error-messages="formErrors[param.name]"
|
||||
persistent-hint
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<label class="m-label">{{ param.label }}</label>
|
||||
<v-select
|
||||
v-if="param.widget === 'ChoiceField'"
|
||||
v-model="parameters[param.name]"
|
||||
:items="param.choices"
|
||||
item-title="text"
|
||||
:hint="param.help_text"
|
||||
persistent-hint
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
/>
|
||||
<v-text-field
|
||||
v-else
|
||||
v-model="parameters[param.name]"
|
||||
:hint="param.help_text"
|
||||
persistent-hint
|
||||
:error="formErrors[param.name] !== undefined"
|
||||
:error-messages="formErrors[param.name]"
|
||||
:type="
|
||||
param.widget === 'PasswordField' ? 'password' : 'text'
|
||||
"
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-container>
|
||||
</v-tabs-window-item>
|
||||
</v-tabs-window>
|
||||
<v-btn
|
||||
icon="mdi-content-save"
|
||||
class="ma-5"
|
||||
position="fixed"
|
||||
location="bottom right"
|
||||
color="green"
|
||||
size="large"
|
||||
@click="save"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useBusStore } from '@/stores'
|
||||
|
||||
const props = defineProps({
|
||||
app: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
structure: {
|
||||
type: Array,
|
||||
default: null,
|
||||
},
|
||||
values: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
saveFunction: {
|
||||
type: Function,
|
||||
default: null,
|
||||
},
|
||||
})
|
||||
const emit = defineEmits(['success'])
|
||||
|
||||
const { $gettext } = useGettext()
|
||||
const { displayNotification } = useBusStore()
|
||||
|
||||
const displayableElements = computed(() =>
|
||||
props.structure.filter((element) => display(element))
|
||||
)
|
||||
|
||||
const active = ref(0)
|
||||
const formErrors = ref({})
|
||||
const parameters = ref({})
|
||||
const tab_error = ref([])
|
||||
|
||||
watch(
|
||||
() => props.values,
|
||||
(newValue) => {
|
||||
if (newValue) {
|
||||
parameters.value = { ...newValue }
|
||||
}
|
||||
}
|
||||
)
|
||||
watch(parameters, () => {
|
||||
tab_error.value = []
|
||||
})
|
||||
|
||||
function display(element) {
|
||||
if (element.display === '') {
|
||||
return true
|
||||
}
|
||||
let result = true
|
||||
element.display.split('&').forEach((rule) => {
|
||||
let [field, value] = rule.split('=')
|
||||
if (value === 'true' || value === 'false') {
|
||||
value = Boolean(value)
|
||||
}
|
||||
result &= parameters.value[field] === value
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
function displayableParams(params) {
|
||||
return params.filter((param) => display(param))
|
||||
}
|
||||
|
||||
async function save() {
|
||||
formErrors.value = {}
|
||||
tab_error.value = []
|
||||
try {
|
||||
await props.saveFunction(props.app, parameters.value)
|
||||
displayNotification({
|
||||
msg: $gettext('Parameters updated'),
|
||||
})
|
||||
emit('success', parameters.value)
|
||||
} catch (error) {
|
||||
displayNotification({
|
||||
msg: $gettext('Could not save parameters'),
|
||||
type: 'error',
|
||||
})
|
||||
formErrors.value = error.response.data
|
||||
Object.keys(formErrors.value).forEach((element) => {
|
||||
for (let i = 0; i < props.structure.length; i++) {
|
||||
const isIn =
|
||||
props.structure[i].parameters.filter(
|
||||
(param) => param.name === element
|
||||
).length > 0
|
||||
if (isIn) {
|
||||
tab_error.value.push(i)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.error_tab {
|
||||
color: #ff5252 !important;
|
||||
}
|
||||
</style>
|
||||
@@ -1,21 +1,32 @@
|
||||
<template>
|
||||
<ConnectedLayout color="grey" :menu-items="getUserSettingsMenuItems()" />
|
||||
<ConnectedLayout color="grey" :menu-items="userSettingsMenuItems" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useAuthStore } from '@/stores'
|
||||
import ConnectedLayout from '@/layouts/connected/ConnectedLayout.vue'
|
||||
import parametersApi from '@/api/parameters'
|
||||
|
||||
const authStore = useAuthStore()
|
||||
const { $gettext } = useGettext()
|
||||
|
||||
const applications = ref([])
|
||||
|
||||
const authUser = computed(() => authStore.authUser)
|
||||
|
||||
function getUserSettingsMenuItems() {
|
||||
const userSettingsMenuItems = computed(() => {
|
||||
const result = []
|
||||
// Temporary solution...
|
||||
const appIcons = {
|
||||
contacts: 'mdi-contacts-outline',
|
||||
}
|
||||
|
||||
result.push({
|
||||
text: $gettext('Settings'),
|
||||
to: { name: 'AccountSettings' },
|
||||
icon: 'mdi-cog',
|
||||
})
|
||||
if (authUser.value.mailbox) {
|
||||
result.push({
|
||||
text: $gettext('Filters'),
|
||||
@@ -23,11 +34,17 @@ function getUserSettingsMenuItems() {
|
||||
icon: 'mdi-filter',
|
||||
})
|
||||
}
|
||||
result.push({
|
||||
text: $gettext('Settings'),
|
||||
to: { name: 'AccountSettings' },
|
||||
icon: 'mdi-cog',
|
||||
})
|
||||
for (const app of applications.value) {
|
||||
result.push({
|
||||
icon: appIcons[app.name],
|
||||
text: app.label,
|
||||
to: { name: 'AccountParametersEdit', params: { app: app.name } },
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
})
|
||||
|
||||
parametersApi.getUserApplications().then((resp) => {
|
||||
applications.value = resp.data
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -100,7 +100,7 @@ const adminMenuItems = [
|
||||
|
||||
onMounted(() => {
|
||||
if (authUser.value.role === 'SuperAdmins') {
|
||||
parametersApi.getApplications().then((response) => {
|
||||
parametersApi.getGlobalApplications().then((response) => {
|
||||
response.data.forEach((item) => {
|
||||
settings.push({
|
||||
text: item.label,
|
||||
@@ -109,7 +109,7 @@ onMounted(() => {
|
||||
})
|
||||
})
|
||||
if (parametersStore.imapMigrationEnabled === null) {
|
||||
parametersApi.getApplication('imap_migration').then((response) => {
|
||||
parametersApi.getGlobalApplication('imap_migration').then((response) => {
|
||||
parametersStore.imapMigrationEnabled =
|
||||
response.data.params.enabled_imapmigration
|
||||
})
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
<template>
|
||||
<v-main>
|
||||
<v-container fluid>
|
||||
<v-container fluid style="height: 100%">
|
||||
<router-view v-slot="{ Component }">
|
||||
<transition name="fade">
|
||||
<div v-show="true">
|
||||
<component :is="Component" />
|
||||
</div>
|
||||
<component :is="Component" />
|
||||
</transition>
|
||||
</router-view>
|
||||
</v-container>
|
||||
|
||||
@@ -9,6 +9,7 @@ import vuetify from './vuetify'
|
||||
import router from '../router'
|
||||
import gettext from './gettext'
|
||||
import filters from './filters'
|
||||
import permissions from './permissions'
|
||||
import pinia from '@/stores'
|
||||
import VueApexCharts from 'vue3-apexcharts'
|
||||
|
||||
@@ -19,5 +20,6 @@ export function registerPlugins(app) {
|
||||
.use(pinia)
|
||||
.use(router)
|
||||
.use(filters)
|
||||
.use(permissions)
|
||||
.use(VueApexCharts)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useAuthStore } from '@/stores'
|
||||
|
||||
export default {
|
||||
install: (app) => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
app.directive('can', (el, binding) => {
|
||||
const permission = binding.value
|
||||
if (authStore.authUser) {
|
||||
if (
|
||||
authUser.authUser.role !== 'SuperAdmins' &&
|
||||
authStore.authUser.permissions.indexOf(permission) === -1
|
||||
) {
|
||||
el.style.display = 'none'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
app.config.globalProperties.$can = function (permission) {
|
||||
if (!authStore.authUser) {
|
||||
return false
|
||||
}
|
||||
if (
|
||||
authStore.authUser.role === 'SuperAdmins' ||
|
||||
authStore.authUser.permissions.indexOf(permission) !== -1
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -24,7 +24,11 @@ function samePassword(value, confirmation) {
|
||||
|
||||
export default {
|
||||
required: (value) =>
|
||||
(value !== '' && value != null) || $gettext('Field is required'),
|
||||
(value !== '' &&
|
||||
value != null &&
|
||||
value !== undefined &&
|
||||
(!Array.isArray(value) || value.length)) ||
|
||||
$gettext('Field is required'),
|
||||
email: (value) => validateEmail(value),
|
||||
emailOrNull: (value) => value != null || value !== '' || validateEmail(value),
|
||||
minLength: (len) => (value) =>
|
||||
|
||||
@@ -250,6 +250,14 @@ const routes = [
|
||||
requiresMailbox: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'parameters/:app',
|
||||
name: 'AccountParametersEdit',
|
||||
component: () => import('@/views/account/ParametersView.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':tab?',
|
||||
name: 'AccountSettings',
|
||||
@@ -291,6 +299,22 @@ const routes = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'calendars',
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'CalendarView',
|
||||
component: () => import('@/views/calendars/CalendarView.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<template>
|
||||
<div>
|
||||
<v-toolbar flat>
|
||||
<v-toolbar-title>{{ title }}</v-toolbar-title>
|
||||
</v-toolbar>
|
||||
|
||||
<ParametersForm
|
||||
:app="$route.params.app"
|
||||
:structure="structure"
|
||||
:values="parameters"
|
||||
:save-function="parametersApi.saveUserApplication"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useRoute } from 'vue-router'
|
||||
import ParametersForm from '@/components/tools/ParametersForm'
|
||||
import parametersApi from '@/api/parameters'
|
||||
|
||||
const { $gettext } = useGettext()
|
||||
const route = useRoute()
|
||||
|
||||
const label = ref('')
|
||||
const structure = ref([])
|
||||
const parameters = ref({})
|
||||
|
||||
const title = computed(() => $gettext('Settings: ' + label.value))
|
||||
|
||||
function loadParams(app) {
|
||||
parametersApi.getUserApplicationStructure(app).then((response) => {
|
||||
structure.value = response.data
|
||||
})
|
||||
parametersApi.getUserApplication(app).then((response) => {
|
||||
parameters.value = response.data.params
|
||||
label.value = response.data.label
|
||||
})
|
||||
}
|
||||
|
||||
loadParams(route.params.app)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.v-toolbar {
|
||||
background-color: #f7f8fa !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
.v-window__container {
|
||||
width: 100% !important;
|
||||
}
|
||||
</style>
|
||||
@@ -4,188 +4,57 @@
|
||||
<v-toolbar-title>{{ title }}</v-toolbar-title>
|
||||
</v-toolbar>
|
||||
|
||||
<v-tabs v-model="active" bg-color="white">
|
||||
<v-tab
|
||||
v-for="(element, index) in displayableElements"
|
||||
:key="index"
|
||||
color="primary"
|
||||
:class="tab_error.includes(index) ? 'error_tab' : ''"
|
||||
>
|
||||
{{ element.label }}
|
||||
</v-tab>
|
||||
</v-tabs>
|
||||
<v-tabs-window v-model="active">
|
||||
<v-tabs-window-item
|
||||
v-for="element in displayableElements"
|
||||
:key="element.label"
|
||||
>
|
||||
<v-container fluid class="pa-0">
|
||||
<v-card>
|
||||
<v-card-text>
|
||||
<template
|
||||
v-for="param in displayableParams(element.parameters)"
|
||||
:key="param.name"
|
||||
>
|
||||
<div class="my-4">
|
||||
<template v-if="param.widget === 'SeparatorField'">
|
||||
<h2>{{ param.label }}</h2>
|
||||
</template>
|
||||
<template v-else-if="param.widget === 'BooleanField'">
|
||||
<v-switch
|
||||
v-if="param.widget === 'BooleanField'"
|
||||
v-model="parameters[param.name]"
|
||||
:label="param.label"
|
||||
:hint="param.help_text"
|
||||
:error="formErrors[param.name] !== undefined"
|
||||
color="primary"
|
||||
density="compact"
|
||||
:error-messages="formErrors[param.name]"
|
||||
persistent-hint
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<label class="m-label">{{ param.label }}</label>
|
||||
<v-select
|
||||
v-if="param.widget === 'ChoiceField'"
|
||||
v-model="parameters[param.name]"
|
||||
:items="param.choices"
|
||||
item-title="text"
|
||||
:hint="param.help_text"
|
||||
persistent-hint
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
/>
|
||||
<v-text-field
|
||||
v-else
|
||||
v-model="parameters[param.name]"
|
||||
:hint="param.help_text"
|
||||
persistent-hint
|
||||
:error="formErrors[param.name] !== undefined"
|
||||
:error-messages="formErrors[param.name]"
|
||||
:type="
|
||||
param.widget === 'PasswordField' ? 'password' : 'text'
|
||||
"
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-container>
|
||||
</v-tabs-window-item>
|
||||
</v-tabs-window>
|
||||
<v-btn
|
||||
icon="mdi-content-save"
|
||||
class="ma-5"
|
||||
position="fixed"
|
||||
location="bottom right"
|
||||
color="green"
|
||||
size="large"
|
||||
@click="save"
|
||||
<ParametersForm
|
||||
:app="$route.params.app"
|
||||
:structure="structure"
|
||||
:values="parameters"
|
||||
:save-function="parametersApi.saveGlobalApplication"
|
||||
@success="onSuccess"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
<script setup>
|
||||
import { useBusStore } from '@/stores'
|
||||
import parametersApi from '@/api/parameters'
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useGlobalStore, useParametersStore } from '@/stores'
|
||||
import ParametersForm from '@/components/tools/ParametersForm'
|
||||
|
||||
const { $gettext } = useGettext()
|
||||
const busStore = useBusStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const route = useRoute()
|
||||
const parametersStore = useParametersStore()
|
||||
|
||||
const active = ref(0)
|
||||
const structure = ref([])
|
||||
const parameters = ref({})
|
||||
const formErrors = ref({})
|
||||
const label = ref('')
|
||||
const tab_error = ref([])
|
||||
|
||||
const displayableElements = computed(() =>
|
||||
structure.value.filter((element) => display(element))
|
||||
)
|
||||
|
||||
const title = computed(() => $gettext('Settings: ' + label.value))
|
||||
|
||||
function loadParams(app) {
|
||||
parametersApi.getApplicationStructure(app).then((response) => {
|
||||
parametersApi.getGlobalApplicationStructure(app).then((response) => {
|
||||
structure.value = response.data
|
||||
})
|
||||
parametersApi.getApplication(app).then((response) => {
|
||||
parametersApi.getGlobalApplication(app).then((response) => {
|
||||
parameters.value = response.data.params
|
||||
label.value = response.data.label
|
||||
})
|
||||
}
|
||||
|
||||
function display(element) {
|
||||
if (element.display === '') {
|
||||
return true
|
||||
function onSuccess(newValues) {
|
||||
globalStore.fetchNotifications()
|
||||
if (route.params.app === 'imap_migration') {
|
||||
parametersStore.imapMigrationEnabled = newValues.enabled_imapmigration
|
||||
}
|
||||
let result = true
|
||||
element.display.split('&').forEach((rule) => {
|
||||
let [field, value] = rule.split('=')
|
||||
if (value === 'true' || value === 'false') {
|
||||
value = Boolean(value)
|
||||
}
|
||||
result &= parameters.value[field] === value
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
function displayableParams(params) {
|
||||
return params.filter((param) => display(param))
|
||||
}
|
||||
|
||||
async function save() {
|
||||
formErrors.value = {}
|
||||
tab_error.value = []
|
||||
parametersApi
|
||||
.saveApplication(route.params.app, parameters.value)
|
||||
.then(() => {
|
||||
busStore.displayNotification({
|
||||
msg: $gettext('Parameters updated'),
|
||||
})
|
||||
globalStore.fetchNotifications()
|
||||
if (route.params.app === 'imap_migration') {
|
||||
parametersStore.imapMigrationEnabled =
|
||||
parameters.value.enabled_imapmigration
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
busStore.displayNotification({
|
||||
msg: $gettext('Could not save parameters'),
|
||||
type: 'error',
|
||||
})
|
||||
formErrors.value = error.response.data
|
||||
Object.keys(formErrors.value).forEach((element) => {
|
||||
for (let i = 0; i < structure.value.length; i++) {
|
||||
const isIn =
|
||||
structure.value[i].parameters.filter(
|
||||
(param) => param.name === element
|
||||
).length > 0
|
||||
if (isIn) {
|
||||
tab_error.value.push(i)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
watch(route, (toRoute) => {
|
||||
loadParams(toRoute.params.app)
|
||||
})
|
||||
|
||||
watch(parameters, () => {
|
||||
tab_error.value = []
|
||||
})
|
||||
loadParams(route.params.app)
|
||||
</script>
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ const account = computed(() => {
|
||||
})
|
||||
const limitsConfig = ref({})
|
||||
|
||||
parametersApi.getApplication('limits').then((resp) => {
|
||||
parametersApi.getGlobalApplication('limits').then((resp) => {
|
||||
limitsConfig.value = resp.data
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
<template>
|
||||
<div class="text-h5 ml-4 mb-6">
|
||||
{{ $gettext('Calendar') }}
|
||||
</div>
|
||||
<FullCalendar ref="calendarRef" :options="calendarOptions" />
|
||||
|
||||
<v-dialog v-model="showInformation" persistent max-width="800px">
|
||||
<CalendarDetail :calendar="selectedCalendar" @close="closeInformation" />
|
||||
</v-dialog>
|
||||
<v-dialog v-model="showCalendarForm" persistent max-width="800px">
|
||||
<CalendarForm
|
||||
:initial-calendar="selectedCalendar"
|
||||
@color-changed="refreshCalendarEvents"
|
||||
@close="closeCalendarForm"
|
||||
/>
|
||||
</v-dialog>
|
||||
<v-dialog v-model="showEventForm" persistent max-width="800px">
|
||||
<EventForm
|
||||
:info="selectInfo"
|
||||
:event="selectedEvent"
|
||||
@close="closeEventForm"
|
||||
/>
|
||||
</v-dialog>
|
||||
<v-dialog v-model="showAccessRulesForm" persistent max-width="800px">
|
||||
<CalendarAccessRulesForm
|
||||
v-if="selectedCalendar"
|
||||
:calendar-pk="selectedCalendar.pk"
|
||||
@close="closeAccessRulesForm"
|
||||
/>
|
||||
</v-dialog>
|
||||
<v-dialog v-model="showImportEventsForm" persistent max-width="800px">
|
||||
<ImportEventsForm
|
||||
v-if="selectedCalendar"
|
||||
:calendar="selectedCalendar"
|
||||
@events-imported="refreshCalendarEvents"
|
||||
@close="closeImportEventsForm"
|
||||
/>
|
||||
</v-dialog>
|
||||
<ConfirmDialog ref="confirm" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useLayoutStore } from '@/stores'
|
||||
import { useBusStore } from '@/stores'
|
||||
import { DateTime } from 'luxon'
|
||||
import api from '@/api/calendars'
|
||||
import CalendarAccessRulesForm from '@/components/calendars/CalendarAccessRulesForm'
|
||||
import CalendarForm from '@/components/calendars/CalendarForm'
|
||||
import CalendarDetail from '@/components/calendars/CalendarDetail'
|
||||
import ConfirmDialog from '@/components/tools/ConfirmDialog'
|
||||
import EventForm from '@/components/calendars/EventForm'
|
||||
import ImportEventsForm from '@/components/calendars/ImportEventsForm'
|
||||
import FullCalendar from '@fullcalendar/vue3'
|
||||
import dayGridPlugin from '@fullcalendar/daygrid'
|
||||
import interactionPlugin from '@fullcalendar/interaction'
|
||||
import timeGridPlugin from '@fullcalendar/timegrid'
|
||||
|
||||
const { $gettext, current } = useGettext()
|
||||
const layoutStore = useLayoutStore()
|
||||
const busStore = useBusStore()
|
||||
|
||||
const calendarRef = ref()
|
||||
const confirm = ref()
|
||||
const selectInfo = ref()
|
||||
const selectedCalendar = ref(null)
|
||||
const selectedEvent = ref(null)
|
||||
const userCalendars = ref([])
|
||||
const showAccessRulesForm = ref(false)
|
||||
const showCalendarForm = ref(false)
|
||||
const showInformation = ref(false)
|
||||
const showEventForm = ref(false)
|
||||
const showImportEventsForm = ref(false)
|
||||
|
||||
const leftMenuItems = computed(() => {
|
||||
const result = [
|
||||
{
|
||||
icon: 'mdi-plus',
|
||||
text: $gettext('New calendar'),
|
||||
action: openCalendarForm,
|
||||
},
|
||||
{
|
||||
text: $gettext('My calendars'),
|
||||
subheader: true,
|
||||
},
|
||||
]
|
||||
for (const calendar of userCalendars.value) {
|
||||
result.push({
|
||||
text: calendar.name,
|
||||
children: [
|
||||
{
|
||||
text: $gettext('Information'),
|
||||
icon: 'mdi-information-outline',
|
||||
action: () => openInformation(calendar),
|
||||
},
|
||||
{
|
||||
text: $gettext('Edit'),
|
||||
icon: 'mdi-pencil',
|
||||
action: () => editCalendar(calendar),
|
||||
},
|
||||
{
|
||||
text: $gettext('Access rules'),
|
||||
icon: 'mdi-filter-outline',
|
||||
action: () => openAccessRulesForm(calendar),
|
||||
},
|
||||
{
|
||||
text: $gettext('Delete'),
|
||||
icon: 'mdi-trash-can-outline',
|
||||
action: () => deleteCalendar(calendar.pk),
|
||||
},
|
||||
{
|
||||
text: $gettext('Import'),
|
||||
icon: 'mdi-calendar-import-outline',
|
||||
action: () => openImportEventsForm(calendar),
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
async function fetchUserCalendarEvents(
|
||||
calendarPk,
|
||||
info,
|
||||
successCallback,
|
||||
failureCallback
|
||||
) {
|
||||
try {
|
||||
const resp = await api.getUserCalendarEvents(calendarPk, {
|
||||
start: info.startStr,
|
||||
end: info.endStr,
|
||||
})
|
||||
successCallback(resp.data)
|
||||
} catch (err) {
|
||||
failureCallback(err)
|
||||
}
|
||||
}
|
||||
|
||||
function openCalendarForm() {
|
||||
showCalendarForm.value = true
|
||||
}
|
||||
|
||||
function closeCalendarForm() {
|
||||
selectedCalendar.value = null
|
||||
showCalendarForm.value = false
|
||||
fetchUserCalendars()
|
||||
}
|
||||
|
||||
function openInformation(calendar) {
|
||||
selectedCalendar.value = calendar
|
||||
showInformation.value = true
|
||||
}
|
||||
|
||||
function closeInformation() {
|
||||
selectedCalendar.value = null
|
||||
showInformation.value = false
|
||||
}
|
||||
|
||||
function openAccessRulesForm(calendar) {
|
||||
selectedCalendar.value = calendar
|
||||
showAccessRulesForm.value = true
|
||||
}
|
||||
|
||||
function closeAccessRulesForm() {
|
||||
selectedCalendar.value = null
|
||||
showAccessRulesForm.value = false
|
||||
}
|
||||
|
||||
function openImportEventsForm(calendar) {
|
||||
selectedCalendar.value = calendar
|
||||
showImportEventsForm.value = true
|
||||
}
|
||||
|
||||
function closeImportEventsForm() {
|
||||
selectedCalendar.value = null
|
||||
showImportEventsForm.value = false
|
||||
}
|
||||
|
||||
function fetchUserCalendars() {
|
||||
api.getUserCalendars().then((resp) => {
|
||||
userCalendars.value = resp.data
|
||||
})
|
||||
}
|
||||
|
||||
function refreshCalendarEvents(calendar) {
|
||||
const fullc = calendarRef.value.getApi()
|
||||
const evtSource = fullc.getEventSourceById(`user-${calendar.pk}`)
|
||||
evtSource.refetch()
|
||||
}
|
||||
|
||||
function selectCallback(info) {
|
||||
selectInfo.value = info
|
||||
showEventForm.value = true
|
||||
}
|
||||
|
||||
async function eventClickCallback(info) {
|
||||
const resp = await api.getUserEvent(
|
||||
info.event.extendedProps.calendar.pk,
|
||||
info.event.id
|
||||
)
|
||||
selectedEvent.value = resp.data
|
||||
showEventForm.value = true
|
||||
}
|
||||
|
||||
function updateEventDates(calEvent) {
|
||||
var data = {
|
||||
start: calEvent.start,
|
||||
end: calEvent.end,
|
||||
}
|
||||
const evtCalendar = calEvent.extendedProps.calendar
|
||||
if (calEvent.allDay) {
|
||||
const end = DateTime.fromJSDate(data.start)
|
||||
end.plus({ days: 1 })
|
||||
data.start.setHours(0, 0, 0)
|
||||
data.end = end
|
||||
data.allDay = calEvent.allDay
|
||||
} else if (!calEvent.end) {
|
||||
const end = DateTime.fromJSDate(data.start)
|
||||
end.plus({ hours: 1 })
|
||||
data.end = end
|
||||
}
|
||||
api.patchUserEvent(evtCalendar.pk, calEvent.id, data).then((response) => {
|
||||
busStore.displayNotification({ msg: $gettext('Event updated') })
|
||||
})
|
||||
}
|
||||
function eventDropCallback(info) {
|
||||
updateEventDates(info.event)
|
||||
}
|
||||
function eventResizeCallback(info) {
|
||||
updateEventDates(info.event)
|
||||
}
|
||||
|
||||
function closeEventForm() {
|
||||
showEventForm.value = false
|
||||
selectedEvent.value = null
|
||||
}
|
||||
|
||||
function editCalendar(calendar) {
|
||||
selectedCalendar.value = calendar
|
||||
showCalendarForm.value = true
|
||||
}
|
||||
|
||||
async function deleteCalendar(calendarPk) {
|
||||
const result = await confirm.value.open(
|
||||
$gettext('Warning'),
|
||||
$gettext('Do you really want to delete this calendar?'),
|
||||
{ color: 'warning' }
|
||||
)
|
||||
if (!result) {
|
||||
return
|
||||
}
|
||||
await api.deleteUserCalendar(calendarPk)
|
||||
const fullc = calendarRef.value.getApi()
|
||||
const evtSource = fullc.getEventSourceById(`user-${calendar.pk}`)
|
||||
evtSource.remove()
|
||||
busStore.displayNotification({ msg: $gettext('Calendar deleted') })
|
||||
}
|
||||
|
||||
const calendarOptions = {
|
||||
plugins: [timeGridPlugin, dayGridPlugin, interactionPlugin],
|
||||
headerToolbar: {
|
||||
left: 'prev,next today',
|
||||
center: 'title',
|
||||
right: 'dayGridMonth,timeGridWeek,timeGridDay',
|
||||
},
|
||||
scrollTime: '09:00:00',
|
||||
height: '100%',
|
||||
firstDay: 1,
|
||||
initialView: 'timeGridWeek',
|
||||
locale: current,
|
||||
selectable: true,
|
||||
selectMirror: true,
|
||||
editable: true,
|
||||
dayMaxEventRows: true,
|
||||
businessHours: {
|
||||
daysOfWeek: [1, 2, 3, 4, 5],
|
||||
startTime: '09:00',
|
||||
endTime: '18:00',
|
||||
},
|
||||
select: selectCallback,
|
||||
eventClick: eventClickCallback,
|
||||
eventDrop: eventDropCallback,
|
||||
eventResize: eventResizeCallback,
|
||||
}
|
||||
|
||||
watch(
|
||||
leftMenuItems,
|
||||
(value) => {
|
||||
layoutStore.setLeftMenuItems(value)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
watch(userCalendars, (value) => {
|
||||
const fullc = calendarRef.value.getApi()
|
||||
if (!fullc) {
|
||||
return
|
||||
}
|
||||
for (const calendar of value) {
|
||||
const evtSource = fullc.getEventSourceById(`user-${calendar.pk}`)
|
||||
if (!evtSource) {
|
||||
fullc.addEventSource({
|
||||
id: `user-${calendar.pk}`,
|
||||
events: fetchUserCalendarEvents.bind(this, calendar.pk),
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserCalendars()
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user