@@ -7,33 +7,23 @@ define([
77 'jquery' ,
88 'uiComponent' ,
99 'mage/translate' ,
10- 'text!Magento_MediaGalleryUi/template/grid/massactions/cancelButton .html'
11- ] , function ( $ , Component , $t , cancelMassActionButton ) {
10+ 'text!Magento_MediaGalleryUi/template/grid/massactions/massactionButtons .html'
11+ ] , function ( $ , Component , $t , massactionButtons ) {
1212 'use strict' ;
1313
1414 return Component . extend ( {
1515 defaults : {
16- pageActionsSelector : '.page-actions-buttons' ,
1716 gridSelector : '[data-id="media-gallery-masonry-grid"]' ,
18- originDeleteSelector : null ,
19- originCancelEvent : null ,
20- cancelMassactionButton : cancelMassActionButton ,
21- isCancelButtonInserted : false ,
22- deleteButtonSelector : '#delete_massaction' ,
23- addSelectedButtonSelector : '#add_selected' ,
24- cancelMassactionButtonSelector : '#cancel' ,
2517 standAloneTitle : 'Manage Gallery' ,
2618 slidePanelTitle : 'Media Gallery' ,
2719 defaultTitle : null ,
28- contextButtonSelector : '.three-dots' ,
29- buttonsIds : [
30- '#delete_folder' ,
31- '#create_folder' ,
32- '#upload_image' ,
33- '#search_adobe_stock' ,
34- '.three-dots' ,
35- '#add_selected'
36- ] ,
20+ are : null ,
21+ standAloneArea : 'standalone' ,
22+ slidepanelArea : 'slidepanel' ,
23+ massactionButtonsSelector : '.massaction-buttons' ,
24+ buttonsSelectorStandalone : '.page-actions-buttons' ,
25+ buttonsSelectorSlidePanel : '.page-actions.floating-header' ,
26+ buttons : '.page-main-actions :button' ,
3727 massactionModeTitle : $t ( 'Select Images to Delete' )
3828 } ,
3929
@@ -62,7 +52,6 @@ define([
6252 * Hide or show buttons per active mode.
6353 */
6454 switchButtons : function ( ) {
65-
6655 if ( this . massActionMode ( ) ) {
6756 this . activateMassactionButtonView ( ) ;
6857 } else {
@@ -74,66 +63,40 @@ define([
7463 * Sets buttons to default regular -mode view.
7564 */
7665 revertButtonsToDefaultView : function ( ) {
77- $ ( this . deleteButtonSelector ) . replaceWith ( this . originDeleteSelector ) ;
78-
79- if ( ! this . isCancelButtonInserted ) {
80- $ ( '#cancel_massaction' ) . replaceWith ( this . originCancelEvent ) ;
81- } else {
82- $ ( this . cancelMassactionButtonSelector ) . addClass ( 'no-display' ) ;
83- $ ( '#cancel_massaction' ) . remove ( ) ;
84- }
85-
86- $ . each ( this . buttonsIds , function ( key , value ) {
87- $ ( value ) . removeClass ( 'no-display' ) ;
88- } ) ;
89-
90- $ ( this . addSelectedButtonSelector ) . addClass ( 'no-display' ) ;
91- $ ( this . deleteButtonSelector )
92- . addClass ( 'media-gallery-actions-buttons' )
93- . removeClass ( 'primary' ) ;
66+ $ ( this . buttons ) . removeClass ( 'no-display' ) ;
67+ $ ( this . massactionButtonsSelector ) . remove ( ) ;
9468 } ,
9569
9670 /**
9771 * Activate mass action buttons view
9872 */
9973 activateMassactionButtonView : function ( ) {
100- this . originDeleteSelector = $ ( this . deleteButtonSelector ) . clone ( ) ;
101- $ ( this . originDeleteSelector ) . click ( function ( ) {
102- $ ( window ) . trigger ( 'massAction.MediaGallery' ) ;
103- } ) ;
104- this . originCancelEvent = $ ( '#cancel' ) . clone ( true , true ) ;
74+ var buttonsContainer ;
10575
106- $ . each ( this . buttonsIds , function ( key , value ) {
107- $ ( value ) . addClass ( 'no-display' ) ;
108- } ) ;
76+ $ ( this . buttons ) . addClass ( 'no-display' ) ;
10977
110- $ ( this . deleteButtonSelector )
111- . removeClass ( 'media-gallery-actions-buttons' )
112- . text ( $t ( 'Delete Selected' ) )
113- . addClass ( 'primary' ) ;
114-
115- if ( ! $ ( this . cancelMassactionButtonSelector ) . length ) {
116- $ ( this . pageActionsSelector ) . append ( this . cancelMassactionButton ) ;
117- this . isCancelButtonInserted = true ;
118- } else {
119- $ ( this . cancelMassactionButtonSelector ) . replaceWith ( this . cancelMassactionButton ) ;
120- }
121- $ ( '#cancel_massaction' ) . on ( 'click' , function ( ) {
122- $ ( window ) . trigger ( 'terminateMassAction.MediaGallery' ) ;
123- } ) . applyBindings ( ) ;
124-
125- $ ( this . deleteButtonSelector ) . off ( 'click' ) . on ( 'click' , function ( ) {
126- $ ( this . deleteButtonSelector ) . trigger ( 'massDelete' ) ;
127- } . bind ( this ) ) ;
78+ buttonsContainer = this . area === this . standAloneArea ?
79+ this . buttonsSelectorStandalone :
80+ this . buttonsSelectorSlidePanel ;
12881
82+ $ ( buttonsContainer ) . append ( massactionButtons ) ;
83+ $ ( this . massactionButtonsSelector ) . applyBindings ( ) ;
12984 } ,
13085
13186 /**
13287 * Change page title per active mode.
13388 */
13489 changePageTitle : function ( ) {
13590 var title = $ ( 'h1:contains(' + this . standAloneTitle + ')' ) ,
136- titleSelector = title . length === 1 ? title : $ ( 'h1:contains(' + this . slidePanelTitle + ')' ) ;
91+ titleSelector ;
92+
93+ if ( title . length === 1 ) {
94+ titleSelector = title ;
95+ this . area = this . standAloneArea ;
96+ } else {
97+ titleSelector = $ ( 'h1:contains(' + this . slidePanelTitle + ')' ) ;
98+ this . area = this . slidepanelArea ;
99+ }
137100
138101 if ( this . massActionMode ( ) ) {
139102 this . defaultTitle = titleSelector . text ( ) ;
0 commit comments