@@ -467,7 +467,7 @@ class App {
467467
468468 #createEditInPlaceElements( ) {
469469 const toggle_attr = 'data-edit-in-place-toggle' ;
470- const toggles = document . querySelectorAll ( '[' + toggle_attr + ']' ) ;
470+ const toggles = document . querySelectorAll ( `[ ${ toggle_attr } ]` ) ;
471471
472472 if ( ! toggles . length ) {
473473 return ;
@@ -476,27 +476,35 @@ class App {
476476 toggles . forEach ( ( toggle ) => {
477477 const unique_id = toggle . getAttribute ( toggle_attr ) ;
478478 if ( ! unique_id ) {
479- console . error ( ' There is an element with attribute "' + toggle_attr + ' ", but the attribute has no value.' ) ;
479+ console . error ( ` There is an element with attribute "${ toggle_attr } ", but the attribute has no value.` ) ;
480480 return ;
481481 }
482- const field_container = document . querySelector ( `[data-edit-field="${ unique_id } "]` )
482+ const field_container = document . querySelector ( `[data-edit-field="${ unique_id } "]` ) ;
483483 if ( ! field_container ) {
484- console . error ( 'There is an element with attribute "' + toggle_attr + '", but there is no field value associated with it.' ) ;
484+ console . error (
485+ `There is an element with attribute "${ toggle_attr } ", but there is no field value associated with it.`
486+ ) ;
485487 return ;
486488 }
487- const form_container = document . querySelector ( `[data-edit-form="${ unique_id } "]` )
489+ const form_container = document . querySelector ( `[data-edit-form="${ unique_id } "]` ) ;
488490 if ( ! form_container ) {
489- console . error ( 'There is an element with attribute "' + toggle_attr + '", but there is no edit form container associated with it.' ) ;
491+ console . error (
492+ `There is an element with attribute "${ toggle_attr } ", but there is no edit form container associated with it.`
493+ ) ;
490494 return ;
491495 }
492- const message_container = document . querySelector ( `[data-edit-message="${ unique_id } "]` )
496+ const message_container = document . querySelector ( `[data-edit-message="${ unique_id } "]` ) ;
493497 if ( ! message_container ) {
494- console . error ( 'There is an element with attribute "' + toggle_attr + '", but there is no message container associated with it.' ) ;
498+ console . error (
499+ `There is an element with attribute "${ toggle_attr } ", but there is no message container associated with it.`
500+ ) ;
495501 return ;
496502 }
497503 const form = form_container . querySelector ( 'form' ) ;
498504 if ( ! form ) {
499- console . error ( 'There is an element with attribute "' + toggle_attr + '", but there is no edit form associated with it.' ) ;
505+ console . error (
506+ `There is an element with attribute "${ toggle_attr } ", but there is no edit form associated with it.`
507+ ) ;
500508 return ;
501509 }
502510
@@ -509,7 +517,7 @@ class App {
509517 field_container . style . display = show_form ? 'none' : 'block' ;
510518 } ) ;
511519
512- form_container . addEventListener ( 'submit' , function ( event ) {
520+ form_container . addEventListener ( 'submit' , ( event ) => {
513521 event . preventDefault ( ) ;
514522 event . stopPropagation ( ) ;
515523 const url = form . action ;
@@ -520,7 +528,7 @@ class App {
520528 const formData = new FormData ( form ) ;
521529
522530 [ ...form_container . querySelectorAll ( 'input,select' ) ]
523- . filter ( el => ! el . hasAttribute ( 'disabled' ) )
531+ . filter ( ( el ) => ! el . hasAttribute ( 'disabled' ) )
524532 . forEach ( ( el ) => {
525533 el . setAttribute ( 'disabled' , 'disabled' ) ;
526534 el . dataset . enableAfterCall = '1' ;
@@ -530,51 +538,55 @@ class App {
530538 method : 'post' ,
531539 body : formData ,
532540 headers : {
533- 'Accept' : 'application/json'
534- }
535- } ) . catch ( ( e ) => {
536- message ( 'error' , e , `HTTP error.` ) ;
537- } ) . then ( ( res ) => {
538- if ( ! res ) {
539- message ( 'error' , res , `Internal error: Empty response.` ) ;
540- return ;
541- }
541+ Accept : 'application/json' ,
542+ } ,
543+ } )
544+ . catch ( ( e ) => {
545+ message ( 'error' , e , 'HTTP error.' ) ;
546+ } )
547+ . then ( ( res ) => {
548+ if ( ! res ) {
549+ message ( 'error' , res , 'Internal error: Empty response.' ) ;
550+ return ;
551+ }
542552
543- if ( res . status !== 200 ) {
544- message ( 'error' , res , ` Form submit error.` ) ;
545- return ;
546- }
553+ if ( res . status !== 200 ) {
554+ message ( 'error' , res , ' Form submit error.' ) ;
555+ return ;
556+ }
547557
548- return res . json ( ) ;
549- } ) . then ( ( json ) => {
550- if ( ! json ) {
551- console . error ( 'No data.' ) ;
552- return ;
553- }
554- if ( ! json . field_content ) {
555- console . error ( 'The property "field_content" was not returned.' ) ;
556- message ( 'error' , json , `Internal error: The field content was not returned.` ) ;
557- return ;
558- }
558+ return res . json ( ) ;
559+ } )
560+ . then ( ( json ) => {
561+ if ( ! json ) {
562+ console . error ( 'No data.' ) ;
563+ return ;
564+ }
565+ if ( ! json . field_content ) {
566+ console . error ( 'The property "field_content" was not returned.' ) ;
567+ message ( 'error' , json , 'Internal error: The field content was not returned.' ) ;
568+ return ;
569+ }
559570
560- console . info ( 'Successful edit' , json ) ;
561- field_container . style . display = 'block' ;
562- form_container . style . display = 'none' ;
563- show_form = false ;
564- field_container . innerHTML = json . field_content ;
565- } ) . finally ( ( ) => {
566- [ ...form_container . querySelectorAll ( 'input,select' ) ]
567- . filter ( el => el . dataset . enableAfterCall !== undefined )
568- . forEach ( ( el ) => el . removeAttribute ( 'disabled' , 'disabled' ) ) ;
569- } ) ;
571+ console . info ( 'Successful edit' , json ) ;
572+ field_container . style . display = 'block' ;
573+ form_container . style . display = 'none' ;
574+ show_form = false ;
575+ field_container . innerHTML = json . field_content ;
576+ } )
577+ . finally ( ( ) => {
578+ [ ...form_container . querySelectorAll ( 'input,select' ) ]
579+ . filter ( ( el ) => el . dataset . enableAfterCall !== undefined )
580+ . forEach ( ( el ) => el . removeAttribute ( 'disabled' , 'disabled' ) ) ;
581+ } ) ;
570582 } ) ;
571583
572584 function message ( type , object , message ) {
573585 let className = 'alert ' ;
574586 if ( type === 'success' ) {
575- className += 'alert-success'
587+ className += 'alert-success' ;
576588 } else if ( type === 'error' ) {
577- className += 'alert-danger'
589+ className += 'alert-danger' ;
578590 } else {
579591 className += 'alert-info' ;
580592 }
0 commit comments