@@ -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 . DeadHosts . getAll ,
23
+
24
+ showData : function ( response ) {
25
+ this . showChildView ( 'list_region' , new ListView ( {
26
+ collection : new DeadHostModel . 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 . showNginxDead ( ) ;
36
+ }
37
+ } ) ) ;
38
+
39
+ console . error ( err ) ;
40
+ } ,
41
+
42
+ showEmpty : function ( ) {
43
+ let manage = App . Cache . User . canManage ( 'dead_hosts' ) ;
44
+
45
+ this . showChildView ( 'list_region' , new EmptyView ( {
46
+ title : App . i18n ( 'dead-hosts' , 'empty' ) ,
47
+ subtitle : App . i18n ( 'all-hosts' , 'empty-subtitle' , { manage : manage } ) ,
48
+ link : manage ? App . i18n ( 'dead-hosts' , 'add' ) : null ,
49
+ btn_color : 'danger' ,
50
+ permission : 'dead_hosts' ,
51
+ action : function ( ) {
52
+ App . Controller . showNginxDeadForm ( ) ;
53
+ }
54
+ } ) ) ;
18
55
} ,
19
56
20
57
regions : {
@@ -30,6 +67,17 @@ module.exports = Mn.View.extend({
30
67
'click @ui.help' : function ( e ) {
31
68
e . preventDefault ( ) ;
32
69
App . Controller . showHelp ( App . i18n ( 'dead-hosts' , 'help-title' ) , App . i18n ( 'dead-hosts' , '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' , 'certificate' ] , query )
77
+ . then ( response => this . showData ( response ) )
78
+ . catch ( err => {
79
+ this . showError ( err ) ;
80
+ } ) ;
33
81
}
34
82
} ,
35
83
@@ -40,39 +88,18 @@ module.exports = Mn.View.extend({
40
88
onRender : function ( ) {
41
89
let view = this ;
42
90
43
- App . Api . Nginx . DeadHosts . getAll ( [ 'owner' , 'certificate' ] )
91
+ view . fetch ( [ 'owner' , 'certificate' ] )
44
92
. then ( response => {
45
93
if ( ! view . isDestroyed ( ) ) {
46
94
if ( response && response . length ) {
47
- view . showChildView ( 'list_region' , new ListView ( {
48
- collection : new DeadHostModel . Collection ( response )
49
- } ) ) ;
95
+ view . showData ( response ) ;
50
96
} else {
51
- let manage = App . Cache . User . canManage ( 'dead_hosts' ) ;
52
-
53
- view . showChildView ( 'list_region' , new EmptyView ( {
54
- title : App . i18n ( 'dead-hosts' , 'empty' ) ,
55
- subtitle : App . i18n ( 'all-hosts' , 'empty-subtitle' , { manage : manage } ) ,
56
- link : manage ? App . i18n ( 'dead-hosts' , 'add' ) : null ,
57
- btn_color : 'danger' ,
58
- permission : 'dead_hosts' ,
59
- action : function ( ) {
60
- App . Controller . showNginxDeadForm ( ) ;
61
- }
62
- } ) ) ;
97
+ view . showEmpty ( ) ;
63
98
}
64
99
}
65
100
} )
66
101
. catch ( err => {
67
- view . showChildView ( 'list_region' , new ErrorView ( {
68
- code : err . code ,
69
- message : err . message ,
70
- retry : function ( ) {
71
- App . Controller . showNginxDead ( ) ;
72
- }
73
- } ) ) ;
74
-
75
- console . error ( err ) ;
102
+ view . showError ( err ) ;
76
103
} )
77
104
. then ( ( ) => {
78
105
view . ui . dimmer . removeClass ( 'active' ) ;
0 commit comments