5
5
define ( [
6
6
'jquery' ,
7
7
'underscore' ,
8
- 'uiElement'
9
- ] , function ( $ , _ , Element ) {
8
+ 'uiElement' ,
9
+ 'Magento_Ui/js/modal/alert' ,
10
+ 'mage/translate'
11
+ ] , function ( $ , _ , Element , alert ) {
10
12
'use strict' ;
11
13
12
14
return Element . extend ( {
13
15
defaults : {
14
16
template : 'ui/grid/exportButton' ,
15
17
checked : '' ,
18
+ title : $ . mage . __ ( 'Attention' ) ,
19
+ message : $ . mage . __ ( 'You haven\'t selected any items!' ) ,
20
+
16
21
modules : {
17
22
selections : '${ $.selectProvider }'
18
23
}
@@ -36,23 +41,28 @@ define([
36
41
this . options [ 0 ] . value
37
42
) ;
38
43
}
44
+
39
45
return this ;
40
46
} ,
41
47
42
48
getParams : function ( ) {
43
49
var selections = this . selections ( ) ,
44
- data = selections . getSelections ( ) ,
50
+ data = selections ? selections . getSelections ( ) : { } ,
45
51
itemsType = data . excludeMode ? 'excluded' : 'selected' ,
46
- result = { } ;
52
+ result ;
47
53
48
- result [ 'filters' ] = data . params . filters ;
49
- result [ 'search' ] = data . params . search ;
50
- result [ 'namespace' ] = data . params . namespace ;
51
- result [ itemsType ] = data [ itemsType ] ;
54
+ if ( selections ) {
55
+ result = { } ;
56
+ result . filters = data . params . filters ;
57
+ result . search = data . params . search ;
58
+ result . namespace = data . params . namespace ;
59
+ result [ itemsType ] = data [ itemsType ] ;
52
60
53
- if ( ! result [ itemsType ] . length ) {
54
- result [ itemsType ] = false ;
61
+ if ( ! result [ itemsType ] . length ) {
62
+ result [ itemsType ] = false ;
63
+ }
55
64
}
65
+
56
66
return result ;
57
67
} ,
58
68
@@ -63,16 +73,21 @@ define([
63
73
} ,
64
74
65
75
buildOptionUrl : function ( option ) {
66
- var url = option . url + '?' ;
67
-
68
- return url + $ . param ( this . getParams ( ) ) ;
76
+ return this . getParams ( ) ? option . url + '?' + $ . param ( this . getParams ( ) ) : '' ;
69
77
} ,
70
78
71
79
applyOption : function ( ) {
72
80
var option = this . getActiveOption ( ) ,
73
81
url = this . buildOptionUrl ( option ) ;
74
82
75
- location . href = url ;
83
+ if ( url ) {
84
+ location . href = url ;
85
+ } else {
86
+ alert ( {
87
+ title : this . title ,
88
+ content : this . message
89
+ } ) ;
90
+ }
76
91
}
77
92
} ) ;
78
93
} ) ;
0 commit comments