@@ -12,39 +12,68 @@ module.exports = Mn.View.extend({
1212
1313 ui : {
1414 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+ } ) ) ;
1645 } ,
1746
1847 regions : {
1948 list_region : '@ui.list_region'
2049 } ,
2150
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+
2264 onRender : function ( ) {
2365 let view = this ;
2466
25- App . Api . AuditLog . getAll ( [ 'user' ] )
67+ view . fetch ( [ 'user' ] )
2668 . then ( response => {
2769 if ( ! view . isDestroyed ( ) && response && response . length ) {
28- view . showChildView ( 'list_region' , new ListView ( {
29- collection : new AuditLogModel . Collection ( response )
30- } ) ) ;
70+ view . showData ( response ) ;
3171 } 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 ( ) ;
3673 }
3774 } )
3875 . 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 ) ;
4877 } )
4978 . then ( ( ) => {
5079 view . ui . dimmer . removeClass ( 'active' ) ;
0 commit comments