Skip to content
Snippets Groups Projects
Select Git revision
  • 737c0b2ade4ea92ea85ad9c536553abfcbc96877
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

wiki.js

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    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: {