Select Git revision
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
-
Closes #838, #1850, and #1817 Merge request studip/studip!1136
Closes #838, #1850, and #1817 Merge request studip/studip!1136
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
wiki.js 5.13 KiB
/**
* This file contains all wiki related javascript.
*
* For now this is the "submit and edit" functionality via ajax.
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @copyright Stud.IP Core Group
* @license GPL2 or any later version
* @since Stud.IP 3.3
*/
$(document).on('click', '#wiki button[name="submit-and-edit"]', function(event) {
var form = $(this).closest('form'),
data = {},
form_data,
i,
wysiwyg_editor = false;
if (STUDIP.editor_enabled) {
const textarea = $('textarea[name="body"]', form).get(0);
if (textarea) {
wysiwyg_editor = STUDIP.wysiwyg.getEditor(textarea);
wysiwyg_editor.sourceElement.value = STUDIP.wysiwyg.markAsHtml(wysiwyg_editor.getData());
}
}
form_data = form.serializeArray();
// Show ajax overlay to indicate activity (and prevent buttons to be
// clicked again)
STUDIP.Overlay.show(true, form.css('position', 'relative'));
// Include this button into form's data
form_data.push({
name: $(this).attr('name'),
value: true
});
// Transform data into an easier accessible format
for (i = 0; i < form_data.length; i += 1) {
data[form_data[i].name] = form_data[i].value;
}
// Check version
$.getJSON(
STUDIP.URLHelper.getURL('dispatch.php/wiki/version_check/' + data.version, {
keyword: data.wiki
})
)
.then(function(response, status, jqxhr) {
var error = jqxhr.getResponseHeader('X-Studip-Error'),
to_confirm = jqxhr.getResponseHeader('X-Studip-Confirm'),
confirmed = false;
// Unrecoverable error
if (response === false) {
window.alert(error);
return;
}
// Saving needs confirmation (newer version available?)
if (response === null) {
confirmed = window.confirm(error + '\n\n' + to_confirm);
} else {
confirmed = true;
}
// Ready to save
if (confirmed) {
$.ajax({
type: (form.attr('method') || 'GET').toUpperCase(),
url: STUDIP.URLHelper.getURL('dispatch.php/wiki/store/' + data.version),
data: {