@@ -14,7 +14,44 @@ module.exports = Mn.View.extend({
14
14
list_region : '.list-region' ,
15
15
add : '.add-item' ,
16
16
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
+ } ) ) ;
18
55
} ,
19
56
20
57
regions : {
@@ -31,6 +68,17 @@ module.exports = Mn.View.extend({
31
68
'click @ui.help' : function ( e ) {
32
69
e . preventDefault ( ) ;
33
70
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
+ } ) ;
34
82
}
35
83
} ,
36
84
@@ -41,39 +89,18 @@ module.exports = Mn.View.extend({
41
89
onRender : function ( ) {
42
90
let view = this ;
43
91
44
- App . Api . Nginx . Certificates . getAll ( [ 'owner' ] )
92
+ view . fetch ( [ 'owner' ] )
45
93
. then ( response => {
46
94
if ( ! view . isDestroyed ( ) ) {
47
95
if ( response && response . length ) {
48
- view . showChildView ( 'list_region' , new ListView ( {
49
- collection : new CertificateModel . Collection ( response )
50
- } ) ) ;
96
+ view . showData ( response ) ;
51
97
} 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 ( ) ;
64
99
}
65
100
}
66
101
} )
67
102
. 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 ) ;
77
104
} )
78
105
. then ( ( ) => {
79
106
view . ui . dimmer . removeClass ( 'active' ) ;
0 commit comments