Skip to content

Commit

Permalink
series: Add an input field to series the series name
Browse files Browse the repository at this point in the history
By popular demand, it's time to implement that filter!

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
Damien Lespiau committed Feb 25, 2016
1 parent 59b437a commit 8dfc030
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
44 changes: 44 additions & 0 deletions htdocs/js/patchwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,50 @@ var pw = (function() {
return o;
};

/* a specialized filter for the search input */
exports.create_search_filter = function(config) {
var o = {};

$.extend(o, config);
$.extend(o, filter_mixin);

o.refresh_active = function() {
if (this.is_active) {
$('#' + this.name + '-filter .btn-link').fadeIn();
} else {
$('#' + this.name + '-filter .btn-link').fadeOut();
}
};

/* install a few call backs */
$('#' + o.name + '-form').submit(function(e) {
e.preventDefault();
if (!o.can_submit())
return;

o.set_filter(o.table);
o.table.refresh();
o.set_active(true);
});

$('#' + o.name + '-filter .btn-default').click(function(e) {
$('#' + o.name + '-form').submit();
});

$('#' + o.name + '-filter .btn-link').click(function(e) {
e.preventDefault();
e.stopPropagation();
o._clear_filter();
});

/* initialize the filter */
o.init();
o.clear_filter(o.table);
o.set_active(false);
o.table.add_filter(o);

};

/*
* table: the table the action applies to
* name: name of the action, used to lookup HTML elements
Expand Down
23 changes: 23 additions & 0 deletions htdocs/js/series-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,29 @@ $(function () {
},
});

/* tests filter */
pw.create_search_filter({
table: series_table,
name: 'search',
init: function() {
this.input = $('#search-series');
},
set_filter: function(table) {
table.set_filter('name', this.input.val());
},
clear_filter: function(table) {
this.input.val('');
table.set_filter('name', null);
},
can_submit: function() {
var val = this.input.val();
return val && val.length > 0;
},
humanize: function() {
return 'containing "' + this.input.val() + '"';
},
});

/* reviewer action */
pw.create_action({
table: series_table,
Expand Down
10 changes: 10 additions & 0 deletions patchwork/templates/patchwork/series-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ <h1>Series</h1>
</li>
</ul>
</li>
<li id="search-filter">
<form id="search-form" class="navbar-form navbar-left" role="search">
<div class="input-group">
<input id="search-series" type="text" style="width:20em;"
class="form-control" placeholder="Search series title">
<a class="input-group-addon btn btn-default">Search</a>
</div>
<button type="button" class="btn btn-link" style="display:none;">Clear search</button>
</form>
</li>
</ul>
<div class="btn-group navbar-btn" id="serieslist-actions" style="display:none;">
<div class="btn-group" style="margin-left: 20px">
Expand Down

0 comments on commit 8dfc030

Please sign in to comment.