mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 04:29:21 +03:00
Code refactoring
This commit is contained in:
parent
36329110e5
commit
b4f416b6f8
105 changed files with 4331 additions and 4339 deletions
116
dev/ViewModels/Popups/PopupsNewOpenPgpKeyViewModel.js
Normal file
116
dev/ViewModels/Popups/PopupsNewOpenPgpKeyViewModel.js
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
(function (module, require) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
window = require('window'),
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
|
||||
Utils = require('Utils'),
|
||||
|
||||
Data = require('Storage:RainLoop:Data'),
|
||||
|
||||
kn = require('App:Knoin'),
|
||||
KnoinAbstractViewModel = require('Knoin:AbstractViewModel')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsNewOpenPgpKeyViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsNewOpenPgpKey');
|
||||
|
||||
this.email = ko.observable('');
|
||||
this.email.focus = ko.observable('');
|
||||
this.email.error = ko.observable(false);
|
||||
|
||||
this.name = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
this.keyBitLength = ko.observable(2048);
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
|
||||
this.email.subscribe(function () {
|
||||
this.email.error(false);
|
||||
}, this);
|
||||
|
||||
this.generateOpenPgpKeyCommand = Utils.createCommand(this, function () {
|
||||
|
||||
var
|
||||
self = this,
|
||||
sUserID = '',
|
||||
mKeyPair = null,
|
||||
oOpenpgpKeyring = Data.openpgpKeyring
|
||||
;
|
||||
|
||||
this.email.error('' === Utils.trim(this.email()));
|
||||
if (!oOpenpgpKeyring || this.email.error())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sUserID = this.email();
|
||||
if ('' !== this.name())
|
||||
{
|
||||
sUserID = this.name() + ' <' + sUserID + '>';
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
_.delay(function () {
|
||||
// mKeyPair = window.openpgp.generateKeyPair(1, Utils.pInt(self.keyBitLength()), sUserID, Utils.trim(self.password()));
|
||||
mKeyPair = window.openpgp.generateKeyPair({
|
||||
'userId': sUserID,
|
||||
'numBits': Utils.pInt(self.keyBitLength()),
|
||||
'passphrase': Utils.trim(self.password())
|
||||
});
|
||||
|
||||
if (mKeyPair && mKeyPair.privateKeyArmored)
|
||||
{
|
||||
oOpenpgpKeyring.privateKeys.importKey(mKeyPair.privateKeyArmored);
|
||||
oOpenpgpKeyring.publicKeys.importKey(mKeyPair.publicKeyArmored);
|
||||
oOpenpgpKeyring.store();
|
||||
|
||||
require('App:RainLoop').reloadOpenPgpKeys();
|
||||
Utils.delegateRun(self, 'cancelCommand');
|
||||
}
|
||||
|
||||
self.submitRequest(false);
|
||||
}, 100);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
kn.extendAsViewModel('PopupsNewOpenPgpKeyViewModel', PopupsNewOpenPgpKeyViewModel);
|
||||
|
||||
PopupsNewOpenPgpKeyViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.name('');
|
||||
this.password('');
|
||||
|
||||
this.email('');
|
||||
this.email.error(false);
|
||||
this.keyBitLength(2048);
|
||||
};
|
||||
|
||||
PopupsNewOpenPgpKeyViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
PopupsNewOpenPgpKeyViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.email.focus(true);
|
||||
};
|
||||
|
||||
module.exports = PopupsNewOpenPgpKeyViewModel;
|
||||
|
||||
}(module, require));
|
||||
Loading…
Add table
Add a link
Reference in a new issue