@@ -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 . Certificates . getAll ,
23+
24+ showData : function ( response ) {
25+ this . showChildView ( 'list_region' , new ListView ( {
26+ collection : new CertificateModel . 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 . showNginxCertificates ( ) ;
36+ }
37+ } ) ) ;
38+
39+ console . error ( err ) ;
40+ } ,
41+
42+ showEmpty : function ( ) {
43+ let manage = App . Cache . User . canManage ( 'certificates' ) ;
44+
45+ this . showChildView ( 'list_region' , new EmptyView ( {
46+ title : App . i18n ( 'certificates' , 'empty' ) ,
47+ subtitle : App . i18n ( 'all-hosts' , 'empty-subtitle' , { manage : manage } ) ,
48+ link : manage ? App . i18n ( 'certificates' , 'add' ) : null ,
49+ btn_color : 'pink' ,
50+ permission : 'certificates' ,
51+ action : function ( ) {
52+ App . Controller . showNginxCertificateForm ( ) ;
53+ }
54+ } ) ) ;
1855 } ,
1956
2057 regions : {
@@ -31,6 +68,17 @@ module.exports = Mn.View.extend({
3168 'click @ui.help' : function ( e ) {
3269 e . preventDefault ( ) ;
3370 App . Controller . showHelp ( App . i18n ( 'certificates' , 'help-title' ) , App . i18n ( 'certificates' , 'help-content' ) ) ;
71+ } ,
72+
73+ 'submit @ui.search' : function ( e ) {
74+ e . preventDefault ( ) ;
75+ let query = this . ui . query . val ( ) ;
76+
77+ this . fetch ( [ 'owner' ] , query )
78+ . then ( response => this . showData ( response ) )
79+ . catch ( err => {
80+ this . showError ( err ) ;
81+ } ) ;
3482 }
3583 } ,
3684
@@ -41,39 +89,18 @@ module.exports = Mn.View.extend({
4189 onRender : function ( ) {
4290 let view = this ;
4391
44- App . Api . Nginx . Certificates . getAll ( [ 'owner' ] )
92+ view . fetch ( [ 'owner' ] )
4593 . then ( response => {
4694 if ( ! view . isDestroyed ( ) ) {
4795 if ( response && response . length ) {
48- view . showChildView ( 'list_region' , new ListView ( {
49- collection : new CertificateModel . Collection ( response )
50- } ) ) ;
96+ view . showData ( response ) ;
5197 } else {
52- let manage = App . Cache . User . canManage ( 'certificates' ) ;
53-
54- view . showChildView ( 'list_region' , new EmptyView ( {
55- title : App . i18n ( 'certificates' , 'empty' ) ,
56- subtitle : App . i18n ( 'all-hosts' , 'empty-subtitle' , { manage : manage } ) ,
57- link : manage ? App . i18n ( 'certificates' , 'add' ) : null ,
58- btn_color : 'pink' ,
59- permission : 'certificates' ,
60- action : function ( ) {
61- App . Controller . showNginxCertificateForm ( ) ;
62- }
63- } ) ) ;
98+ view . showEmpty ( ) ;
6499 }
65100 }
66101 } )
67102 . catch ( err => {
68- view . showChildView ( 'list_region' , new ErrorView ( {
69- code : err . code ,
70- message : err . message ,
71- retry : function ( ) {
72- App . Controller . showNginxCertificates ( ) ;
73- }
74- } ) ) ;
75-
76- console . error ( err ) ;
103+ view . showError ( err ) ;
77104 } )
78105 . then ( ( ) => {
79106 view . ui . dimmer . removeClass ( 'active' ) ;
0 commit comments