Improve event editing

This commit is contained in:
Ferdinand Thiessen 2021-11-17 01:55:55 +01:00
parent 511014d043
commit 70545c3dda
2 changed files with 39 additions and 28 deletions

View File

@ -51,6 +51,7 @@
v-model="event.end" v-model="event.end"
class="col-xs-12 col-sm-6 q-pa-sm" class="col-xs-12 col-sm-6 q-pa-sm"
label="Veranstaltungsende" label="Veranstaltungsende"
:rules="[afterStart]"
/> />
<q-input <q-input
v-model="event.description" v-model="event.description"
@ -80,7 +81,6 @@
<q-card class="q-my-auto"> <q-card class="q-my-auto">
<edit-job-slot <edit-job-slot
v-model="event.jobs[index]" v-model="event.jobs[index]"
:job-can-delete="jobDeleteDisabled"
@remove-job="removeJob(index)" @remove-job="removeJob(index)"
/> />
</q-card> </q-card>
@ -119,8 +119,8 @@ export default defineComponent({
}, },
date: { date: {
required: false, required: false,
default: '', default: undefined,
type: String type: String as PropType<string|undefined>
} }
}, },
emits: { emits: {
@ -128,29 +128,35 @@ export default defineComponent({
}, },
setup(props, { emit }) { setup(props, { emit }) {
const store = useScheduleStore(); const store = useScheduleStore();
const startDate = computed(() => {
const d = date.buildDate({milliseconds: 0, seconds: 0, minutes: 0, hours: 0})
if (!props.date || !date.isValid(props.date)) return d
const split = props.date.split('-');
return date.adjustDate(d, {year: parseInt(split[0]), month: parseInt(split[1]), date: parseInt(split[2])})
})
const emptyJob = {
const emptyJob = () => ({
id: NaN, id: NaN,
start: date.adjustDate(new Date(props.date), {hours: (new Date()).getHours()}), start: date.adjustDate(startDate.value, {hours: (new Date()).getHours()}, true),
end: date.addToDate(date.adjustDate(new Date(props.date), {hours: (new Date()).getHours()}), {hours: 1}), end: date.addToDate(date.adjustDate(startDate.value, {hours: (new Date()).getHours()}, true), {hours: 1}),
services: [], services: [],
required_services: 2, required_services: 2,
type: store.jobTypes[0], type: store.jobTypes[0],
}; });
const emptyEvent = { const emptyEvent = () => ({
id: NaN, id: NaN,
start: new Date(props.date), start: new Date(startDate.value),
jobs: [Object.assign({}, emptyJob)], jobs: [emptyJob()],
type: store.eventTypes[0], type: store.eventTypes[0],
is_template: false, is_template: false,
}; });
const templates = computed(() => store.templates); const templates = computed(() => store.templates);
const template = ref<FG.Event | undefined>(undefined); const template = ref<FG.Event | undefined>(undefined);
const event = ref<FG.Event>(props.modelValue || Object.assign({}, emptyEvent)); const event = ref<FG.Event>(props.modelValue || emptyEvent());
const eventtypes = computed(() => store.eventTypes); const eventtypes = computed(() => store.eventTypes);
const jobDeleteDisabled = computed(() => event.value.jobs.length < 2);
const recurrent = ref(false); const recurrent = ref(false);
const recurrenceRule = ref<FG.RecurrenceRule>({ frequency: 'daily', interval: 1 }); const recurrenceRule = ref<FG.RecurrenceRule>({ frequency: 'daily', interval: 1 });
@ -161,7 +167,7 @@ export default defineComponent({
}); });
function addJob() { function addJob() {
event.value.jobs.push(Object.assign({}, emptyJob)); event.value.jobs.push(emptyJob());
} }
function removeJob(index: number) { function removeJob(index: number) {
@ -223,25 +229,27 @@ export default defineComponent({
} }
function reset() { function reset() {
event.value = Object.assign({}, props.modelValue || emptyEvent); event.value = Object.assign({}, props.modelValue || emptyEvent());
template.value = undefined; template.value = undefined;
} }
const afterStart = (d: Date) => !d || (event.value.start <= d || 'Das Veranstaltungsende muss vor dem Beginn liegen')
return { return {
jobDeleteDisabled,
addJob, addJob,
eventtypes, afterStart,
templates,
removeJob,
notEmpty,
save,
reset,
recurrent,
fromTemplate,
removeTemplate,
template,
recurrenceRule,
event, event,
eventtypes,
fromTemplate,
notEmpty,
recurrenceRule,
recurrent,
removeJob,
removeTemplate,
reset,
save,
template,
templates,
}; };
}, },
}); });

View File

@ -63,7 +63,10 @@ export default defineComponent({
required: true, required: true,
type: Object as PropType<FG.Job>, type: Object as PropType<FG.Job>,
}, },
jobCanDelete: Boolean, jobCanDelete: {
type: Boolean,
default: false,
}
}, },
emits: { emits: {
'remove-job': () => true, 'remove-job': () => true,