2023-02-17 19:00:27 +00:00
|
|
|
<template>
|
2023-09-20 22:04:47 +00:00
|
|
|
<SVGRect
|
2023-09-22 19:02:51 +00:00
|
|
|
style="cursor: text"
|
2023-09-20 22:04:47 +00:00
|
|
|
:rectangle="door.position"
|
|
|
|
:variant="editing ? 'success' : 'primary'"
|
2023-09-22 19:02:51 +00:00
|
|
|
@click.left="on_click"
|
2023-09-07 01:17:14 +00:00
|
|
|
>
|
2023-09-22 19:02:51 +00:00
|
|
|
<input
|
|
|
|
v-if="editing"
|
|
|
|
v-model="day_str"
|
|
|
|
ref="day_input"
|
|
|
|
class="input is-large"
|
|
|
|
type="number"
|
|
|
|
:min="MIN_DAY"
|
|
|
|
placeholder="Tag"
|
|
|
|
@keydown="on_keydown"
|
|
|
|
/>
|
|
|
|
<div v-else class="has-text-danger">
|
|
|
|
{{ door.day > 0 ? door.day : "*" }}
|
2023-02-17 19:00:27 +00:00
|
|
|
</div>
|
2023-09-22 19:02:51 +00:00
|
|
|
</SVGRect>
|
2023-02-17 19:00:27 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-09-07 02:08:56 +00:00
|
|
|
import { Door } from "@/lib/door";
|
2023-02-17 19:00:27 +00:00
|
|
|
import { Options, Vue } from "vue-class-component";
|
|
|
|
|
2023-09-10 01:59:19 +00:00
|
|
|
import SVGRect from "../calendar/SVGRect.vue";
|
2023-02-17 19:00:27 +00:00
|
|
|
|
|
|
|
@Options({
|
|
|
|
components: {
|
|
|
|
SVGRect,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
door: Door,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class extends Vue {
|
2023-09-06 16:25:35 +00:00
|
|
|
public door!: Door;
|
2023-09-12 14:55:08 +00:00
|
|
|
public readonly MIN_DAY = Door.MIN_DAY;
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2023-09-06 16:25:35 +00:00
|
|
|
public day_str = "";
|
|
|
|
public editing = false;
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2023-02-18 00:43:07 +00:00
|
|
|
declare $refs: {
|
2023-09-14 14:20:21 +00:00
|
|
|
day_input: HTMLInputElement | unknown;
|
2023-02-18 00:43:07 +00:00
|
|
|
};
|
|
|
|
|
2023-02-17 19:00:27 +00:00
|
|
|
private toggle_editing() {
|
|
|
|
this.day_str = String(this.door.day);
|
2023-09-07 00:34:42 +00:00
|
|
|
this.editing = !this.editing;
|
2023-02-17 19:00:27 +00:00
|
|
|
}
|
|
|
|
|
2023-09-06 16:25:35 +00:00
|
|
|
public on_click(event: MouseEvent) {
|
2023-09-22 19:02:51 +00:00
|
|
|
if (event.target === null || !(event.target instanceof SVGRectElement)) {
|
2023-02-17 19:00:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-18 00:43:07 +00:00
|
|
|
if (!this.editing) {
|
|
|
|
const day_input_focus = () => {
|
|
|
|
if (this.$refs.day_input instanceof HTMLInputElement) {
|
2023-09-04 21:27:37 +00:00
|
|
|
this.$refs.day_input.select();
|
2023-02-18 00:43:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$nextTick(day_input_focus);
|
|
|
|
};
|
|
|
|
day_input_focus();
|
|
|
|
} else {
|
2023-09-07 00:34:42 +00:00
|
|
|
this.door.day = this.day_str;
|
2023-02-17 19:00:27 +00:00
|
|
|
}
|
|
|
|
|
2023-02-18 00:43:07 +00:00
|
|
|
this.toggle_editing();
|
2023-02-17 19:00:27 +00:00
|
|
|
}
|
|
|
|
|
2023-09-06 16:25:35 +00:00
|
|
|
public on_keydown(event: KeyboardEvent) {
|
2023-02-17 19:00:27 +00:00
|
|
|
if (!this.editing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.key === "Enter") {
|
2023-09-07 00:34:42 +00:00
|
|
|
this.door.day = this.day_str;
|
2023-02-17 19:00:27 +00:00
|
|
|
this.toggle_editing();
|
|
|
|
} else if (event.key === "Delete") {
|
|
|
|
this.door.day = -1;
|
|
|
|
this.toggle_editing();
|
|
|
|
} else if (event.key === "Escape") {
|
|
|
|
this.toggle_editing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|