client/posts: add controls for reordering uploads
This commit is contained in:
parent
280a55046a
commit
3da4c54030
3 changed files with 51 additions and 7 deletions
|
@ -40,6 +40,7 @@
|
||||||
height: 7em
|
height: 7em
|
||||||
margin: 0.2em 1em 0 0
|
margin: 0.2em 1em 0 0
|
||||||
|
|
||||||
.remove
|
.controls
|
||||||
float: right
|
float: right
|
||||||
|
a
|
||||||
color: $inactive-link-color
|
color: $inactive-link-color
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<li class='uploadable'>
|
<li class='uploadable'>
|
||||||
<a href class='remove'>
|
<div class='controls'>
|
||||||
<i class='fa fa-remove'></i>
|
<a href class='move-up'><i class='fa fa-chevron-up'></i></a>
|
||||||
</a>
|
<a href class='move-down'><i class='fa fa-chevron-down'></i></a>
|
||||||
|
<a href class='remove'><i class='fa fa-remove'></i></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class='thumbnail'>
|
<div class='thumbnail'>
|
||||||
<% if (['image'].includes(ctx.uploadable.type)) { %>
|
<% if (['image'].includes(ctx.uploadable.type)) { %>
|
||||||
|
|
|
@ -200,6 +200,7 @@ class PostUploadView extends events.EventTarget {
|
||||||
uploadable.destroy();
|
uploadable.destroy();
|
||||||
uploadable.rowNode.parentNode.removeChild(uploadable.rowNode);
|
uploadable.rowNode.parentNode.removeChild(uploadable.rowNode);
|
||||||
this._uploadables.delete(uploadable.key);
|
this._uploadables.delete(uploadable.key);
|
||||||
|
this._normalizeUploadablesOrder();
|
||||||
this._emit('change');
|
this._emit('change');
|
||||||
if (!this._uploadables.size) {
|
if (!this._uploadables.size) {
|
||||||
this._formNode.classList.add('inactive');
|
this._formNode.classList.add('inactive');
|
||||||
|
@ -224,6 +225,30 @@ class PostUploadView extends events.EventTarget {
|
||||||
this.removeUploadable(uploadable);
|
this.removeUploadable(uploadable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_evtMoveUpClick(e, uploadable) {
|
||||||
|
e.preventDefault();
|
||||||
|
let sortedUploadables = this._getSortedUploadables();
|
||||||
|
if (uploadable.order > 0) {
|
||||||
|
uploadable.order--;
|
||||||
|
const prevUploadable = sortedUploadables[uploadable.order];
|
||||||
|
prevUploadable.order++;
|
||||||
|
uploadable.rowNode.parentNode.insertBefore(
|
||||||
|
uploadable.rowNode, prevUploadable.rowNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_evtMoveDownClick(e, uploadable) {
|
||||||
|
e.preventDefault();
|
||||||
|
let sortedUploadables = this._getSortedUploadables();
|
||||||
|
if (uploadable.order + 1 < sortedUploadables.length) {
|
||||||
|
uploadable.order++;
|
||||||
|
const nextUploadable = sortedUploadables[uploadable.order];
|
||||||
|
nextUploadable.order--;
|
||||||
|
uploadable.rowNode.parentNode.insertBefore(
|
||||||
|
nextUploadable.rowNode, uploadable.rowNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_evtSafetyRadioboxChange(e, uploadable) {
|
_evtSafetyRadioboxChange(e, uploadable) {
|
||||||
uploadable.safety = e.target.value;
|
uploadable.safety = e.target.value;
|
||||||
}
|
}
|
||||||
|
@ -232,12 +257,24 @@ class PostUploadView extends events.EventTarget {
|
||||||
uploadable.anonymous = e.target.checked;
|
uploadable.anonymous = e.target.checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
_emit(eventType) {
|
_normalizeUploadablesOrder() {
|
||||||
|
let sortedUploadables = this._getSortedUploadables();
|
||||||
|
for (let i = 0; i < sortedUploadables.length; i++) {
|
||||||
|
sortedUploadables[i].order = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_getSortedUploadables() {
|
||||||
let sortedUploadables = [...this._uploadables.values()];
|
let sortedUploadables = [...this._uploadables.values()];
|
||||||
sortedUploadables.sort((a, b) => a.order - b.order);
|
sortedUploadables.sort((a, b) => a.order - b.order);
|
||||||
|
return sortedUploadables;
|
||||||
|
}
|
||||||
|
|
||||||
|
_emit(eventType) {
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new CustomEvent(
|
new CustomEvent(
|
||||||
eventType, {detail: {uploadables: sortedUploadables}}));
|
eventType,
|
||||||
|
{detail: {uploadables: this._getSortedUploadables()}}));
|
||||||
}
|
}
|
||||||
|
|
||||||
_createRowNode(uploadable) {
|
_createRowNode(uploadable) {
|
||||||
|
@ -258,6 +295,10 @@ class PostUploadView extends events.EventTarget {
|
||||||
|
|
||||||
rowNode.querySelector('a.remove').addEventListener(
|
rowNode.querySelector('a.remove').addEventListener(
|
||||||
'click', e => this._evtRemoveClick(e, uploadable));
|
'click', e => this._evtRemoveClick(e, uploadable));
|
||||||
|
rowNode.querySelector('a.move-up').addEventListener(
|
||||||
|
'click', e => this._evtMoveUpClick(e, uploadable));
|
||||||
|
rowNode.querySelector('a.move-down').addEventListener(
|
||||||
|
'click', e => this._evtMoveDownClick(e, uploadable));
|
||||||
uploadable.rowNode = rowNode;
|
uploadable.rowNode = rowNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue