@@ -97,13 +97,28 @@ var ClientModel = Backbone.Model.extend({
97
97
98
98
matches :function ( term ) {
99
99
if ( term ) {
100
- return ( this . get ( 'clientId' ) . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 )
101
- || ( this . get ( 'clientName' ) != null && this . get ( 'clientName' ) . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 )
102
- || ( this . get ( 'clientDescription' ) != null && this . get ( 'clientDescription' ) . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 )
103
- || ( this . get ( 'clientUri' ) != null && this . get ( 'clientUri' ) . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 )
104
- || ( this . get ( 'contacts' ) != null && _ . filter ( this . get ( 'contacts' ) , function ( item ) {
105
- return item . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 ;
106
- } ) ) ;
100
+ if ( this . get ( 'clientId' ) . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 ) {
101
+ return true ;
102
+ } else if ( this . get ( 'clientName' ) != null && this . get ( 'clientName' ) . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 ) {
103
+ return true ;
104
+ } else if ( this . get ( 'clientDescription' ) != null && this . get ( 'clientDescription' ) . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 ) {
105
+ return true ;
106
+ } else if ( this . get ( 'clientUri' ) != null && this . get ( 'clientUri' ) . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 ) {
107
+ return true ;
108
+ } else {
109
+ if ( this . get ( 'contacts' ) != null ) {
110
+ var f = _ . filter ( this . get ( 'contacts' ) , function ( item ) {
111
+ return item . toLowerCase ( ) . indexOf ( term . toLowerCase ( ) ) != - 1 ;
112
+ } ) ;
113
+ if ( f . length > 0 ) {
114
+ return true ;
115
+ } else {
116
+ return false ;
117
+ }
118
+ } else {
119
+ return false ;
120
+ }
121
+ }
107
122
} else {
108
123
return true ;
109
124
}
@@ -284,7 +299,8 @@ var ClientListView = Backbone.View.extend({
284
299
events :{
285
300
"click .new-client" :"newClient" ,
286
301
"click .refresh-table" :"refreshTable" ,
287
- 'keyup .search-query' :'searchTable'
302
+ 'keyup .search-query' :'searchTable' ,
303
+ 'click .form-search button' :'clearSearch'
288
304
} ,
289
305
290
306
newClient :function ( e ) {
@@ -322,9 +338,19 @@ var ClientListView = Backbone.View.extend({
322
338
if ( this . filteredModel . length > 0 ) {
323
339
$ ( '#client-table' , this . el ) . show ( ) ;
324
340
$ ( '#client-table-empty' , this . el ) . hide ( ) ;
341
+ $ ( '#client-table-search-empty' , this . el ) . hide ( ) ;
325
342
} else {
326
- $ ( '#client-table' , this . el ) . hide ( ) ;
327
- $ ( '#client-table-empty' , this . el ) . show ( ) ;
343
+ if ( this . model . length > 0 ) {
344
+ // there's stuff in the model but it's been filtered out
345
+ $ ( '#client-table' , this . el ) . hide ( ) ;
346
+ $ ( '#client-table-empty' , this . el ) . hide ( ) ;
347
+ $ ( '#client-table-search-empty' , this . el ) . show ( ) ;
348
+ } else {
349
+ // we're empty
350
+ $ ( '#client-table' , this . el ) . hide ( ) ;
351
+ $ ( '#client-table-empty' , this . el ) . show ( ) ;
352
+ $ ( '#client-table-search-empty' , this . el ) . hide ( ) ;
353
+ }
328
354
}
329
355
} ,
330
356
@@ -359,18 +385,20 @@ var ClientListView = Backbone.View.extend({
359
385
this . filteredModel = this . model ;
360
386
}
361
387
362
- console . log ( this . filteredModel ) ;
363
-
364
388
// clear out the table
365
389
$ ( 'tbody' , this . el ) . html ( '' ) ;
366
390
367
391
// re-render the table
368
392
this . renderInner ( ) ;
369
393
370
- //$('.search-query', this.el).val(term);
371
- //$('.search-query', this.el).focus();
372
-
394
+ } ,
395
+
396
+ clearSearch :function ( e ) {
397
+ $ ( '.search-query' , this . el ) . val ( '' ) ;
398
+ this . searchTable ( ) ;
373
399
}
400
+
401
+
374
402
} ) ;
375
403
376
404
var ClientFormView = Backbone . View . extend ( {
0 commit comments