@@ -281,17 +281,46 @@ ns.Editor.prototype.getParams = function (notFormSubmit) {
281
281
*
282
282
* @alias H5PEditor.Editor#getContent
283
283
* @param {Function } submit Callback to submit the content data
284
+ * @param {Function } [error] Callback on failure
284
285
*/
285
- ns . Editor . prototype . getContent = function ( submit ) {
286
+ ns . Editor . prototype . getContent = function ( submit , error ) {
286
287
const iframeEditor = this . iframeWindow . H5PEditor ;
287
288
289
+ if ( ! this . selector . form ) {
290
+ if ( error ) {
291
+ error ( 'content-not-selected' ) ;
292
+ }
293
+ return ;
294
+ }
295
+
288
296
const content = {
289
297
title : this . isMainTitleSet ( ) ,
290
298
library : this . getLibrary ( ) ,
291
299
params : this . getParams ( )
292
300
} ;
293
301
294
- if ( ! content . title || ! content . library || ! content . params || ! content . params . params ) {
302
+ if ( ! content . title ) {
303
+ if ( error ) {
304
+ error ( 'missing-title' ) ;
305
+ }
306
+ return ;
307
+ }
308
+ if ( ! content . library ) {
309
+ if ( error ) {
310
+ error ( 'missing-library' ) ;
311
+ }
312
+ return ;
313
+ }
314
+ if ( ! content . params ) {
315
+ if ( error ) {
316
+ error ( 'missing-params' ) ;
317
+ }
318
+ return ;
319
+ }
320
+ if ( ! content . params . params ) {
321
+ if ( error ) {
322
+ error ( 'missing-params-params' ) ;
323
+ }
295
324
return ;
296
325
}
297
326
@@ -305,7 +334,12 @@ ns.Editor.prototype.getContent = function (submit) {
305
334
if ( upgradeLibrary ) {
306
335
// We need to run content upgrade before saving
307
336
iframeEditor . upgradeContent ( library , upgradeLibrary , content . params , function ( err , result ) {
308
- if ( ! err ) {
337
+ if ( err ) {
338
+ if ( error ) {
339
+ error ( err ) ;
340
+ }
341
+ }
342
+ else {
309
343
content . library = iframeEditor . ContentType . getNameVersionString ( upgradeLibrary ) ;
310
344
content . params = result ;
311
345
submit ( content ) ;
0 commit comments