@@ -12,39 +12,68 @@ module.exports = Mn.View.extend({
12
12
13
13
ui : {
14
14
list_region : '.list-region' ,
15
- dimmer : '.dimmer'
15
+ dimmer : '.dimmer' ,
16
+ search : '.search-form' ,
17
+ query : 'input[name="source-query"]'
18
+ } ,
19
+
20
+ fetch : App . Api . AuditLog . getAll ,
21
+
22
+ showData : function ( response ) {
23
+ this . showChildView ( 'list_region' , new ListView ( {
24
+ collection : new AuditLogModel . Collection ( response )
25
+ } ) ) ;
26
+ } ,
27
+
28
+ showError : function ( err ) {
29
+ this . showChildView ( 'list_region' , new ErrorView ( {
30
+ code : err . code ,
31
+ message : err . message ,
32
+ retry : function ( ) {
33
+ App . Controller . showAuditLog ( ) ;
34
+ }
35
+ } ) ) ;
36
+
37
+ console . error ( err ) ;
38
+ } ,
39
+
40
+ showEmpty : function ( ) {
41
+ this . showChildView ( 'list_region' , new EmptyView ( {
42
+ title : App . i18n ( 'audit-log' , 'empty' ) ,
43
+ subtitle : App . i18n ( 'audit-log' , 'empty-subtitle' )
44
+ } ) ) ;
16
45
} ,
17
46
18
47
regions : {
19
48
list_region : '@ui.list_region'
20
49
} ,
21
50
51
+ events : {
52
+ 'submit @ui.search' : function ( e ) {
53
+ e . preventDefault ( ) ;
54
+ let query = this . ui . query . val ( ) ;
55
+
56
+ this . fetch ( [ 'user' ] , query )
57
+ . then ( response => this . showData ( response ) )
58
+ . catch ( err => {
59
+ this . showError ( err ) ;
60
+ } ) ;
61
+ }
62
+ } ,
63
+
22
64
onRender : function ( ) {
23
65
let view = this ;
24
66
25
- App . Api . AuditLog . getAll ( [ 'user' ] )
67
+ view . fetch ( [ 'user' ] )
26
68
. then ( response => {
27
69
if ( ! view . isDestroyed ( ) && response && response . length ) {
28
- view . showChildView ( 'list_region' , new ListView ( {
29
- collection : new AuditLogModel . Collection ( response )
30
- } ) ) ;
70
+ view . showData ( response ) ;
31
71
} else {
32
- view . showChildView ( 'list_region' , new EmptyView ( {
33
- title : App . i18n ( 'audit-log' , 'empty' ) ,
34
- subtitle : App . i18n ( 'audit-log' , 'empty-subtitle' )
35
- } ) ) ;
72
+ view . showEmpty ( ) ;
36
73
}
37
74
} )
38
75
. catch ( err => {
39
- view . showChildView ( 'list_region' , new ErrorView ( {
40
- code : err . code ,
41
- message : err . message ,
42
- retry : function ( ) {
43
- App . Controller . showAuditLog ( ) ;
44
- }
45
- } ) ) ;
46
-
47
- console . error ( err ) ;
76
+ view . showError ( err ) ;
48
77
} )
49
78
. then ( ( ) => {
50
79
view . ui . dimmer . removeClass ( 'active' ) ;
0 commit comments