Ask for confirmation when saving document with errors

Bug: 63202
Change-Id: Ifbdf976f3c0f27da67d7cf034c040d4279d62217
This commit is contained in:
Derk-Jan Hartman 2014-03-28 11:47:21 +01:00
parent 27249af1cc
commit 262bfde28e
4 changed files with 29 additions and 8 deletions

View file

@ -49,7 +49,8 @@ $wgResourceModules['jquery.codeEditor'] = array(
'jquery.ui.resizable'
),
'messages' => array(
'codeeditor-toolbar-toggle'
'codeeditor-toolbar-toggle',
'codeeditor-save-with-errors'
)
) + $tpl;

View file

@ -1,9 +1,11 @@
{
"@metadata": {
"authors": [
"Brion Vibber"
"Brion Vibber",
"Derk-Jan Hartman"
]
},
"codeeditor-desc": "Syntax-highlighted editing for JavaScript and CSS pages using [http://ace.ajax.org/ Ace editor]",
"codeeditor-toolbar-toggle": "Toggle code editor"
}
"codeeditor-toolbar-toggle": "Toggle code editor",
"codeeditor-save-with-errors": "The document contains errors. Are you sure you want to save?"
}

View file

@ -2,9 +2,11 @@
"@metadata": {
"authors": [
"Purodha",
"Shirayuki"
"Shirayuki",
"Derk-Jan Hartman"
]
},
"codeeditor-desc": "{{desc|name=Code Editor|url=http://www.mediawiki.org/wiki/Extension:CodeEditor}}",
"codeeditor-toolbar-toggle": "Used as label for toolbar button."
}
"codeeditor-toolbar-toggle": "Used as label for toolbar button.",
"codeeditor-save-with-errors": "Used as message in a dialog before saving a document with errors."
}

View file

@ -1,5 +1,5 @@
/* Ace syntax-highlighting code editor extension for wikiEditor */
/*global require, ace */
/*global require, ace, confirm */
(function ( $, mw ) {
$.wikiEditor.modules.codeEditor = {
/**
@ -60,7 +60,23 @@
'ready': function ( ) {
},
'codeEditorSubmit': function ( ) {
context.evt.codeEditorSync();
var i,
hasError = false,
annotations = context.codeEditor.getSession().getAnnotations();
for( i = 0; i < annotations.length; i++ ) {
if ( annotations[i].type === 'error' ) {
hasError = true;
break;
}
}
if ( hasError ) {
return confirm( mw.msg( 'codeeditor-save-with-errors' ) );
}
},
'codeEditorSync': function ( ) {
context.$textarea.val( context.$textarea.textSelection( 'getContents' ) );
}
} );