Skip to content

Commit

Permalink
refactor keydown
Browse files Browse the repository at this point in the history
  • Loading branch information
david-loe committed Nov 21, 2024
1 parent 7f3984b commit 295bc72
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<template>
<Vueform :schema="schema" ref="form$" :endpoint="false" @submit="(form$: any) => postConnectionSettings(form$.data)"></Vueform>
<Vueform
:schema="schema"
ref="form$"
:endpoint="false"
@submit="(form$: any) => postConnectionSettings(form$.data)"
@keydown.ctrl.s.prevent="() => postConnectionSettings(($refs.form$ as any).data)"></Vueform>
</template>

<script lang="ts">
Expand Down Expand Up @@ -30,21 +35,10 @@ export default defineComponent({
this.connectionSettings = result.ok
;(this.$refs.form$ as any).load(this.connectionSettings)
}
},
ctrlS(event: KeyboardEvent) {
if (event.ctrlKey && event.key === 's') {
event.preventDefault()
if (!event.repeat && this.$refs.form$) {
this.postConnectionSettings((this.$refs.form$ as any).data)
}
}
}
},
beforeDestroy() {
document.removeEventListener('keydown', this.ctrlS)
},
async mounted() {
document.addEventListener('keydown', this.ctrlS)
await this.$root.load()
this.schema = Object.assign({}, (await this.$root.getter<any>('admin/connectionSettings/form')).ok?.data, {
buttons: {
Expand Down
19 changes: 6 additions & 13 deletions frontend/src/components/settings/elements/DisplaySettingsForm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<template>
<Vueform :schema="schema" ref="form$" :endpoint="false" @submit="(form$: any) => postDisplaySettings(form$.data)"></Vueform>
<Vueform
:schema="schema"
ref="form$"
:endpoint="false"
@submit="(form$: any) => postDisplaySettings(form$.data)"
@keydown.ctrl.s.prevent="() => postDisplaySettings(($refs.form$ as any).data)"></Vueform>
</template>

<script lang="ts">
Expand All @@ -21,21 +26,9 @@ export default defineComponent({
this.displaySettings = result.ok
;(this.$refs.form$ as any).load(this.displaySettings)
}
},
ctrlS(event: KeyboardEvent) {
if (event.ctrlKey && event.key === 's') {
event.preventDefault()
if (!event.repeat && this.$refs.form$) {
this.postDisplaySettings((this.$refs.form$ as any).data)
}
}
}
},
beforeDestroy() {
document.removeEventListener('keydown', this.ctrlS)
},
async mounted() {
document.addEventListener('keydown', this.ctrlS)
await this.$root.load()
this.schema = Object.assign({}, (await this.$root.getter<any>('admin/displaySettings/form')).ok?.data, {
buttons: {
Expand Down
19 changes: 6 additions & 13 deletions frontend/src/components/settings/elements/SettingsForm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<template>
<Vueform :schema="schema" ref="form$" :endpoint="false" @submit="(form$: any) => postSettings(form$.data)"></Vueform>
<Vueform
:schema="schema"
ref="form$"
:endpoint="false"
@submit="(form$: any) => postSettings(form$.data)"
@keydown.ctrl.s.prevent="() => postSettings(($refs.form$ as any).data)"></Vueform>
</template>

<script lang="ts">
Expand All @@ -20,21 +25,9 @@ export default defineComponent({
this.$root.settings = result.ok
;(this.$refs.form$ as any).load(this.$root.settings)
}
},
ctrlS(event: KeyboardEvent) {
if (event.ctrlKey && event.key === 's') {
event.preventDefault()
if (!event.repeat && this.$refs.form$) {
this.postSettings((this.$refs.form$ as any).data)
}
}
}
},
beforeDestroy() {
document.removeEventListener('keydown', this.ctrlS)
},
async mounted() {
document.addEventListener('keydown', this.ctrlS)
await this.$root.load()
this.schema = Object.assign({}, (await this.$root.getter<any>('admin/settings/form')).ok?.data, {
buttons: {
Expand Down

0 comments on commit 295bc72

Please sign in to comment.