Skip to content

Commit d3a5a3d

Browse files
Add search feature to Users
1 parent 366fcf0 commit d3a5a3d

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

frontend/js/app/users/main.ejs

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
<div class="card-header">
44
<h3 class="card-title"><%- i18n('users', 'title') %></h3>
55
<div class="card-options">
6+
<form class="search-form" role="search">
7+
<div class="input-icon">
8+
<span class="input-icon-addon">
9+
<i class="fe fe-search"></i>
10+
</span>
11+
<input name="source-query" type="text" value="" class="form-control form-control-sm" placeholder="Search User…" aria-label="Search in Users">
12+
</div>
13+
</form>
614
<a href="#" class="btn btn-outline-teal btn-sm ml-2 add-item"><%- i18n('users', 'add') %></a>
715
</div>
816
</div>

frontend/js/app/users/main.js

+37-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,29 @@ module.exports = Mn.View.extend({
1212
ui: {
1313
list_region: '.list-region',
1414
add: '.add-item',
15-
dimmer: '.dimmer'
15+
dimmer: '.dimmer',
16+
search: '.search-form',
17+
query: 'input[name="source-query"]'
18+
},
19+
20+
fetch: App.Api.Users.getAll,
21+
22+
showData: function(response) {
23+
this.showChildView('list_region', new ListView({
24+
collection: new UserModel.Collection(response)
25+
}));
26+
},
27+
28+
showError: function(err) {
29+
this.showChildView('list_region', new ErrorView({
30+
code: err.code,
31+
message: err.message,
32+
retry: function () {
33+
App.Controller.showUsers();
34+
}
35+
}));
36+
37+
console.error(err);
1638
},
1739

1840
regions: {
@@ -23,30 +45,31 @@ module.exports = Mn.View.extend({
2345
'click @ui.add': function (e) {
2446
e.preventDefault();
2547
App.Controller.showUserForm(new UserModel.Model());
48+
},
49+
50+
'submit @ui.search': function (e) {
51+
e.preventDefault();
52+
let query = this.ui.query.val();
53+
54+
this.fetch(['permissions'], query)
55+
.then(response => this.showData(response))
56+
.catch(err => {
57+
this.showError(err);
58+
});
2659
}
2760
},
2861

2962
onRender: function () {
3063
let view = this;
3164

32-
App.Api.Users.getAll(['permissions'])
65+
view.fetch(['permissions'])
3366
.then(response => {
3467
if (!view.isDestroyed() && response && response.length) {
35-
view.showChildView('list_region', new ListView({
36-
collection: new UserModel.Collection(response)
37-
}));
68+
view.showData(response);
3869
}
3970
})
4071
.catch(err => {
41-
view.showChildView('list_region', new ErrorView({
42-
code: err.code,
43-
message: err.message,
44-
retry: function () {
45-
App.Controller.showUsers();
46-
}
47-
}));
48-
49-
console.error(err);
72+
view.showError(err);
5073
})
5174
.then(() => {
5275
view.ui.dimmer.removeClass('active');

0 commit comments

Comments
 (0)