Added query to post list
This commit is contained in:
parent
da41fd7a96
commit
7d8dfd797f
4 changed files with 47 additions and 5 deletions
|
@ -7,6 +7,13 @@
|
|||
margin: 0 auto;
|
||||
}
|
||||
|
||||
#post-list .search {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
#post-list .search input {
|
||||
max-width: 20em;
|
||||
}
|
||||
|
||||
#post-list ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
|
|
|
@ -7,19 +7,24 @@ App.Presenters.PostListPresenter = function(
|
|||
util,
|
||||
promise,
|
||||
auth,
|
||||
router,
|
||||
keyboard,
|
||||
pagerPresenter,
|
||||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
|
||||
var KEY_RETURN = 13;
|
||||
|
||||
var $el = jQuery('#content');
|
||||
var $searchInput;
|
||||
var listTemplate;
|
||||
var itemTemplate;
|
||||
|
||||
var searchArgs;
|
||||
|
||||
function init(args, loaded) {
|
||||
topNavigationPresenter.select('posts');
|
||||
topNavigationPresenter.changeTitle('Posts');
|
||||
searchArgs = util.parseComplexRouteArgs(args.searchArgs);
|
||||
|
||||
promise.waitAll(
|
||||
util.promiseTemplate('post-list'),
|
||||
|
@ -53,16 +58,28 @@ App.Presenters.PostListPresenter = function(
|
|||
function reinit(args, loaded) {
|
||||
loaded();
|
||||
|
||||
var searchArgs = util.parseComplexRouteArgs(args.searchArgs);
|
||||
pagerPresenter.reinit({page: searchArgs.page, searchParams: {query: searchArgs.query, order: searchArgs.order}});
|
||||
searchArgs = util.parseComplexRouteArgs(args.searchArgs);
|
||||
pagerPresenter.reinit({
|
||||
page: searchArgs.page,
|
||||
searchParams: {
|
||||
query: searchArgs.query,
|
||||
order: searchArgs.order}});
|
||||
}
|
||||
|
||||
function render() {
|
||||
$el.html(listTemplate());
|
||||
$searchInput = $el.find('input[name=query]');
|
||||
|
||||
$searchInput.val(searchArgs.query);
|
||||
$searchInput.keydown(searchInputKeyPressed);
|
||||
|
||||
keyboard.keyup('p', function() {
|
||||
$el.find('.posts li a').eq(0).focus();
|
||||
});
|
||||
|
||||
keyboard.keyup('q', function() {
|
||||
$searchInput.eq(0).focus();
|
||||
});
|
||||
}
|
||||
|
||||
function renderPosts(posts, clear) {
|
||||
|
@ -82,6 +99,17 @@ App.Presenters.PostListPresenter = function(
|
|||
}
|
||||
}
|
||||
|
||||
function searchInputKeyPressed(e) {
|
||||
if (e.which !== KEY_RETURN) {
|
||||
return;
|
||||
}
|
||||
|
||||
$searchInput.blur();
|
||||
pagerPresenter.setSearchParams({
|
||||
query: $searchInput.val(),
|
||||
order: searchArgs.order});
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
reinit: reinit,
|
||||
|
@ -90,4 +118,4 @@ App.Presenters.PostListPresenter = function(
|
|||
|
||||
};
|
||||
|
||||
App.DI.register('postListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'router', 'keyboard', 'pagerPresenter', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostListPresenter);
|
||||
App.DI.register('postListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'keyboard', 'pagerPresenter', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostListPresenter);
|
||||
|
|
|
@ -13,6 +13,8 @@ App.Presenters.PostUploadPresenter = function(
|
|||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
|
||||
var KEY_RETURN = 13;
|
||||
|
||||
var $el = jQuery('#content');
|
||||
var $messages;
|
||||
var template;
|
||||
|
@ -72,7 +74,7 @@ App.Presenters.PostUploadPresenter = function(
|
|||
}
|
||||
|
||||
function urlHandlerKeyPressed(e) {
|
||||
if (e.which !== 13) {
|
||||
if (e.which !== KEY_RETURN) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
<div id="post-list">
|
||||
<div class="search">
|
||||
<input type="text" name="query" placeholder="Search query..."/>
|
||||
<button type="submit">Search</button>
|
||||
</div>
|
||||
|
||||
<div class="pagination-target">
|
||||
<div class="wrapper">
|
||||
<ul class="posts">
|
||||
|
|
Loading…
Reference in a new issue