opnform/client/stores/working_form.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-12-09 14:47:03 +00:00
import { defineStore } from 'pinia'
export const useWorkingFormStore = defineStore('working_form', {
state: () => ({
content: null,
// Field being edited
selectedFieldIndex: null,
showEditFieldSidebar: null,
showAddFieldSidebar: null
}),
actions: {
set (form) {
2023-12-24 08:51:22 +00:00
console.log('setting working form', form)
console.trace();
2023-12-09 14:47:03 +00:00
this.content = form
},
setProperties (properties) {
this.content.properties = properties
},
openSettingsForField (index) {
// If field is passed, compute index
if (typeof index === 'object') {
index = this.content.properties.findIndex(prop => prop.id === index.id)
}
this.selectedFieldIndex = index
this.showEditFieldSidebar = true
this.showAddFieldSidebar = false
},
closeEditFieldSidebar () {
this.selectedFieldIndex = null
this.showEditFieldSidebar = false
this.showAddFieldSidebar = false
},
openAddFieldSidebar (index) {
// If field is passed, compute index
if (index !== null && typeof index === 'object') {
index = this.content.properties.findIndex(prop => prop.id === index.id)
}
this.selectedFieldIndex = index
this.showAddFieldSidebar = true
this.showEditFieldSidebar = false
},
closeAddFieldSidebar () {
this.selectedFieldIndex = null
this.showAddFieldSidebar = false
this.showEditFieldSidebar = false
}
}
})