(function () { 'use strict'; var _ = require('_'), $ = require('$'), ko = require('ko'), key = require('key'), PhotoSwipe = require('PhotoSwipe'), PhotoSwipeUI_Default = require('PhotoSwipeUI_Default'), Consts = require('Common/Consts'), Enums = require('Common/Enums'), Globals = require('Common/Globals'), Utils = require('Common/Utils'), Events = require('Common/Events'), Cache = require('Storage/User/Cache'), Data = require('Storage/User/Data'), Remote = require('Storage/User/Remote'), kn = require('Knoin/Knoin'), AbstractView = require('Knoin/AbstractView') ; /** * @constructor * @extends AbstractView */ function MessageViewMailBoxUserView() { AbstractView.call(this, 'Right', 'MailMessageView'); var self = this, sLastEmail = '', createCommandHelper = function (sType) { return Utils.createCommand(self, function () { this.replyOrforward(sType); }, self.canBeRepliedOrForwarded); } ; this.oMessageScrollerDom = null; this.pswp = null; this.message = Data.message; this.currentMessage = Data.currentMessage; this.messageListChecked = Data.messageListChecked; this.hasCheckedMessages = Data.hasCheckedMessages; this.messageListCheckedOrSelectedUidsWithSubMails = Data.messageListCheckedOrSelectedUidsWithSubMails; this.messageLoading = Data.messageLoading; this.messageLoadingThrottle = Data.messageLoadingThrottle; this.messagesBodiesDom = Data.messagesBodiesDom; this.useThreads = Data.useThreads; this.replySameFolder = Data.replySameFolder; this.layout = Data.layout; this.usePreviewPane = Data.usePreviewPane; this.isMessageSelected = Data.isMessageSelected; this.messageActiveDom = Data.messageActiveDom; this.messageError = Data.messageError; this.fullScreenMode = Data.messageFullScreenMode; this.showFullInfo = ko.observable(false); this.moreDropdownTrigger = ko.observable(false); this.messageDomFocused = ko.observable(false).extend({'rateLimit': 0}); this.messageVisibility = ko.computed(function () { return !this.messageLoadingThrottle() && !!this.message(); }, this); this.message.subscribe(function (oMessage) { if (!oMessage) { this.currentMessage(null); } }, this); this.canBeRepliedOrForwarded = this.messageVisibility; // commands this.closeMessage = Utils.createCommand(this, function () { Data.message(null); }); this.replyCommand = createCommandHelper(Enums.ComposeType.Reply); this.replyAllCommand = createCommandHelper(Enums.ComposeType.ReplyAll); this.forwardCommand = createCommandHelper(Enums.ComposeType.Forward); this.forwardAsAttachmentCommand = createCommandHelper(Enums.ComposeType.ForwardAsAttachment); this.editAsNewCommand = createCommandHelper(Enums.ComposeType.EditAsNew); this.messageVisibilityCommand = Utils.createCommand(this, Utils.emptyFunction, this.messageVisibility); this.messageEditCommand = Utils.createCommand(this, function () { this.editMessage(); }, this.messageVisibility); this.deleteCommand = Utils.createCommand(this, function () { if (this.message()) { require('App/User').deleteMessagesFromFolder(Enums.FolderType.Trash, this.message().folderFullNameRaw, [this.message().uid], true); } }, this.messageVisibility); this.deleteWithoutMoveCommand = Utils.createCommand(this, function () { if (this.message()) { require('App/User').deleteMessagesFromFolder(Enums.FolderType.Trash, Data.currentFolderFullNameRaw(), [this.message().uid], false); } }, this.messageVisibility); this.archiveCommand = Utils.createCommand(this, function () { if (this.message()) { require('App/User').deleteMessagesFromFolder(Enums.FolderType.Archive, this.message().folderFullNameRaw, [this.message().uid], true); } }, this.messageVisibility); this.spamCommand = Utils.createCommand(this, function () { if (this.message()) { require('App/User').deleteMessagesFromFolder(Enums.FolderType.Spam, this.message().folderFullNameRaw, [this.message().uid], true); } }, this.messageVisibility); this.notSpamCommand = Utils.createCommand(this, function () { if (this.message()) { require('App/User').deleteMessagesFromFolder(Enums.FolderType.NotSpam, this.message().folderFullNameRaw, [this.message().uid], true); } }, this.messageVisibility); // viewer this.viewHash = ''; this.viewSubject = ko.observable(''); this.viewFromShort = ko.observable(''); this.viewToShort = ko.observable(''); this.viewFrom = ko.observable(''); this.viewTo = ko.observable(''); this.viewCc = ko.observable(''); this.viewBcc = ko.observable(''); this.viewDate = ko.observable(''); this.viewSize = ko.observable(''); this.viewMoment = ko.observable(''); this.viewLineAsCcc = ko.observable(''); this.viewViewLink = ko.observable(''); this.viewDownloadLink = ko.observable(''); this.viewUserPic = ko.observable(Consts.DataImages.UserDotPic); this.viewUserPicVisible = ko.observable(false); this.viewPgpPassword = ko.observable(''); this.viewPgpSignedVerifyStatus = ko.computed(function () { return this.message() ? this.message().pgpSignedVerifyStatus() : Enums.SignedVerifyStatus.None; }, this); this.viewPgpSignedVerifyUser = ko.computed(function () { return this.message() ? this.message().pgpSignedVerifyUser() : ''; }, this); this.message.subscribe(function (oMessage) { this.messageActiveDom(null); this.viewPgpPassword(''); if (oMessage) { if (this.viewHash !== oMessage.hash) { this.scrollMessageToTop(); } this.viewHash = oMessage.hash; this.viewSubject(oMessage.subject()); this.viewFromShort(oMessage.fromToLine(true, true)); this.viewToShort(oMessage.toToLine(true, true)); this.viewFrom(oMessage.fromToLine(false)); this.viewTo(oMessage.toToLine(false)); this.viewCc(oMessage.ccToLine(false)); this.viewBcc(oMessage.bccToLine(false)); this.viewDate(oMessage.fullFormatDateValue()); this.viewSize(oMessage.friendlySize()); this.viewMoment(oMessage.momentDate()); this.viewLineAsCcc(oMessage.lineAsCcc()); this.viewViewLink(oMessage.viewLink()); this.viewDownloadLink(oMessage.downloadLink()); sLastEmail = oMessage.fromAsSingleEmail(); Cache.getUserPic(sLastEmail, function (sPic, $sEmail) { if (sPic !== self.viewUserPic() && sLastEmail === $sEmail) { self.viewUserPicVisible(false); self.viewUserPic(Consts.DataImages.UserDotPic); if ('' !== sPic) { self.viewUserPicVisible(true); self.viewUserPic(sPic); } } }); } else { this.viewHash = ''; this.scrollMessageToTop(); } }, this); this.fullScreenMode.subscribe(function (bValue) { if (bValue) { Globals.$html.addClass('rl-message-fullscreen'); } else { Globals.$html.removeClass('rl-message-fullscreen'); } Utils.windowResize(); }); this.messageLoadingThrottle.subscribe(function (bV) { if (bV) { Utils.windowResize(); } }); this.goUpCommand = Utils.createCommand(this, function () { Events.pub('mailbox.message-list.selector.go-up'); }); this.goDownCommand = Utils.createCommand(this, function () { Events.pub('mailbox.message-list.selector.go-down'); }); kn.constructorEnd(this); } kn.extendAsViewModel(['View/User/MailBox/MessageView', 'View/App/MailBox/MessageView', 'MailBoxMessageViewViewModel'], MessageViewMailBoxUserView); _.extend(MessageViewMailBoxUserView.prototype, AbstractView.prototype); MessageViewMailBoxUserView.prototype.isPgpActionVisible = function () { return Enums.SignedVerifyStatus.Success !== this.viewPgpSignedVerifyStatus(); }; MessageViewMailBoxUserView.prototype.isPgpStatusVerifyVisible = function () { return Enums.SignedVerifyStatus.None !== this.viewPgpSignedVerifyStatus(); }; MessageViewMailBoxUserView.prototype.isPgpStatusVerifySuccess = function () { return Enums.SignedVerifyStatus.Success === this.viewPgpSignedVerifyStatus(); }; MessageViewMailBoxUserView.prototype.pgpStatusVerifyMessage = function () { var sResult = ''; switch (this.viewPgpSignedVerifyStatus()) { case Enums.SignedVerifyStatus.UnknownPublicKeys: sResult = Utils.i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND'); break; case Enums.SignedVerifyStatus.UnknownPrivateKey: sResult = Utils.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND'); break; case Enums.SignedVerifyStatus.Unverified: sResult = Utils.i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE'); break; case Enums.SignedVerifyStatus.Error: sResult = Utils.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'); break; case Enums.SignedVerifyStatus.Success: sResult = Utils.i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', { 'USER': this.viewPgpSignedVerifyUser() }); break; } return sResult; }; MessageViewMailBoxUserView.prototype.fullScreen = function () { this.fullScreenMode(true); Utils.windowResize(); }; MessageViewMailBoxUserView.prototype.unFullScreen = function () { this.fullScreenMode(false); Utils.windowResize(); }; MessageViewMailBoxUserView.prototype.toggleFullScreen = function () { Utils.removeSelection(); this.fullScreenMode(!this.fullScreenMode()); Utils.windowResize(); }; /** * @param {string} sType */ MessageViewMailBoxUserView.prototype.replyOrforward = function (sType) { kn.showScreenPopup(require('View/Popup/Compose'), [sType, Data.message()]); }; MessageViewMailBoxUserView.prototype.onBuild = function (oDom) { var self = this, sErrorMessage = Utils.i18n('PREVIEW_POPUP/IMAGE_ERROR') ; this.fullScreenMode.subscribe(function (bValue) { if (bValue) { self.message.focused(true); } }, this); // $('.attachmentsPlace', oDom).magnificPopup({ // 'delegate': '.attachmentImagePreview:visible', // 'type': 'image', // 'gallery': { // 'enabled': true, // 'preload': [1, 1], // 'navigateByImgClick': true // }, // 'callbacks': { // 'open': function() { // Globals.useKeyboardShortcuts(false); // }, // 'close': function() { // Globals.useKeyboardShortcuts(true); // } // }, // 'mainClass': 'mfp-fade', // 'removalDelay': 400 // }); this.pswpDom = $('.pswp', oDom)[0]; if (this.pswpDom) { oDom .on('click', 'a.attachmentImagePreview[data-index]:visible', function (oEvent) { var oPs = null, oEl = oEvent.currentTarget || null, aItems = [] ; oDom.find('a.attachmentImagePreview:visible').each(function (index, oSubElement) { var $oItem = $(oSubElement); aItems.push({ w: 600, h: 400, 'src': $oItem.attr('href'), 'title': $oItem.attr('title') || '' }); }); if (aItems && 0 < aItems.length) { Globals.useKeyboardShortcuts(false); oPs = new PhotoSwipe(self.pswpDom, PhotoSwipeUI_Default, aItems, { 'index': Utils.pInt($(oEl).data('index')), 'bgOpacity': 0.85, 'loadingIndicatorDelay': 500, 'errorMsg': '