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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
const Wiki = {
updatePageContent(pageContents) {
if (!pageContents) {
return;
}
for (let page_id in pageContents.contents) {
$('.wiki_page_content_' + page_id).html(pageContents.contents[page_id]);
}
},
updateEditorStatus(editorStatus) {
if (!editorStatus) {
return;
}
for (let page_id in STUDIP.Wiki.Editors) {
STUDIP.Wiki.Editors[page_id].users = editorStatus.users[page_id];
if (!STUDIP.Wiki.Editors[page_id].editing) {
STUDIP.Wiki.Editors[page_id].content = editorStatus.contents[page_id];
STUDIP.Wiki.Editors[page_id].editor.setData(editorStatus.wysiwyg_contents[page_id]);
}
if (
!STUDIP.Wiki.Editors[page_id].editing
&& editorStatus.pages[page_id].editing > 0
) {
STUDIP.Wiki.Editors[page_id].editing = true;
STUDIP.Wiki.Editors[page_id].focusEditor();
} else {
STUDIP.Wiki.Editors[page_id].editing = editorStatus.pages[page_id].editing > 0;
}
STUDIP.Wiki.Editors[page_id].lastSaveDate = new Date(editorStatus.pages[page_id].chdate * 1000);
}
},
Editors: {},
initEditor() {
let wiki_edit_container = document.querySelectorAll( '.wiki-editor-container');
for (let edit_container of wiki_edit_container) {
let page_id = edit_container.dataset.page_id;
Promise.all([
STUDIP.Vue.load(),
import('../../../vue/components/WikiEditorOnlineUsers.vue').then((config) => config.default),
]).then(([{ createApp }, WikiEditorOnlineUsers]) => {
return createApp({
el: edit_container,
data() {
return {
page_id: page_id,
editing: edit_container.dataset.editing > 0,
content: edit_container.dataset.content,
users: JSON.parse(edit_container.dataset.users),
editor: null,
isChanged: false,
lastSaveDate: new Date(edit_container.dataset.chdate * 1000),
lastChangeDate: 0,
lastFocussedDate: 0,
autosave: false
};
},
methods: {
applyEditing() {
const url = STUDIP.URLHelper.getURL('dispatch.php/course/wiki/apply_editing/' + this.page_id)
$.post(url).done(output => {
if (output.me_online.editing > 0) {
this.editing = true;
this.focusEditor();
}
this.users = output.users;
});
},
delegateEditMode(user_id) {
const url = STUDIP.URLHelper.getURL('dispatch.php/course/wiki/delegate_edit_mode/' + this.page_id + '/' + user_id);
$.post(url).done(() => this.editing = false);
},
focusEditor() {
this.$nextTick(() => {
this.editor.editing.view.focus();
});
},
toggleSecurityHandler(state = true) {
if (state) {
window.addEventListener('beforeunload', this.securityHandler);
} else {
window.removeEventListener('beforeunload', this.securityHandler);
}
},
securityHandler(event) {
event.preventDefault();
event.returnValue = true;
},
saveWikiPage() {
this.toggleSecurityHandler(false);
this.$refs.form.submit();
}
},
mounted() {
let textarea = this.$refs['wiki_editor'];
let promise = STUDIP.wysiwyg.replace(textarea);
promise.then((editor) => {
if (this.editing) {
editor.editing.view.focus();
}
editor.model.document.on('change:data',() => {
this.isChanged = editor.getData() !== this.content;
this.lastChangeDate = new Date();
});
this.editor = editor;
});
},
computed: {
requestingUsers() {
return this.users
.filter(u => u.editing_request)
.sort((a, b) => a.fullname.localeCompare(b.fullname));
}
},
watch: {
isChanged(current) {
this.toggleSecurityHandler(current);
}
},
components: { WikiEditorOnlineUsers }
});
}).then((app) => {
STUDIP.Wiki.Editors[page_id] = app;
});
}
}
};
export default Wiki;
|