2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import {StorageResultType, Notification} from 'Common/Enums';
|
|
|
|
import {bMobileDevice} from 'Common/Globals';
|
2016-09-10 06:38:16 +08:00
|
|
|
import {trim, fakeMd5} from 'Common/Utils';
|
2016-08-17 06:01:20 +08:00
|
|
|
import {getNotification} from 'Common/Translator';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import Remote from 'Remote/User/Ajax';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import {getApp} from 'Helper/Apps/User';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
import {popup, command} from 'Knoin/Knoin';
|
2016-08-17 06:01:20 +08:00
|
|
|
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
@popup({
|
2016-08-17 06:01:20 +08:00
|
|
|
name: 'View/Popup/Identity',
|
|
|
|
templateID: 'PopupsIdentity'
|
|
|
|
})
|
|
|
|
class IdentityPopupView extends AbstractViewNext
|
|
|
|
{
|
|
|
|
constructor() {
|
|
|
|
super();
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.id = '';
|
|
|
|
this.edit = ko.observable(false);
|
|
|
|
this.owner = ko.observable(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
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);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.signature = ko.observable('');
|
|
|
|
this.signatureInsertBefore = ko.observable(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.showBcc = ko.observable(false);
|
|
|
|
this.showReplyTo = ko.observable(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.submitRequest = ko.observable(false);
|
|
|
|
this.submitError = ko.observable('');
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.bcc.subscribe((value) => {
|
|
|
|
if (false === this.showBcc() && 0 < value.length)
|
|
|
|
{
|
|
|
|
this.showBcc(true);
|
|
|
|
}
|
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.replyTo.subscribe((value) => {
|
|
|
|
if (false === this.showReplyTo() && 0 < value.length)
|
|
|
|
{
|
|
|
|
this.showReplyTo(true);
|
|
|
|
}
|
|
|
|
});
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2015-02-06 23:26:20 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
@command((self) => !self.submitRequest())
|
|
|
|
addOrEditIdentityCommand() {
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
if (this.signature && this.signature.__fetchEditorValue)
|
|
|
|
{
|
|
|
|
this.signature.__fetchEditorValue();
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
if (!this.email.hasError())
|
|
|
|
{
|
|
|
|
this.email.hasError('' === trim(this.email()));
|
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
if (this.email.hasError())
|
|
|
|
{
|
|
|
|
if (!this.owner())
|
2016-08-17 06:01:20 +08:00
|
|
|
{
|
2016-09-10 06:38:16 +08:00
|
|
|
this.email.focused(true);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
if (this.replyTo.hasError())
|
|
|
|
{
|
|
|
|
this.replyTo.focused(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.bcc.hasError())
|
|
|
|
{
|
|
|
|
this.bcc.focused(true);
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
this.submitRequest(true);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
Remote.identityUpdate((result, data) => {
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
this.submitRequest(false);
|
|
|
|
if (StorageResultType.Success === result && data)
|
|
|
|
{
|
|
|
|
if (data.Result)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2016-09-10 06:38:16 +08:00
|
|
|
getApp().accountsAndIdentities();
|
|
|
|
this.cancelCommand();
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-09-10 06:38:16 +08:00
|
|
|
else if (data.ErrorCode)
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-09-10 06:38:16 +08:00
|
|
|
this.submitError(getNotification(data.ErrorCode));
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.submitError(getNotification(Notification.UnknownError));
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
}, this.id, this.email(), this.name(), this.replyTo(), this.bcc(), this.signature(), this.signatureInsertBefore());
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
return true;
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
clearPopup() {
|
|
|
|
this.id = '';
|
|
|
|
this.edit(false);
|
|
|
|
this.owner(false);
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.name('');
|
|
|
|
this.email('');
|
|
|
|
this.replyTo('');
|
|
|
|
this.bcc('');
|
|
|
|
this.signature('');
|
|
|
|
this.signatureInsertBefore(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.email.hasError(false);
|
|
|
|
this.replyTo.hasError(false);
|
|
|
|
this.bcc.hasError(false);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.showBcc(false);
|
|
|
|
this.showReplyTo(false);
|
2015-02-06 23:26:20 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.submitRequest(false);
|
|
|
|
this.submitError('');
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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();
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShowWithDelay() {
|
|
|
|
if (!this.owner() && !bMobileDevice)
|
|
|
|
{
|
|
|
|
this.email.focused(true);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onHideWithDelay() {
|
|
|
|
this.clearPopup();
|
|
|
|
}
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
export {IdentityPopupView, IdentityPopupView as default};
|