@ -1826,6 +1826,7 @@ define([
* @ param { Object } data JSON representation of a notebook
* /
Notebook . prototype . fromJSON = function ( data ) {
var content = data . content ;
var ncells = this . ncells ( ) ;
var i ;
@ -1975,6 +1976,7 @@ define([
type : "PUT" ,
data : JSON . stringify ( model ) ,
headers : { 'Content-Type' : 'application/json' } ,
dataType : "json" ,
success : $ . proxy ( this . save _notebook _success , this , start ) ,
error : $ . proxy ( this . save _notebook _error , this )
} ;
@ -2004,6 +2006,30 @@ define([
* /
Notebook . prototype . save _notebook _success = function ( start , data , status , xhr ) {
this . set _dirty ( false ) ;
if ( data . message ) {
// save succeeded, but validation failed.
var body = $ ( "<div>" ) ;
var title = "Notebook validation failed" ;
body . append ( $ ( "<p>" ) . text (
"The save operation succeeded," +
" but the notebook does not appear to be valid." +
" The validation error was:"
) ) . append ( $ ( "<div>" ) . addClass ( "validation-error" ) . append (
$ ( "<pre>" ) . text ( data . message )
) ) ;
dialog . modal ( {
notebook : this ,
keyboard _manager : this . keyboard _manager ,
title : title ,
body : body ,
buttons : {
OK : {
"class" : "btn-primary"
}
}
} ) ;
}
this . events . trigger ( 'notebook_saved.Notebook' ) ;
this . _update _autosave _interval ( start ) ;
if ( this . _checkpoint _after _save ) {
@ -2278,7 +2304,57 @@ define([
* @ param { jqXHR } xhr jQuery Ajax object
* /
Notebook . prototype . load _notebook _success = function ( data , status , xhr ) {
this . fromJSON ( data ) ;
var failed ;
try {
this . fromJSON ( data ) ;
} catch ( e ) {
failed = e ;
console . log ( "Notebook failed to load from JSON:" , e ) ;
}
if ( failed || data . message ) {
// *either* fromJSON failed or validation failed
var body = $ ( "<div>" ) ;
var title ;
if ( failed ) {
title = "Notebook failed to load" ;
body . append ( $ ( "<p>" ) . text (
"The error was: "
) ) . append ( $ ( "<div>" ) . addClass ( "js-error" ) . text (
failed . toString ( )
) ) . append ( $ ( "<p>" ) . text (
"See the error console for details."
) ) ;
} else {
title = "Notebook validation failed" ;
}
if ( data . message ) {
var msg ;
if ( failed ) {
msg = "The notebook also failed validation:"
} else {
msg = "An invalid notebook may not function properly." +
" The validation error was:"
}
body . append ( $ ( "<p>" ) . text (
msg
) ) . append ( $ ( "<div>" ) . addClass ( "validation-error" ) . append (
$ ( "<pre>" ) . text ( data . message )
) ) ;
}
dialog . modal ( {
notebook : this ,
keyboard _manager : this . keyboard _manager ,
title : title ,
body : body ,
buttons : {
OK : {
"class" : "btn-primary"
}
}
} ) ;
}
if ( this . ncells ( ) === 0 ) {
this . insert _cell _below ( 'code' ) ;
this . edit _mode ( 0 ) ;