Skip to content

Commit 515c481

Browse files
committed
fixed search, added clear button
1 parent 0e343b9 commit 515c481

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

openid-connect-server-webapp/src/main/webapp/resources/js/client.js

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,28 @@ var ClientModel = Backbone.Model.extend({
9797

9898
matches:function(term) {
9999
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+
}
107122
} else {
108123
return true;
109124
}
@@ -284,7 +299,8 @@ var ClientListView = Backbone.View.extend({
284299
events:{
285300
"click .new-client":"newClient",
286301
"click .refresh-table":"refreshTable",
287-
'keyup .search-query':'searchTable'
302+
'keyup .search-query':'searchTable',
303+
'click .form-search button':'clearSearch'
288304
},
289305

290306
newClient:function (e) {
@@ -322,9 +338,19 @@ var ClientListView = Backbone.View.extend({
322338
if (this.filteredModel.length > 0) {
323339
$('#client-table', this.el).show();
324340
$('#client-table-empty', this.el).hide();
341+
$('#client-table-search-empty', this.el).hide();
325342
} 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+
}
328354
}
329355
},
330356

@@ -359,18 +385,20 @@ var ClientListView = Backbone.View.extend({
359385
this.filteredModel = this.model;
360386
}
361387

362-
console.log(this.filteredModel);
363-
364388
// clear out the table
365389
$('tbody', this.el).html('');
366390

367391
// re-render the table
368392
this.renderInner();
369393

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();
373399
}
400+
401+
374402
});
375403

376404
var ClientFormView = Backbone.View.extend({

openid-connect-server-webapp/src/main/webapp/resources/template/client.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,19 @@
8484
<div class="well well-small">
8585
<button class="btn btn-small refresh-table"><i class="icon-refresh"></i> Refresh</button> &nbsp;
8686
<button class="btn btn-small btn-primary new-client"><i class="icon-plus icon-white"></i> New Client</button>
87-
<input type="text" class="search-query pull-right" placeholder="Search...">
87+
<div class="form-search pull-right">
88+
<div class="input-append">
89+
<input type="text" class="search-query" placeholder="Search...">
90+
<button class="btn">&times;</button>
91+
</div>
92+
</div>
8893
</div>
8994

95+
96+
<div id="client-table-search-empty" class="alert alert-warning">
97+
There are no clients that match your search criteria.
98+
</div>
99+
90100
<div id="client-table-empty" class="alert alert-info">
91101
There are no registered clients on this server.
92102
</div>

0 commit comments

Comments
 (0)