@@ -14,7 +14,44 @@ module.exports = Mn.View.extend({
1414 list_region : '.list-region' ,
1515 add : '.add-item' ,
1616 help : '.help' ,
17- dimmer : '.dimmer'
17+ dimmer : '.dimmer' ,
18+ search : '.search-form' ,
19+ query : 'input[name="source-query"]'
20+ } ,
21+
22+ fetch : App . Api . Nginx . AccessLists . getAll ,
23+
24+ showData : function ( response ) {
25+ this . showChildView ( 'list_region' , new ListView ( {
26+ collection : new AccessListModel . Collection ( response )
27+ } ) ) ;
28+ } ,
29+
30+ showError : function ( err ) {
31+ this . showChildView ( 'list_region' , new ErrorView ( {
32+ code : err . code ,
33+ message : err . message ,
34+ retry : function ( ) {
35+ App . Controller . showNginxAccess ( ) ;
36+ }
37+ } ) ) ;
38+
39+ console . error ( err ) ;
40+ } ,
41+
42+ showEmpty : function ( ) {
43+ let manage = App . Cache . User . canManage ( 'access_lists' ) ;
44+
45+ this . showChildView ( 'list_region' , new EmptyView ( {
46+ title : App . i18n ( 'access-lists' , 'empty' ) ,
47+ subtitle : App . i18n ( 'all-hosts' , 'empty-subtitle' , { manage : manage } ) ,
48+ link : manage ? App . i18n ( 'access-lists' , 'add' ) : null ,
49+ btn_color : 'teal' ,
50+ permission : 'access_lists' ,
51+ action : function ( ) {
52+ App . Controller . showNginxAccessListForm ( ) ;
53+ }
54+ } ) ) ;
1855 } ,
1956
2057 regions : {
@@ -30,6 +67,17 @@ module.exports = Mn.View.extend({
3067 'click @ui.help' : function ( e ) {
3168 e . preventDefault ( ) ;
3269 App . Controller . showHelp ( App . i18n ( 'access-lists' , 'help-title' ) , App . i18n ( 'access-lists' , 'help-content' ) ) ;
70+ } ,
71+
72+ 'submit @ui.search' : function ( e ) {
73+ e . preventDefault ( ) ;
74+ let query = this . ui . query . val ( ) ;
75+
76+ this . fetch ( [ 'owner' , 'items' , 'clients' ] , query )
77+ . then ( response => this . showData ( response ) )
78+ . catch ( err => {
79+ this . showError ( err ) ;
80+ } ) ;
3381 }
3482 } ,
3583
@@ -40,39 +88,18 @@ module.exports = Mn.View.extend({
4088 onRender : function ( ) {
4189 let view = this ;
4290
43- App . Api . Nginx . AccessLists . getAll ( [ 'owner' , 'items' , 'clients' ] )
91+ view . fetch ( [ 'owner' , 'items' , 'clients' ] )
4492 . then ( response => {
4593 if ( ! view . isDestroyed ( ) ) {
4694 if ( response && response . length ) {
47- view . showChildView ( 'list_region' , new ListView ( {
48- collection : new AccessListModel . Collection ( response )
49- } ) ) ;
95+ view . showData ( response ) ;
5096 } else {
51- let manage = App . Cache . User . canManage ( 'access_lists' ) ;
52-
53- view . showChildView ( 'list_region' , new EmptyView ( {
54- title : App . i18n ( 'access-lists' , 'empty' ) ,
55- subtitle : App . i18n ( 'all-hosts' , 'empty-subtitle' , { manage : manage } ) ,
56- link : manage ? App . i18n ( 'access-lists' , 'add' ) : null ,
57- btn_color : 'teal' ,
58- permission : 'access_lists' ,
59- action : function ( ) {
60- App . Controller . showNginxAccessListForm ( ) ;
61- }
62- } ) ) ;
97+ view . showEmpty ( ) ;
6398 }
6499 }
65100 } )
66101 . catch ( err => {
67- view . showChildView ( 'list_region' , new ErrorView ( {
68- code : err . code ,
69- message : err . message ,
70- retry : function ( ) {
71- App . Controller . showNginxAccess ( ) ;
72- }
73- } ) ) ;
74-
75- console . error ( err ) ;
102+ view . showError ( err ) ;
76103 } )
77104 . then ( ( ) => {
78105 view . ui . dimmer . removeClass ( 'active' ) ;
0 commit comments