diff --git a/dev/Component/MaterialDesign/Checkbox.js b/dev/Component/MaterialDesign/Checkbox.js index 547fb1b69..475d0ea3e 100644 --- a/dev/Component/MaterialDesign/Checkbox.js +++ b/dev/Component/MaterialDesign/Checkbox.js @@ -11,31 +11,18 @@ export class CheckboxMaterialDesignComponent extends AbstractCheckbox { this.animationBox = ko.observable(false).extend({ falseTimeout: 200 }); this.animationCheckmark = ko.observable(false).extend({ falseTimeout: 200 }); - this.animationBoxSetTrue = this.animationBoxSetTrue.bind(this); - this.animationCheckmarkSetTrue = this.animationCheckmarkSetTrue.bind(this); - this.disposable.push( - this.value.subscribe((value) => { - this.triggerAnimation(value); - }, this) + this.value.subscribe(value => this.triggerAnimation(value), this) ); } - animationBoxSetTrue() { - this.animationBox(true); - } - - animationCheckmarkSetTrue() { - this.animationCheckmark(true); - } - triggerAnimation(box) { if (box) { - this.animationBoxSetTrue(); - setTimeout(this.animationCheckmarkSetTrue, 200); + this.animationBox(true); + setTimeout(()=>this.animationCheckmark(true), 200); } else { - this.animationCheckmarkSetTrue(); - setTimeout(this.animationBoxSetTrue, 200); + this.animationCheckmark(true); + setTimeout(()=>this.animationBox(true), 200); } } } diff --git a/dev/Stores/User/Message.js b/dev/Stores/User/Message.js index 33fda90f1..dad13f42a 100644 --- a/dev/Stores/User/Message.js +++ b/dev/Stores/User/Message.js @@ -220,8 +220,6 @@ export const MessageUserStore = new class { } }); - this.onMessageResponse = this.onMessageResponse.bind(this); - this.purgeMessageBodyCacheThrottle = this.purgeMessageBodyCache.throttle(30000); } @@ -630,27 +628,20 @@ export const MessageUserStore = new class { if (oMessage) { this.hideMessageBodies(); this.messageLoading(true); - Remote.message(this.onMessageResponse, oMessage.folder, oMessage.uid); + Remote.message((iError, oData, bCached) => { + if (iError) { + if (Notification.RequestAborted !== iError) { + this.message(null); + this.messageError(getNotification(iError)); + } + } else { + this.setMessage(oData, bCached); + } + this.messageLoading(false); + }, oMessage.folder, oMessage.uid); } } - /** - * @param {string} sResult - * @param {FetchJsonDefaultResponse} oData - * @param {boolean} bCached - */ - onMessageResponse(iError, oData, bCached) { - if (iError) { - if (Notification.RequestAborted !== iError) { - this.message(null); - this.messageError(getNotification(iError)); - } - } else { - this.setMessage(oData, bCached); - } - this.messageLoading(false); - } - /** * @param {Array} list * @returns {string} diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 7ea0fdcea..62736cf04 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -419,7 +419,24 @@ class ComposePopupView extends AbstractViewPopup { setFolderHash(sSentFolder, ''); Remote.sendMessage( - this.sendMessageResponse.bind(this), + (iError, data) => { + this.sending(false); + if (this.modalVisibility()) { + if (iError) { + if (Notification.CantSaveMessage === iError) { + this.sendSuccessButSaveError(true); + this.savedErrorDesc(i18n('COMPOSE/SAVED_ERROR_ON_SEND').trim()); + } else { + this.sendError(true); + this.sendErrorDesc(getNotification(iError, data && data.ErrorMessage) + || getNotification(Notification.CantSendMessage)); + } + } else { + this.closeCommand && this.closeCommand(); + } + } + this.reloadDraftFolder(); + }, this.getMessageRequestParams(sSentFolder) ); } @@ -438,7 +455,40 @@ class ComposePopupView extends AbstractViewPopup { setFolderHash(FolderUserStore.draftFolder(), ''); Remote.saveMessage( - this.saveMessageResponse.bind(this), + (iError, oData) => { + let result = false; + + this.saving(false); + + if (!iError) { + if (oData.Result.NewFolder && oData.Result.NewUid) { + result = true; + + if (this.bFromDraft) { + const message = MessageUserStore.message(); + if (message && this.draftFolder() === message.folder && this.draftUid() === message.uid) { + MessageUserStore.message(null); + } + } + + this.draftFolder(oData.Result.NewFolder); + this.draftUid(oData.Result.NewUid); + + this.savedTime(new Date); + + if (this.bFromDraft) { + setFolderHash(this.draftFolder(), ''); + } + } + } + + if (!result) { + this.savedError(true); + this.savedErrorDesc(getNotification(Notification.CantSaveMessage)); + } + + this.reloadDraftFolder(); + }, this.getMessageRequestParams(FolderUserStore.draftFolder()) ); } @@ -578,63 +628,6 @@ class ComposePopupView extends AbstractViewPopup { } } - sendMessageResponse(iError, data) { - - this.sending(false); - - if (this.modalVisibility()) { - if (iError) { - if (Notification.CantSaveMessage === iError) { - this.sendSuccessButSaveError(true); - this.savedErrorDesc(i18n('COMPOSE/SAVED_ERROR_ON_SEND').trim()); - } else { - this.sendError(true); - this.sendErrorDesc(getNotification(iError, data && data.ErrorMessage) - || getNotification(Notification.CantSendMessage)); - } - } else { - this.closeCommand && this.closeCommand(); - } - } - - this.reloadDraftFolder(); - } - - saveMessageResponse(iError, oData) { - let result = false; - - this.saving(false); - - if (!iError) { - if (oData.Result.NewFolder && oData.Result.NewUid) { - result = true; - - if (this.bFromDraft) { - const message = MessageUserStore.message(); - if (message && this.draftFolder() === message.folder && this.draftUid() === message.uid) { - MessageUserStore.message(null); - } - } - - this.draftFolder(oData.Result.NewFolder); - this.draftUid(oData.Result.NewUid); - - this.savedTime(new Date); - - if (this.bFromDraft) { - setFolderHash(this.draftFolder(), ''); - } - } - } - - if (!result) { - this.savedError(true); - this.savedErrorDesc(getNotification(Notification.CantSaveMessage)); - } - - this.reloadDraftFolder(); - } - onHide() { // Stop autosave clearTimeout(this.iTimer); diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 6faf64ab9..36187c356 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -90,7 +90,7 @@ class ContactsPopupView extends AbstractViewPopup { this.bDropPageAfterDelete = false; - // this.saveCommandDebounce = _.debounce(this.saveCommand.bind(this), 1000); + // this.saveCommandDebounce = this.saveCommand.bind(this).debounce(1000); const // propertyFocused = property => !property.isValid() && !property.focused(), @@ -382,26 +382,18 @@ class ContactsPopupView extends AbstractViewPopup { deleteSelectedContacts() { if (this.contactsCheckedOrSelected().length) { - Remote.contactsDelete(this.deleteResponse.bind(this), this.contactsCheckedOrSelectedUids()); + Remote.contactsDelete((iError, oData) => { + if (500 < (!iError && oData && oData.Time ? pInt(oData.Time) : 0)) { + this.reloadContactList(this.bDropPageAfterDelete); + } else { + setTimeout(() => this.reloadContactList(this.bDropPageAfterDelete), 500); + } + }, this.contactsCheckedOrSelectedUids()); this.removeCheckedOrSelectedContactsFromList(); } } - /** - * @param {int} iError - * @param {FetchJsonDefaultResponse} oData - */ - deleteResponse(iError, oData) { - if (500 < (!iError && oData && oData.Time ? pInt(oData.Time) : 0)) { - this.reloadContactList(this.bDropPageAfterDelete); - } else { - setTimeout(() => { - this.reloadContactList(this.bDropPageAfterDelete); - }, 500); - } - } - removeProperty(oProp) { this.viewProperties.remove(oProp); delegateRunOnDestroy(oProp); diff --git a/dev/View/Popup/Domain.js b/dev/View/Popup/Domain.js index 1d36cdaaf..b03890349 100644 --- a/dev/View/Popup/Domain.js +++ b/dev/View/Popup/Domain.js @@ -187,7 +187,48 @@ class DomainPopupView extends AbstractViewPopup { this.testing(true); Remote.testConnectionForDomain( - this.onTestConnectionResponse.bind(this), + (iError, oData) => { + this.testing(false); + if (iError) { + this.testingImapError(true); + this.testingSieveError(true); + this.testingSmtpError(true); + this.sieveSettings(false); + } else { + let bImap = false, + bSieve = false; + + this.testingDone(true); + this.testingImapError(true !== oData.Result.Imap); + this.testingSieveError(true !== oData.Result.Sieve); + this.testingSmtpError(true !== oData.Result.Smtp); + + if (this.testingImapError() && oData.Result.Imap) { + bImap = true; + this.testingImapErrorDesc(''); + this.testingImapErrorDesc(oData.Result.Imap); + } + + if (this.testingSieveError() && oData.Result.Sieve) { + bSieve = true; + this.testingSieveErrorDesc(''); + this.testingSieveErrorDesc(oData.Result.Sieve); + } + + if (this.testingSmtpError() && oData.Result.Smtp) { + this.testingSmtpErrorDesc(''); + this.testingSmtpErrorDesc(oData.Result.Smtp); + } + + if (this.sieveSettings()) { + if (!bSieve && bImap) { + this.sieveSettings(false); + } + } else if (bSieve && !bImap) { + this.sieveSettings(true); + } + } + }, this ); } @@ -205,49 +246,6 @@ class DomainPopupView extends AbstractViewPopup { this.clearTesting(); } - onTestConnectionResponse(iError, oData) { - this.testing(false); - if (iError) { - this.testingImapError(true); - this.testingSieveError(true); - this.testingSmtpError(true); - this.sieveSettings(false); - } else { - let bImap = false, - bSieve = false; - - this.testingDone(true); - this.testingImapError(true !== oData.Result.Imap); - this.testingSieveError(true !== oData.Result.Sieve); - this.testingSmtpError(true !== oData.Result.Smtp); - - if (this.testingImapError() && oData.Result.Imap) { - bImap = true; - this.testingImapErrorDesc(''); - this.testingImapErrorDesc(oData.Result.Imap); - } - - if (this.testingSieveError() && oData.Result.Sieve) { - bSieve = true; - this.testingSieveErrorDesc(''); - this.testingSieveErrorDesc(oData.Result.Sieve); - } - - if (this.testingSmtpError() && oData.Result.Smtp) { - this.testingSmtpErrorDesc(''); - this.testingSmtpErrorDesc(oData.Result.Smtp); - } - - if (this.sieveSettings()) { - if (!bSieve && bImap) { - this.sieveSettings(false); - } - } else if (bSieve && !bImap) { - this.sieveSettings(true); - } - } - } - onDomainCreateOrSaveResponse(iError) { this.saving(false); if (iError) { diff --git a/dev/View/Popup/Plugin.js b/dev/View/Popup/Plugin.js index 242d302bb..f1cb19fd0 100644 --- a/dev/View/Popup/Plugin.js +++ b/dev/View/Popup/Plugin.js @@ -14,8 +14,6 @@ class PluginPopupView extends AbstractViewPopup { constructor() { super('Plugin'); - this.onPluginSettingsUpdateResponse = this.onPluginSettingsUpdateResponse.bind(this); - this.addObservables({ saveError: '', name: '', @@ -50,15 +48,11 @@ class PluginPopupView extends AbstractViewPopup { }); this.saveError(''); - Remote.pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, list); - } - - onPluginSettingsUpdateResponse(iError) { - if (iError) { - this.saveError(getNotification(iError)); - } else { - this.cancelCommand(); - } + Remote.pluginSettingsUpdate(iError => + iError + ? this.saveError(getNotification(iError)) + : this.cancelCommand() + , list); } onShow(oPlugin) { diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index c3301dced..8717669a7 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -263,8 +263,6 @@ class MessageViewMailBoxUserView extends AbstractViewRight { addEventListener('mailbox.message-view.toggle-full-screen', () => this.toggleFullScreen()); - this.attachmentPreview = this.attachmentPreview.bind(this); - decorateKoCommands(this, { closeMessageCommand: 1, messageEditCommand: self => self.messageVisibility(), @@ -313,57 +311,6 @@ class MessageViewMailBoxUserView extends AbstractViewRight { this.oHeaderDom && this.viewBodyTopValue(this.message() ? this.oHeaderDom.offsetHeight : 0); } - // displayMailToPopup(sMailToUrl) { - // sMailToUrl = sMailToUrl.replace(/\?.+$/, ''); - // - // var - // sResult = '', - // aTo = [], - // EmailModel = require('Model/Email').default, - // fParseEmailLine = function(sLine) { - // return sLine ? [decodeURIComponent(sLine)].map(sItem => { - // var oEmailModel = new EmailModel(); - // oEmailModel.parse(sItem); - // return oEmailModel.email ? oEmailModel : null; - // }).filter(v => v) : null; - // } - // ; - // - // aTo = fParseEmailLine(sMailToUrl); - // sResult = aTo && aTo[0] ? aTo[0].email : ''; - // - // return sResult; - // } - - /** - * @param {Object} oAttachment - * @returns {boolean} - */ - attachmentPreview(/*attachment*/) { -/* - if (attachment && attachment.isImage() && !attachment.isLinked && this.message() && this.message().attachments()) { - const items = this.message().attachments.map(item => { - if (item && !item.isLinked && item.isImage()) { - if (item === attachment) { - index = listIndex; - } - ++listIndex; - return { - src: item.linkPreview(), - msrc: item.linkThumbnail(), - title: item.fileName - }; - } - return null; - }).filter(v => v); - - if (items.length) { - } - } -*/ - return true; - } - onBuild(dom) { this.fullScreenMode.subscribe(value => value && this.message() && AppUserStore.focusedState(Scope.MessageView)); @@ -476,33 +423,28 @@ class MessageViewMailBoxUserView extends AbstractViewRight { this.initShortcuts(); } - /** - * @returns {boolean} - */ - escShortcuts() { - if (this.viewModelVisible && this.message()) { - const preview = SettingsUserStore.usePreviewPane(); - if (this.fullScreenMode()) { - this.fullScreenMode(false); - - if (preview) { - AppUserStore.focusedState(Scope.MessageList); - } - } else if (!preview) { - this.message(null); - } else { - AppUserStore.focusedState(Scope.MessageList); - } - - return false; - } - - return true; - } - initShortcuts() { // exit fullscreen, back - shortcuts.add('escape,backspace', '', Scope.MessageView, this.escShortcuts.bind(this)); + shortcuts.add('escape,backspace', '', Scope.MessageView, () => { + if (this.viewModelVisible && this.message()) { + const preview = SettingsUserStore.usePreviewPane(); + if (this.fullScreenMode()) { + this.fullScreenMode(false); + + if (preview) { + AppUserStore.focusedState(Scope.MessageList); + } + } else if (!preview) { + this.message(null); + } else { + AppUserStore.focusedState(Scope.MessageList); + } + + return false; + } + + return true; + }); // fullscreen shortcuts.add('enter,open', '', Scope.MessageView, () => {