mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 12:39: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,175 +1,165 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
key = require('key'),
|
||||
$ = require('$'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
import $ from '$';
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
Enums = require('Common/Enums'),
|
||||
import {createCommand, pString, log} from 'Common/Utils';
|
||||
import {KeyState, Magics} from 'Common/Enums';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function MessageOpenPgpPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/MessageOpenPgp',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsMessageOpenPgp'
|
||||
})
|
||||
class MessageOpenPgpPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsMessageOpenPgp');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.notification = ko.observable('');
|
||||
this.notification = ko.observable('');
|
||||
|
||||
this.selectedKey = ko.observable(null);
|
||||
this.privateKeys = ko.observableArray([]);
|
||||
this.selectedKey = ko.observable(null);
|
||||
this.privateKeys = ko.observableArray([]);
|
||||
|
||||
this.password = ko.observable('');
|
||||
this.password.focus = ko.observable(false);
|
||||
this.buttonFocus = ko.observable(false);
|
||||
this.password = ko.observable('');
|
||||
this.password.focus = ko.observable(false);
|
||||
this.buttonFocus = ko.observable(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
this.resultCallback = null;
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitRequest = ko.observable(false);
|
||||
|
||||
// commands
|
||||
this.doCommand = Utils.createCommand(this, function() {
|
||||
// commands
|
||||
this.doCommand = createCommand(() => {
|
||||
|
||||
this.submitRequest(true);
|
||||
this.submitRequest(true);
|
||||
|
||||
_.delay(_.bind(function() {
|
||||
_.delay(() => {
|
||||
|
||||
var oPrivateKey = null;
|
||||
let privateKey = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (this.resultCallback && this.selectedKey())
|
||||
try
|
||||
{
|
||||
var oPrivateKeys = this.selectedKey().getNativeKeys();
|
||||
oPrivateKey = oPrivateKeys && oPrivateKeys[0] ? oPrivateKeys[0] : null;
|
||||
|
||||
if (oPrivateKey)
|
||||
if (this.resultCallback && this.selectedKey())
|
||||
{
|
||||
try
|
||||
const privateKeys = this.selectedKey().getNativeKeys();
|
||||
privateKey = privateKeys && privateKeys[0] ? privateKeys[0] : null;
|
||||
|
||||
if (privateKey)
|
||||
{
|
||||
if (!oPrivateKey.decrypt(Utils.pString(this.password())))
|
||||
try
|
||||
{
|
||||
Utils.log('Error: Private key cannot be decrypted');
|
||||
oPrivateKey = null;
|
||||
if (!privateKey.decrypt(pString(this.password())))
|
||||
{
|
||||
log('Error: Private key cannot be decrypted');
|
||||
privateKey = null;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
log(e);
|
||||
privateKey = null;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
else
|
||||
{
|
||||
Utils.log(e);
|
||||
oPrivateKey = null;
|
||||
log('Error: Private key cannot be found');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.log('Error: Private key cannot be found');
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
catch (e)
|
||||
{
|
||||
log(e);
|
||||
privateKey = null;
|
||||
}
|
||||
|
||||
this.submitRequest(false);
|
||||
|
||||
this.cancelCommand();
|
||||
this.resultCallback(privateKey);
|
||||
|
||||
}, Magics.Time100ms);
|
||||
|
||||
}, () => !this.submitRequest());
|
||||
|
||||
this.sDefaultKeyScope = KeyState.PopupMessageOpenPGP;
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.notification('');
|
||||
|
||||
this.password('');
|
||||
this.password.focus(false);
|
||||
this.buttonFocus(false);
|
||||
|
||||
this.selectedKey(false);
|
||||
this.submitRequest(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
this.privateKeys([]);
|
||||
}
|
||||
|
||||
onBuild(oDom) {
|
||||
key('tab,shift+tab', KeyState.PopupMessageOpenPGP, () => {
|
||||
|
||||
switch (true)
|
||||
{
|
||||
Utils.log(e);
|
||||
oPrivateKey = null;
|
||||
case this.password.focus():
|
||||
this.buttonFocus(true);
|
||||
break;
|
||||
case this.buttonFocus():
|
||||
this.password.focus(true);
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
|
||||
this.submitRequest(false);
|
||||
return false;
|
||||
|
||||
this.cancelCommand();
|
||||
this.resultCallback(oPrivateKey);
|
||||
});
|
||||
|
||||
}, this), Enums.Magics.Time100ms);
|
||||
const self = this;
|
||||
|
||||
}, function() {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
oDom
|
||||
.on('click', '.key-list__item', function() { // eslint-disable-line prefer-arrow-callback
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.PopupMessageOpenPGP;
|
||||
oDom.find('.key-list__item .key-list__item__radio')
|
||||
.addClass('icon-radio-unchecked')
|
||||
.removeClass('icon-radio-checked');
|
||||
|
||||
kn.constructorEnd(this);
|
||||
$(this).find('.key-list__item__radio') // eslint-disable-line no-invalid-this
|
||||
.removeClass('icon-radio-unchecked')
|
||||
.addClass('icon-radio-checked');
|
||||
|
||||
self.selectedKey(ko.dataFor(this)); // eslint-disable-line no-invalid-this
|
||||
|
||||
self.password.focus(true);
|
||||
});
|
||||
}
|
||||
|
||||
onHideWithDelay() {
|
||||
this.clearPopup();
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
this.password.focus(true);
|
||||
// this.buttonFocus(true);
|
||||
}
|
||||
|
||||
onShow(fCallback, privateKeys) {
|
||||
this.clearPopup();
|
||||
|
||||
this.resultCallback = fCallback;
|
||||
this.privateKeys(privateKeys);
|
||||
|
||||
if (this.viewModelDom)
|
||||
{
|
||||
this.viewModelDom.find('.key-list__item').first().click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/MessageOpenPgp'], MessageOpenPgpPopupView);
|
||||
_.extend(MessageOpenPgpPopupView.prototype, AbstractView.prototype);
|
||||
|
||||
MessageOpenPgpPopupView.prototype.clearPopup = function()
|
||||
{
|
||||
this.notification('');
|
||||
|
||||
this.password('');
|
||||
this.password.focus(false);
|
||||
this.buttonFocus(false);
|
||||
|
||||
this.selectedKey(false);
|
||||
this.submitRequest(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
this.privateKeys([]);
|
||||
};
|
||||
|
||||
MessageOpenPgpPopupView.prototype.onBuild = function(oDom)
|
||||
{
|
||||
key('tab,shift+tab', Enums.KeyState.PopupMessageOpenPGP, _.bind(function() {
|
||||
|
||||
switch (true)
|
||||
{
|
||||
case this.password.focus():
|
||||
this.buttonFocus(true);
|
||||
break;
|
||||
case this.buttonFocus():
|
||||
this.password.focus(true);
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}, this));
|
||||
|
||||
var self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.key-list__item', function() {
|
||||
|
||||
oDom.find('.key-list__item .key-list__item__radio')
|
||||
.addClass('icon-radio-unchecked')
|
||||
.removeClass('icon-radio-checked');
|
||||
|
||||
$(this).find('.key-list__item__radio')
|
||||
.removeClass('icon-radio-unchecked')
|
||||
.addClass('icon-radio-checked');
|
||||
|
||||
self.selectedKey(ko.dataFor(this));
|
||||
|
||||
self.password.focus(true);
|
||||
});
|
||||
};
|
||||
|
||||
MessageOpenPgpPopupView.prototype.onHideWithDelay = function()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
MessageOpenPgpPopupView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
this.password.focus(true);
|
||||
// this.buttonFocus(true);
|
||||
};
|
||||
|
||||
MessageOpenPgpPopupView.prototype.onShow = function(fCallback, aPrivateKeys)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
this.resultCallback = fCallback;
|
||||
this.privateKeys(aPrivateKeys);
|
||||
|
||||
if (this.viewModelDom)
|
||||
{
|
||||
this.viewModelDom.find('.key-list__item').first().click();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = MessageOpenPgpPopupView;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue