-
-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathsign.js
More file actions
80 lines (69 loc) · 1.95 KB
/
sign.js
File metadata and controls
80 lines (69 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { defineStore } from 'pinia'
import { set } from 'vue'
import { loadState } from '@nextcloud/initial-state'
import { useFilesStore } from './files.js'
import { useSidebarStore } from './sidebar.js'
import { useSignMethodsStore } from './signMethods.js'
const defaultState = {
errors: [],
document: {
id: 0,
name: '',
description: '',
status: '',
statusText: '',
url: '',
nodeId: 0,
nodeType: 'file',
uuid: '',
signers: [],
},
mounted: false,
}
export const useSignStore = defineStore('sign', {
state: () => ({ ...defaultState }),
actions: {
async initFromState() {
this.errors = loadState('libresign', 'errors', [])
const file = {
id: loadState('libresign', 'id', 0),
name: loadState('libresign', 'filename', ''),
description: loadState('libresign', 'description', ''),
status: loadState('libresign', 'status', ''),
statusText: loadState('libresign', 'statusText', ''),
nodeId: loadState('libresign', 'nodeId', 0),
nodeType: loadState('libresign', 'nodeType', ''),
uuid: loadState('libresign', 'uuid', null),
signers: loadState('libresign', 'signers', []),
}
const filesStore = useFilesStore()
const sidebarStore = useSidebarStore()
await filesStore.addFile(file)
filesStore.selectFile(file.id)
this.setFileToSign(file)
sidebarStore.activeSignTab()
},
setFileToSign(file) {
if (file) {
this.errors = []
set(this, 'document', file)
const sidebarStore = useSidebarStore()
sidebarStore.activeSignTab()
const signMethodsStore = useSignMethodsStore()
const signer = file.signers.find(row => row.me) || {}
signMethodsStore.settings = signer.signatureMethods || {}
return
}
this.reset()
},
reset() {
set(this, 'document', defaultState)
const sidebarStore = useSidebarStore()
sidebarStore.setActiveTab()
},
},
})