@@ -30,14 +30,73 @@ export default {
3030 },
3131 data () {
3232 return {
33- file: {},
34- signers: [],
35- requested_by: {},
36- requestDate: ' ' ,
33+ sidebarTitleObserver: null ,
3734 }
3835 },
3936 methods: {
37+ checkAndLoadPendingEnvelope () {
38+ const pendingEnvelope = window .OCA ? .Libresign ? .pendingEnvelope
39+ if (pendingEnvelope? .id ) {
40+ this .filesStore .addFile (pendingEnvelope)
41+ this .filesStore .selectFile (pendingEnvelope .id )
42+ delete window .OCA .Libresign .pendingEnvelope
43+
44+ this .$nextTick (() => {
45+ this .updateSidebarTitle (pendingEnvelope .name )
46+ })
47+
48+ return true
49+ }
50+ return false
51+ },
52+
53+ updateSidebarTitle (envelopeName ) {
54+ if (! envelopeName) return
55+
56+ this .disconnectTitleObserver ()
57+
58+ const titleElement = document .querySelector (' .app-sidebar-header__mainname' )
59+
60+ if (titleElement) {
61+ titleElement .textContent = envelopeName
62+ titleElement .setAttribute (' title' , envelopeName)
63+
64+ this .sidebarTitleObserver = new MutationObserver (() => {
65+ if (titleElement .textContent !== envelopeName) {
66+ titleElement .textContent = envelopeName
67+ titleElement .setAttribute (' title' , envelopeName)
68+ }
69+ })
70+
71+ this .sidebarTitleObserver .observe (titleElement, {
72+ childList: true ,
73+ characterData: true ,
74+ subtree: true
75+ })
76+
77+ setTimeout (() => this .disconnectTitleObserver (), 5000 )
78+ }
79+ },
80+
81+ disconnectTitleObserver () {
82+ if (this .sidebarTitleObserver ) {
83+ console .log (' Disconnecting sidebar title observer' )
84+ this .sidebarTitleObserver .disconnect ()
85+ this .sidebarTitleObserver = null
86+ }
87+ },
88+
4089 async update (fileInfo ) {
90+ if (this .checkAndLoadPendingEnvelope ()) {
91+ return
92+ }
93+
94+ this .disconnectTitleObserver ()
95+
96+ if (this .filesStore .selectedId === fileInfo .id ) {
97+ return
98+ }
99+
41100 this .filesStore .addFile ({
42101 nodeId: fileInfo .id ,
43102 name: fileInfo .name ,
@@ -46,6 +105,14 @@ export default {
46105 signers: [],
47106 })
48107 this.filesStore.selectFile(fileInfo.id)
108+
109+ this.$nextTick(() => {
110+ const titleElement = document.querySelector('.app-sidebar-header__mainname')
111+ if (titleElement) {
112+ titleElement.textContent = fileInfo.name
113+ titleElement.setAttribute('title', fileInfo.name)
114+ }
115+ })
49116 },
50117 },
51118}
0 commit comments