Snippets

Marcel "childno͡.de" Trautwein prevent empty version comment in confluence on save

Created by Marcel "childno͡.de" Trautwein last modified
/** Author: childno͡.de **/
var valOnSaveMsg="PLEASE insert a text into the change message field or uncheck the notifications if you only made minor / typo changes. Thank you!"
AJS.$(document).on("valOnSaveMsg", function(e, useDialog){
    if (!useDialog) {
		Confluence.EditorNotification.notify("error", valOnSaveMsg, 10)
		return;
	}
	
	(function() {var dialog = new AJS.Dialog({
	    width: 500,
	    height: 200,
	    id: "warn-on-save-empty-versioncomment",
	    closeOnOutsideClick: true
	});
	dialog.addHeader("oh no", "aui-lozenge-error");
	
	dialog.addPanel("PLEASE", "<p>" + valOnSaveMsg + "</p>", "panel-body");
	
	dialog.addLink("Dismiss", function (dialog) {
	    dialog.hide();
	}, "#");
	
	dialog.gotoPage(0);
	dialog.gotoPanel(0);
	dialog.show();})()
});
AJS.$(document).ready(function() { 
	// known bug: submit is also done by cancel action
    AJS.$("form#editpageform").on("submit", function(e) {
        if (AJS.$("input#notifyWatchers").attr("checked") && AJS.$("input#versionComment")[0].value.trim().length == 0) {
            e.preventDefault();
			// use notification instead of dialog
            AJS.$(document).trigger("valOnSaveMsg", [ false ]);
            Confluence.Editor.UI.toggleSavebarBusy(false);
            Confluence.Editor.isCancelling=true
        }
    })
})

Comments (2)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.