client/merge: add search button

This commit is contained in:
rr- 2017-01-03 21:58:32 +01:00
parent 9edaaffec2
commit 58fabc6e36
3 changed files with 46 additions and 30 deletions

View file

@ -14,9 +14,6 @@
.right-post-container .right-post-container
width: 47% width: 47%
float: right float: right
input[type=text]
width: 8em
margin-top: -2px
.post-mirror .post-mirror
margin-bottom: 1em margin-bottom: 1em
&:after &:after
@ -31,3 +28,10 @@
margin-right: 0.35em margin-right: 0.35em
.target-post, .target-post-content .target-post, .target-post-content
margin: 1em 0 margin: 1em 0
header
margin-bottom: 1em
label
display: inline-block
margin-top: 2px
input[type=text]
width: 6em

View file

@ -1,8 +1,12 @@
<% if (ctx.editable) { %> <header>
<p>Post # <input type='text' pattern='^[0-9]+$' value='<%- ctx.post ? ctx.post.id : '' %>'/></p> <label for='merge-id-<%- ctx.name %>'>Post #</label>
<% } else { %> <% if (ctx.editable) { %>
<p>Post # <input type='text' pattern='^[0-9]+$' value='<%- ctx.post ? ctx.post.id : '' %>' readonly/></p> <input type='text' id='merge-id-<%-ctx.name %>' pattern='^[0-9]+$' value='<%- ctx.post ? ctx.post.id : '' %>'/>
<% } %> <input type='button' value='Search'/>
<% } else { %>
<input type='text' id='merge-id-<%-ctx.name %>' pattern='^[0-9]+$' value='<%- ctx.post ? ctx.post.id : '' %>' readonly/>
<% } %>
</header>
<% if (ctx.post) { %> <% if (ctx.post) { %>
<div class='post-thumbnail'> <div class='post-thumbnail'>

View file

@ -53,25 +53,28 @@ class PostMergeView extends events.EventTarget {
} }
_refreshLeftSide() { _refreshLeftSide() {
views.replaceContent( this._refreshSide(this._leftPost, this._leftSideNode, 'left', false);
this._leftSideNode,
sideTemplate(Object.assign({}, this._ctx, {
post: this._leftPost,
name: 'left',
editable: false})));
} }
_refreshRightSide() { _refreshRightSide() {
views.replaceContent( this._refreshSide(this._rightPost, this._rightSideNode, 'right', true);
this._rightSideNode, }
sideTemplate(Object.assign({}, this._ctx, {
post: this._rightPost,
name: 'right',
editable: true})));
if (this._targetPostFieldNode) { _refreshSide(post, sideNode, sideName, isEditable) {
this._targetPostFieldNode.addEventListener( views.replaceContent(
'keydown', e => this._evtTargetPostFieldKeyDown(e)); sideNode,
sideTemplate(Object.assign({}, this._ctx, {
post: post,
name: sideName,
editable: isEditable})));
let postIdNode = sideNode.querySelector('input[type=text]');
let searchButtonNode = sideNode.querySelector('input[type=button]');
if (isEditable) {
postIdNode.addEventListener(
'keydown', e => this._evtPostSearchFieldKeyDown(e));
searchButtonNode.addEventListener(
'click', e => this._evtPostSearchButtonClick(e, postIdNode));
} }
} }
@ -94,7 +97,7 @@ class PostMergeView extends events.EventTarget {
})); }));
} }
_evtTargetPostFieldKeyDown(e) { _evtPostSearchFieldKeyDown(e) {
const key = e.which; const key = e.which;
if (key !== KEY_RETURN) { if (key !== KEY_RETURN) {
return; return;
@ -103,7 +106,17 @@ class PostMergeView extends events.EventTarget {
e.preventDefault(); e.preventDefault();
this.dispatchEvent(new CustomEvent('select', { this.dispatchEvent(new CustomEvent('select', {
detail: { detail: {
postId: this._targetPostFieldNode.value, postId: e.target.value,
},
}));
}
_evtPostSearchButtonClick(e, textNode) {
e.target.blur();
e.preventDefault();
this.dispatchEvent(new CustomEvent('select', {
detail: {
postId: textNode.value,
}, },
})); }));
} }
@ -119,11 +132,6 @@ class PostMergeView extends events.EventTarget {
get _rightSideNode() { get _rightSideNode() {
return this._hostNode.querySelector('.right-post-container'); return this._hostNode.querySelector('.right-post-container');
} }
get _targetPostFieldNode() {
return this._formNode.querySelector(
'.post-mirror input:not([readonly])[type=text]');
}
} }
module.exports = PostMergeView; module.exports = PostMergeView;