@@ -17,7 +17,8 @@ jQuery(document).ready(function($) {
1717 invalidUrlMessage : 'Veuillez saisir une URL valide.' ,
1818 sameUrlMessage : "La nouvelle URL doit être différente de l'URL actuelle." ,
1919 genericError : 'Une erreur est survenue. Veuillez réessayer.' ,
20- successAnnouncement : 'La ligne a été mise à jour avec succès.'
20+ successAnnouncement : 'La ligne a été mise à jour avec succès.' ,
21+ noItemsMessage : 'Aucun élément à afficher.'
2122 } ;
2223
2324 var messages = $ . extend ( { } , defaultMessages , window . blcAdminMessages || { } ) ;
@@ -396,6 +397,38 @@ jQuery(document).ready(function($) {
396397 return $candidate . length ? $candidate [ 0 ] : null ;
397398 }
398399
400+ function determineColumnCount ( $tbody , $row ) {
401+ var columnCount = 0 ;
402+ var $normalizedTbody = $tbody && $tbody . jquery ? $tbody : $ ( ) ;
403+ var $table = $normalizedTbody . length ? $normalizedTbody . closest ( 'table' ) : $ ( ) ;
404+
405+ if ( $table . length ) {
406+ var $headerCells = $table . find ( 'thead tr:first' ) . children ( 'th:visible, td:visible' ) ;
407+ columnCount = $headerCells . length ;
408+
409+ if ( ! columnCount ) {
410+ $headerCells = $table . find ( 'thead tr:first' ) . children ( 'th, td' ) ;
411+ columnCount = $headerCells . length ;
412+ }
413+ }
414+
415+ var $normalizedRow = $row && $row . jquery ? $row : $ ( ) ;
416+
417+ if ( ! columnCount && $normalizedRow . length ) {
418+ columnCount = $normalizedRow . children ( 'td, th' ) . length ;
419+ }
420+
421+ if ( ! columnCount && $table . length ) {
422+ columnCount = $table . find ( 'tr' ) . first ( ) . children ( 'td, th' ) . length ;
423+ }
424+
425+ if ( ! columnCount ) {
426+ columnCount = 1 ;
427+ }
428+
429+ return columnCount ;
430+ }
431+
399432 function handleSuccessfulResponse ( response , row , helpers ) {
400433 var $row = row && row . jquery ? row : $ ( row ) ;
401434
@@ -409,7 +442,50 @@ jQuery(document).ready(function($) {
409442
410443 if ( $row && $row . length ) {
411444 $row . fadeOut ( 300 , function ( ) {
412- $ ( this ) . remove ( ) ;
445+ var $currentRow = $ ( this ) ;
446+ var $tbody = $currentRow . closest ( 'tbody' ) ;
447+ $currentRow . remove ( ) ;
448+
449+ if ( ! $tbody . length ) {
450+ $tbody = $ ( '#the-list' ) ;
451+ }
452+
453+ var $remainingRows = $tbody . children ( 'tr' ) . filter ( function ( ) {
454+ var $candidate = $ ( this ) ;
455+ return ! $candidate . hasClass ( 'no-items' ) && ! $candidate . hasClass ( 'inline-edit-row' ) ;
456+ } ) ;
457+
458+ var messageRow = null ;
459+
460+ if ( ! $remainingRows . length ) {
461+ var messageText = messages . noItemsMessage || '' ;
462+
463+ if ( messageText ) {
464+ var colspan = determineColumnCount ( $tbody , $currentRow ) ;
465+ var $existingNoItems = $tbody . children ( 'tr.no-items' ) ;
466+ if ( $existingNoItems . length ) {
467+ $existingNoItems . remove ( ) ;
468+ }
469+
470+ messageRow = $ ( '<tr>' , { class : 'no-items' } ) ;
471+ $ ( '<td>' , { colspan : colspan } ) . text ( messageText ) . appendTo ( messageRow ) ;
472+ $tbody . append ( messageRow ) ;
473+ }
474+ }
475+
476+ $ ( document ) . trigger ( 'blcAdmin:listUpdated' , {
477+ response : response ,
478+ tbody : $tbody ,
479+ table : $tbody . closest ( 'table' ) ,
480+ messageRow : messageRow
481+ } ) ;
482+ } ) ;
483+ } else {
484+ $ ( document ) . trigger ( 'blcAdmin:listUpdated' , {
485+ response : response ,
486+ tbody : $ ( '#the-list' ) ,
487+ table : $ ( '#the-list' ) . closest ( 'table' ) ,
488+ messageRow : null
413489 } ) ;
414490 }
415491 }
0 commit comments