Skip to content

Commit d2f7d5d

Browse files
committed
Merge pull request #102 from 10gen/INT-533-clear-button
feature(refine-view): INT-533: added clear button
2 parents 989728c + 0d8b8f6 commit d2f7d5d

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/refine-view/index.jade

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
form: .input-group(data-hook='refine-input-group')
33
input.form-control.input-sm(type='text', data-hook='refine-input')
44
span.input-group-btn
5-
button.btn.btn-default.btn-sm(type='button', data-hook='refine-button') Refine
5+
button.btn.btn-info.btn-sm(type='button', data-hook='refine-button') Apply
6+
button.btn.btn-default.btn-sm(type='button', data-hook='reset-button') Reset

src/refine-view/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,28 @@ module.exports = AmpersandView.extend({
1212
default: true
1313
}
1414
},
15+
derived: {
16+
notEmpty: {
17+
deps: ['model.queryString'],
18+
fn: function() {
19+
return this.model.queryString !== '{}';
20+
}
21+
}
22+
},
1523
bindings: {
1624
'model.queryString': {
1725
type: 'value',
1826
hook: 'refine-input'
1927
},
28+
notEmpty: [{
29+
type: 'toggle',
30+
hook: 'reset-button'
31+
}, {
32+
type: 'booleanClass',
33+
hook: 'refine-button',
34+
yes: 'btn-info',
35+
no: 'btn-default'
36+
}],
2037
valid: [
2138
// red input border while query is invalid
2239
{
@@ -35,7 +52,8 @@ module.exports = AmpersandView.extend({
3552
]
3653
},
3754
events: {
38-
'click [data-hook=refine-button]': 'buttonClicked',
55+
'click [data-hook=refine-button]': 'refineClicked',
56+
'click [data-hook=reset-button]': 'resetClicked',
3957
'input [data-hook=refine-input]': 'inputChanged',
4058
'submit form': 'submit'
4159
},
@@ -68,7 +86,11 @@ module.exports = AmpersandView.extend({
6886
}
6987
this.valid = true;
7088
},
71-
buttonClicked: function() {
89+
resetClicked: function() {
90+
this.model.query = new Query();
91+
this.trigger('submit', this);
92+
},
93+
refineClicked: function() {
7294
var queryStr = this._cleanupInput(this.queryByHook('refine-input').value);
7395
var queryObj = new Query(EJSON.parse(queryStr), { parse: true });
7496
this.model.query = queryObj;

src/refine-view/index.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
height: 28px;
1111
& + .input-group-btn {
1212
padding-left: 10px;
13+
14+
&:last-child > .btn {
15+
margin-left: 2px;
16+
}
1317
}
1418
}
1519
}

0 commit comments

Comments
 (0)