Media viewer: delete button
This commit is contained in:
parent
07517d4ad9
commit
1b4c51345c
@ -49,6 +49,8 @@ import I18n, { i18n } from "../lib/langPack";
|
|||||||
import { capitalizeFirstLetter } from "../helpers/string";
|
import { capitalizeFirstLetter } from "../helpers/string";
|
||||||
import setInnerHTML from "../helpers/dom/setInnerHTML";
|
import setInnerHTML from "../helpers/dom/setInnerHTML";
|
||||||
import { doubleRaf, fastRaf } from "../helpers/schedulers";
|
import { doubleRaf, fastRaf } from "../helpers/schedulers";
|
||||||
|
import { attachClickEvent } from "../helpers/dom/clickEvent";
|
||||||
|
import PopupDeleteMessages from "./popups/deleteMessages";
|
||||||
|
|
||||||
// TODO: масштабирование картинок (не SVG) при ресайзе, и правильный возврат на исходную позицию
|
// TODO: масштабирование картинок (не SVG) при ресайзе, и правильный возврат на исходную позицию
|
||||||
// TODO: картинки "обрезаются" если возвращаются или появляются с места, где есть их перекрытие (топбар, поле ввода)
|
// TODO: картинки "обрезаются" если возвращаются или появляются с места, где есть их перекрытие (топбар, поле ввода)
|
||||||
@ -61,7 +63,7 @@ class AppMediaViewerBase<ContentAdditionType extends string, ButtonsAdditionType
|
|||||||
protected overlaysDiv: HTMLElement;
|
protected overlaysDiv: HTMLElement;
|
||||||
protected author: {[k in 'container' | 'avatarEl' | 'nameEl' | 'date']: HTMLElement} = {} as any;
|
protected author: {[k in 'container' | 'avatarEl' | 'nameEl' | 'date']: HTMLElement} = {} as any;
|
||||||
protected content: {[k in 'main' | 'container' | 'media' | 'mover' | ContentAdditionType]: HTMLElement} = {} as any;
|
protected content: {[k in 'main' | 'container' | 'media' | 'mover' | ContentAdditionType]: HTMLElement} = {} as any;
|
||||||
protected buttons: {[k in 'download' | 'close' | 'prev' | 'next' | 'mobile-close' | ButtonsAdditionType]: HTMLElement} = {} as any;
|
protected buttons: {[k in 'download' | 'close' | 'prev' | 'next' | 'mobile-close' | 'zoomin' | ButtonsAdditionType]: HTMLElement} = {} as any;
|
||||||
protected topbar: HTMLElement;
|
protected topbar: HTMLElement;
|
||||||
|
|
||||||
protected tempId = 0;
|
protected tempId = 0;
|
||||||
@ -127,32 +129,31 @@ class AppMediaViewerBase<ContentAdditionType extends string, ButtonsAdditionType
|
|||||||
const topbarLeft = document.createElement('div');
|
const topbarLeft = document.createElement('div');
|
||||||
topbarLeft.classList.add(MEDIA_VIEWER_CLASSNAME + '-topbar-left');
|
topbarLeft.classList.add(MEDIA_VIEWER_CLASSNAME + '-topbar-left');
|
||||||
|
|
||||||
|
|
||||||
this.buttons['mobile-close'] = ButtonIcon('close', {onlyMobile: true});
|
this.buttons['mobile-close'] = ButtonIcon('close', {onlyMobile: true});
|
||||||
|
|
||||||
// * author
|
// * author
|
||||||
this.author.container = document.createElement('div');
|
this.author.container = document.createElement('div');
|
||||||
this.author.container.classList.add(MEDIA_VIEWER_CLASSNAME + '-author', 'no-select');
|
this.author.container.classList.add(MEDIA_VIEWER_CLASSNAME + '-author', 'no-select');
|
||||||
const authorRight = document.createElement('div');
|
const authorRight = document.createElement('div');
|
||||||
|
|
||||||
this.author.avatarEl = new AvatarElement();
|
this.author.avatarEl = new AvatarElement();
|
||||||
this.author.avatarEl.classList.add(MEDIA_VIEWER_CLASSNAME + '-userpic', 'avatar-44');
|
this.author.avatarEl.classList.add(MEDIA_VIEWER_CLASSNAME + '-userpic', 'avatar-44');
|
||||||
|
|
||||||
this.author.nameEl = document.createElement('div');
|
this.author.nameEl = document.createElement('div');
|
||||||
this.author.nameEl.classList.add(MEDIA_VIEWER_CLASSNAME + '-name');
|
this.author.nameEl.classList.add(MEDIA_VIEWER_CLASSNAME + '-name');
|
||||||
|
|
||||||
this.author.date = document.createElement('div');
|
this.author.date = document.createElement('div');
|
||||||
this.author.date.classList.add(MEDIA_VIEWER_CLASSNAME + '-date');
|
this.author.date.classList.add(MEDIA_VIEWER_CLASSNAME + '-date');
|
||||||
|
|
||||||
authorRight.append(this.author.nameEl, this.author.date);
|
authorRight.append(this.author.nameEl, this.author.date);
|
||||||
|
|
||||||
this.author.container.append(this.author.avatarEl, authorRight);
|
this.author.container.append(this.author.avatarEl, authorRight);
|
||||||
|
|
||||||
// * buttons
|
// * buttons
|
||||||
const buttonsDiv = document.createElement('div');
|
const buttonsDiv = document.createElement('div');
|
||||||
buttonsDiv.classList.add(MEDIA_VIEWER_CLASSNAME + '-buttons');
|
buttonsDiv.classList.add(MEDIA_VIEWER_CLASSNAME + '-buttons');
|
||||||
|
|
||||||
topButtons.concat(['download', 'close']).forEach(name => {
|
topButtons.concat(['download', 'zoomin', 'close']).forEach(name => {
|
||||||
const button = ButtonIcon(name, {noRipple: name === 'close' || undefined});
|
const button = ButtonIcon(name, {noRipple: name === 'close' || undefined});
|
||||||
this.buttons[name] = button;
|
this.buttons[name] = button;
|
||||||
buttonsDiv.append(button);
|
buttonsDiv.append(button);
|
||||||
@ -1332,12 +1333,13 @@ type AppMediaViewerTargetType = {
|
|||||||
peerId: number
|
peerId: number
|
||||||
};
|
};
|
||||||
export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delete' | 'forward', AppMediaViewerTargetType> {
|
export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delete' | 'forward', AppMediaViewerTargetType> {
|
||||||
public currentMessageId = 0;
|
protected currentMessageId = 0;
|
||||||
public currentPeerId = 0;
|
protected currentPeerId = 0;
|
||||||
public searchContext: SearchSuperContext;
|
protected searchContext: SearchSuperContext;
|
||||||
|
protected btnMenuDelete: HTMLElement;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super([/* 'delete', */'forward']);
|
super(['delete', 'forward']);
|
||||||
|
|
||||||
/* const stub = document.createElement('div');
|
/* const stub = document.createElement('div');
|
||||||
stub.classList.add(MEDIA_VIEWER_CLASSNAME + '-stub');
|
stub.classList.add(MEDIA_VIEWER_CLASSNAME + '-stub');
|
||||||
@ -1376,7 +1378,9 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
|
|||||||
//this.content.main.append(this.content.caption);
|
//this.content.main.append(this.content.caption);
|
||||||
this.wholeDiv.append(this.content.caption);
|
this.wholeDiv.append(this.content.caption);
|
||||||
|
|
||||||
this.setBtnMenuToggle([{
|
attachClickEvent(this.buttons.delete, this.onDeleteClick);
|
||||||
|
|
||||||
|
const buttons: ButtonMenuItemOptions[] = [{
|
||||||
icon: 'forward',
|
icon: 'forward',
|
||||||
text: 'Forward',
|
text: 'Forward',
|
||||||
onClick: this.onForwardClick
|
onClick: this.onForwardClick
|
||||||
@ -1384,11 +1388,14 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
|
|||||||
icon: 'download',
|
icon: 'download',
|
||||||
text: 'MediaViewer.Context.Download',
|
text: 'MediaViewer.Context.Download',
|
||||||
onClick: this.onDownloadClick
|
onClick: this.onDownloadClick
|
||||||
}/* , {
|
}, {
|
||||||
icon: 'delete danger btn-disabled',
|
icon: 'delete danger',
|
||||||
text: 'Delete',
|
text: 'Delete',
|
||||||
onClick: () => {}
|
onClick: this.onDeleteClick
|
||||||
} */]);
|
}];
|
||||||
|
|
||||||
|
this.setBtnMenuToggle(buttons);
|
||||||
|
this.btnMenuDelete = buttons[buttons.length - 1].element;
|
||||||
|
|
||||||
// * constructing html end
|
// * constructing html end
|
||||||
|
|
||||||
@ -1442,6 +1449,13 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
|
|||||||
this.openMedia(appMessagesManager.getMessageByPeer(target.peerId, target.mid), target.element, 1);
|
this.openMedia(appMessagesManager.getMessageByPeer(target.peerId, target.mid), target.element, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onDeleteClick = () => {
|
||||||
|
new PopupDeleteMessages(this.currentPeerId, [this.currentMessageId], 'chat', () => {
|
||||||
|
this.lastTarget = this.content.media;
|
||||||
|
this.close();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
onForwardClick = () => {
|
onForwardClick = () => {
|
||||||
if(this.currentMessageId) {
|
if(this.currentMessageId) {
|
||||||
//appSidebarRight.forwardTab.open([this.currentMessageId]);
|
//appSidebarRight.forwardTab.open([this.currentMessageId]);
|
||||||
@ -1620,6 +1634,11 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
|
|||||||
|
|
||||||
this.buttons.forward.classList.toggle('hide', message._ === 'messageService');
|
this.buttons.forward.classList.toggle('hide', message._ === 'messageService');
|
||||||
|
|
||||||
|
const canDeleteMessage = appMessagesManager.canDeleteMessage(message);
|
||||||
|
[this.buttons.delete, this.btnMenuDelete].forEach(button => {
|
||||||
|
button.classList.toggle('hide', !canDeleteMessage);
|
||||||
|
});
|
||||||
|
|
||||||
this.currentMessageId = mid;
|
this.currentMessageId = mid;
|
||||||
this.currentPeerId = message.peerId;
|
this.currentPeerId = message.peerId;
|
||||||
this.setCaption(message);
|
this.setCaption(message);
|
||||||
|
Loading…
Reference in New Issue
Block a user