mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 05:29:20 +03:00
es5 -> es2015 (last stage)
Signature plugin fixes Add view decorator A large number of fixes
This commit is contained in:
parent
e88c193334
commit
17669b7be0
153 changed files with 21193 additions and 21115 deletions
|
|
@ -1,197 +1,187 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {bMobileDevice} from 'Common/Globals';
|
||||
import {createCommand, trim, fakeMd5} from 'Common/Utils';
|
||||
import {getNotification} from 'Common/Translator';
|
||||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function IdentityPopupView()
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Popup/Identity',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsIdentity'
|
||||
})
|
||||
class IdentityPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsIdentity');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
var self = this;
|
||||
this.id = '';
|
||||
this.edit = ko.observable(false);
|
||||
this.owner = ko.observable(false);
|
||||
|
||||
this.id = '';
|
||||
this.edit = ko.observable(false);
|
||||
this.owner = ko.observable(false);
|
||||
this.email = ko.observable('').validateEmail();
|
||||
this.email.focused = ko.observable(false);
|
||||
this.name = ko.observable('');
|
||||
this.name.focused = ko.observable(false);
|
||||
this.replyTo = ko.observable('').validateSimpleEmail();
|
||||
this.replyTo.focused = ko.observable(false);
|
||||
this.bcc = ko.observable('').validateSimpleEmail();
|
||||
this.bcc.focused = ko.observable(false);
|
||||
|
||||
this.email = ko.observable('').validateEmail();
|
||||
this.email.focused = ko.observable(false);
|
||||
this.name = ko.observable('');
|
||||
this.name.focused = ko.observable(false);
|
||||
this.replyTo = ko.observable('').validateSimpleEmail();
|
||||
this.replyTo.focused = ko.observable(false);
|
||||
this.bcc = ko.observable('').validateSimpleEmail();
|
||||
this.bcc.focused = ko.observable(false);
|
||||
this.signature = ko.observable('');
|
||||
this.signatureInsertBefore = ko.observable(false);
|
||||
|
||||
this.signature = ko.observable('');
|
||||
this.signatureInsertBefore = ko.observable(false);
|
||||
this.showBcc = ko.observable(false);
|
||||
this.showReplyTo = ko.observable(false);
|
||||
|
||||
this.showBcc = ko.observable(false);
|
||||
this.showReplyTo = ko.observable(false);
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
this.bcc.subscribe(function(aValue) {
|
||||
if (false === self.showBcc() && 0 < aValue.length)
|
||||
{
|
||||
self.showBcc(true);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.replyTo.subscribe(function(aValue) {
|
||||
if (false === self.showReplyTo() && 0 < aValue.length)
|
||||
{
|
||||
self.showReplyTo(true);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.addOrEditIdentityCommand = Utils.createCommand(this, function() {
|
||||
|
||||
if (this.signature && this.signature.__fetchEditorValue)
|
||||
{
|
||||
this.signature.__fetchEditorValue();
|
||||
}
|
||||
|
||||
if (!this.email.hasError())
|
||||
{
|
||||
this.email.hasError('' === Utils.trim(this.email()));
|
||||
}
|
||||
|
||||
if (this.email.hasError())
|
||||
{
|
||||
if (!this.owner())
|
||||
this.bcc.subscribe((value) => {
|
||||
if (false === this.showBcc() && 0 < value.length)
|
||||
{
|
||||
this.email.focused(true);
|
||||
this.showBcc(true);
|
||||
}
|
||||
});
|
||||
|
||||
this.replyTo.subscribe((value) => {
|
||||
if (false === this.showReplyTo() && 0 < value.length)
|
||||
{
|
||||
this.showReplyTo(true);
|
||||
}
|
||||
});
|
||||
|
||||
this.addOrEditIdentityCommand = createCommand(() => {
|
||||
|
||||
if (this.signature && this.signature.__fetchEditorValue)
|
||||
{
|
||||
this.signature.__fetchEditorValue();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.replyTo.hasError())
|
||||
{
|
||||
this.replyTo.focused(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.bcc.hasError())
|
||||
{
|
||||
this.bcc.focused(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
Remote.identityUpdate(_.bind(function(sResult, oData) {
|
||||
|
||||
this.submitRequest(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData)
|
||||
if (!this.email.hasError())
|
||||
{
|
||||
if (oData.Result)
|
||||
this.email.hasError('' === trim(this.email()));
|
||||
}
|
||||
|
||||
if (this.email.hasError())
|
||||
{
|
||||
if (!this.owner())
|
||||
{
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
this.cancelCommand();
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
this.submitError(Translator.getNotification(oData.ErrorCode));
|
||||
this.email.focused(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
if (this.replyTo.hasError())
|
||||
{
|
||||
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
|
||||
this.replyTo.focused(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
}, this), this.id, this.email(), this.name(), this.replyTo(), this.bcc(),
|
||||
this.signature(), this.signatureInsertBefore());
|
||||
if (this.bcc.hasError())
|
||||
{
|
||||
this.bcc.focused(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
this.submitRequest(true);
|
||||
|
||||
}, function() {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
Remote.identityUpdate((result, data) => {
|
||||
|
||||
kn.constructorEnd(this);
|
||||
this.submitRequest(false);
|
||||
if (StorageResultType.Success === result && data)
|
||||
{
|
||||
if (data.Result)
|
||||
{
|
||||
getApp().accountsAndIdentities();
|
||||
this.cancelCommand();
|
||||
}
|
||||
else if (data.ErrorCode)
|
||||
{
|
||||
this.submitError(getNotification(data.ErrorCode));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitError(getNotification(Notification.UnknownError));
|
||||
}
|
||||
|
||||
}, this.id, this.email(), this.name(), this.replyTo(), this.bcc(), this.signature(), this.signatureInsertBefore());
|
||||
|
||||
return true;
|
||||
|
||||
}, () => !this.submitRequest());
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.id = '';
|
||||
this.edit(false);
|
||||
this.owner(false);
|
||||
|
||||
this.name('');
|
||||
this.email('');
|
||||
this.replyTo('');
|
||||
this.bcc('');
|
||||
this.signature('');
|
||||
this.signatureInsertBefore(false);
|
||||
|
||||
this.email.hasError(false);
|
||||
this.replyTo.hasError(false);
|
||||
this.bcc.hasError(false);
|
||||
|
||||
this.showBcc(false);
|
||||
this.showReplyTo(false);
|
||||
|
||||
this.submitRequest(false);
|
||||
this.submitError('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?IdentityModel} oIdentity
|
||||
*/
|
||||
onShow(identity) {
|
||||
|
||||
this.clearPopup();
|
||||
|
||||
if (identity)
|
||||
{
|
||||
this.edit(true);
|
||||
|
||||
this.id = identity.id() || '';
|
||||
this.name(identity.name());
|
||||
this.email(identity.email());
|
||||
this.replyTo(identity.replyTo());
|
||||
this.bcc(identity.bcc());
|
||||
this.signature(identity.signature());
|
||||
this.signatureInsertBefore(identity.signatureInsertBefore());
|
||||
|
||||
this.owner('' === this.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.id = fakeMd5();
|
||||
}
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if (!this.owner() && !bMobileDevice)
|
||||
{
|
||||
this.email.focused(true);
|
||||
}
|
||||
}
|
||||
|
||||
onHideWithDelay() {
|
||||
this.clearPopup();
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/Identity', 'PopupsIdentityViewModel'], IdentityPopupView);
|
||||
_.extend(IdentityPopupView.prototype, AbstractView.prototype);
|
||||
|
||||
IdentityPopupView.prototype.clearPopup = function()
|
||||
{
|
||||
this.id = '';
|
||||
this.edit(false);
|
||||
this.owner(false);
|
||||
|
||||
this.name('');
|
||||
this.email('');
|
||||
this.replyTo('');
|
||||
this.bcc('');
|
||||
this.signature('');
|
||||
this.signatureInsertBefore(false);
|
||||
|
||||
this.email.hasError(false);
|
||||
this.replyTo.hasError(false);
|
||||
this.bcc.hasError(false);
|
||||
|
||||
this.showBcc(false);
|
||||
this.showReplyTo(false);
|
||||
|
||||
this.submitRequest(false);
|
||||
this.submitError('');
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {?IdentityModel} oIdentity
|
||||
*/
|
||||
IdentityPopupView.prototype.onShow = function(oIdentity)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
if (oIdentity)
|
||||
{
|
||||
this.edit(true);
|
||||
|
||||
this.id = oIdentity.id() || '';
|
||||
this.name(oIdentity.name());
|
||||
this.email(oIdentity.email());
|
||||
this.replyTo(oIdentity.replyTo());
|
||||
this.bcc(oIdentity.bcc());
|
||||
this.signature(oIdentity.signature());
|
||||
this.signatureInsertBefore(oIdentity.signatureInsertBefore());
|
||||
|
||||
this.owner('' === this.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.id = Utils.fakeMd5();
|
||||
}
|
||||
};
|
||||
|
||||
IdentityPopupView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
if (!this.owner() && !Globals.bMobile)
|
||||
{
|
||||
this.email.focused(true);
|
||||
}
|
||||
};
|
||||
|
||||
IdentityPopupView.prototype.onHideWithDelay = function()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
module.exports = IdentityPopupView;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue