opnform-host-nginx/client/stores/working_form.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

import { defineStore } from "pinia"
2023-12-09 15:47:03 +01:00
export const useWorkingFormStore = defineStore("working_form", {
2023-12-09 15:47:03 +01:00
state: () => ({
content: null,
// Field being edited
selectedFieldIndex: null,
showEditFieldSidebar: null,
showAddFieldSidebar: null,
2023-12-09 15:47:03 +01:00
}),
actions: {
set(form) {
2023-12-09 15:47:03 +01:00
this.content = form
},
setProperties(properties) {
this.content.properties = [...properties]
2023-12-09 15:47:03 +01:00
},
openSettingsForField(index) {
2023-12-09 15:47:03 +01:00
// If field is passed, compute index
if (typeof index === "object") {
index = this.content.properties.findIndex(
(prop) => prop.id === index.id,
)
2023-12-09 15:47:03 +01:00
}
this.selectedFieldIndex = index
this.showEditFieldSidebar = true
this.showAddFieldSidebar = false
},
closeEditFieldSidebar() {
2023-12-09 15:47:03 +01:00
this.selectedFieldIndex = null
this.showEditFieldSidebar = false
this.showAddFieldSidebar = false
},
openAddFieldSidebar(index) {
2023-12-09 15:47:03 +01:00
// If field is passed, compute index
if (index !== null && typeof index === "object") {
index = this.content.properties.findIndex(
(prop) => prop.id === index.id,
)
2023-12-09 15:47:03 +01:00
}
this.selectedFieldIndex = index
this.showAddFieldSidebar = true
this.showEditFieldSidebar = false
},
closeAddFieldSidebar() {
2023-12-09 15:47:03 +01:00
this.selectedFieldIndex = null
this.showAddFieldSidebar = false
this.showEditFieldSidebar = false
},
reset() {
this.content = null
this.selectedFieldIndex = null
this.showEditFieldSidebar = null
this.showAddFieldSidebar = null
},
},
2023-12-09 15:47:03 +01:00
})