owltide/components/TableScheduleLocations.vue

126 lines
2.5 KiB
Vue
Raw Permalink Normal View History

<!--
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
SPDX-License-Identifier: AGPL-3.0-or-later
-->
2025-03-11 14:12:33 +01:00
<template>
<figure>
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>description</th>
<th v-if="edit"></th>
</tr>
</thead>
<tbody>
<tr
v-for="location in schedule.locations.values()"
2025-03-11 14:12:33 +01:00
:key="location.id"
:class="{ removed: location.deleted }"
2025-03-11 14:12:33 +01:00
>
<template v-if='edit'>
<td>{{ location.id }}</td>
<td>
<input
type="text"
v-model="location.name"
2025-03-11 14:12:33 +01:00
>
</td>
<td>
<input
type="text"
v-model="location.description"
2025-03-11 14:12:33 +01:00
>
</td>
<td>
<button
:disabled="location.deleted"
2025-03-11 14:12:33 +01:00
type="button"
@click="location.deleted = true"
2025-03-11 14:12:33 +01:00
>Remove</button>
<button
v-if="location.isModified()"
2025-03-11 14:12:33 +01:00
type="button"
@click="schedule.locations.discardId(location.id)"
2025-03-11 14:12:33 +01:00
>Revert</button>
</td>
</template>
<template v-else>
<td>{{ location.id }}</td>
<td>{{ location.name }}</td>
<td>{{ location.description }}</td>
</template>
</tr>
<tr v-if='edit'>
<td>
{{ schedule.nextClientId }}
2025-03-11 14:12:33 +01:00
</td>
<td>
<input
type="text"
v-model="newLocationName"
>
</td>
<td>
<input
type="text"
v-model="newLocationDescription"
>
</td>
<td colspan="1">
2025-03-11 14:12:33 +01:00
<button
type="button"
@click="newLocation()"
2025-03-11 14:12:33 +01:00
>Add Location</button>
</td>
</tr>
</tbody>
</table>
</figure>
</template>
<script lang="ts" setup>
import { Info } from '~/shared/utils/luxon';
2025-03-11 14:12:33 +01:00
defineProps<{
edit?: boolean
}>();
const schedule = await useSchedule();
const accountStore = useAccountStore();
2025-03-11 14:12:33 +01:00
const newLocationName = ref("");
const newLocationDescription = ref("");
2025-03-11 14:12:33 +01:00
function newLocation() {
const zone = Info.normalizeZone(accountStore.activeTimezone);
const locale = accountStore.activeLocale;
const location = ClientScheduleLocation.create(
schedule.value.nextClientId--,
newLocationName.value,
newLocationDescription.value,
{ zone, locale },
);
schedule.value.locations.add(location);
newLocationName.value = "";
newLocationDescription.value = "";
}
2025-03-11 14:12:33 +01:00
</script>
<style scoped>
table {
border-spacing: 0;
}
table th {
text-align: left;
border-bottom: 1px solid var(--foreground);
}
table :is(th, td) + :is(th, td) {
padding-inline-start: 0.4em;
}
.removed :is(td, input) {
text-decoration: line-through;
}
</style>