Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #726 from cbmi/issue-678
Browse files Browse the repository at this point in the history
Allow negation/exclusion for searchable fields
  • Loading branch information
bruth committed Oct 14, 2014
2 parents af92fda + 04184e8 commit bd45a47
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
22 changes: 19 additions & 3 deletions src/js/cilantro/ui/controls/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ define([
searchPaginator: SearchPaginator,

events: {
'click [data-action=clear]': 'clearValues'
'click [data-action=clear]': 'clearValues',
'change [name=exclude]': 'change'
},

regions: {
Expand All @@ -150,6 +151,10 @@ define([
values: values.ValueList
},

ui: {
excludeCheckbox: '[name=exclude]'
},

initialize: function() {
// Initialize a new collection of values for use by the
// two regions. This is shared between the source data
Expand Down Expand Up @@ -215,12 +220,23 @@ define([
if (this.model) return this.model.id;
},

// This is currently always an 'in', however 'not in' may be
// desirable as well.
getOperator: function() {
if (this.ui.excludeCheckbox.prop('checked')) {
return '-in';
}

return 'in';
},

setOperator: function(operator) {
if (operator === '-in') {
this.ui.excludeCheckbox.prop('checked', true);
}
else {
this.ui.excludeCheckbox.prop('checked', false);
}
},

// Returns an array of objects with value and label attributes.
// These are returned as is to enable correct repopulation.
getValue: function() {
Expand Down
25 changes: 22 additions & 3 deletions src/scss/views/_field-value-search.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
.field-value-search {
.paginator {
text-align: right;
}
.toolbar {
.page-numbers {
float: right;
padding: 0px;
}

.btn-danger {
float: right;
}

.exclude-container {
display: inline-block;
}

.exclude-checkbox {
padding: 0px;
margin: 0px;
width: 12px;
height: 12px;
}

.exclude-label {
margin-left: 5px;
font-size: 13px;
vertical-align: middle;
}
}
}
16 changes: 11 additions & 5 deletions src/templates/controls/search/layout.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<div class=row-fluid>
<div class='span6'>
<div class='toolbar paginator-region'></div>
<div class=search-region></div>
<div class=browse-region></div>
</div>
<div class=span6>
<div class=toolbar>
<div class=exclude-container>
<input class=exclude-checkbox type=checkbox name=exclude />
<span class=exclude-label>Exclude selected values</span>
</div>
<button type=button data-action=clear class='btn btn-mini btn-danger'>
<i class='icon-remove icon-white'></i>Clear
</button>
<div class=paginator-region></div>
</div>
<div class=search-region></div>
<div class=browse-region></div>
</div>
<div class='span6 values-region'></div>
<div class=values-region></div>
</div>
</div>

0 comments on commit bd45a47

Please sign in to comment.