snappymail/dev/ViewModels/PopupsAddOpenPgpKeyViewModel.js
RainLoop Team 5ece4cc0ec OpenPGP Key Storage (Settings) (#53)
Import, Delete, Generate, View
2014-03-13 02:29:33 +04:00

62 lines
1.2 KiB
JavaScript

/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsAddOpenPgpKeyViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAddOpenPgpKey');
this.key = ko.observable('');
this.key.error = ko.observable(false);
this.key.focus = ko.observable(false);
this.key.subscribe(function () {
this.key.error(false);
}, this);
this.addOpenPgpKeyCommand = Utils.createCommand(this, function () {
var
sKey = Utils.trim(this.key()),
oOpenpgpKeyring = RL.data().openpgpKeyring
;
this.key.error('' === sKey);
if (!oOpenpgpKeyring || this.key.error())
{
return false;
}
oOpenpgpKeyring.importKey(sKey);
oOpenpgpKeyring.store();
RL.reloadOpenPgpKeys();
Utils.delegateRun(this, 'cancelCommand');
return true;
});
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsAddOpenPgpKeyViewModel', PopupsAddOpenPgpKeyViewModel);
PopupsAddOpenPgpKeyViewModel.prototype.clearPopup = function ()
{
this.key('');
this.key.error(false);
};
PopupsAddOpenPgpKeyViewModel.prototype.onShow = function ()
{
this.clearPopup();
};
PopupsAddOpenPgpKeyViewModel.prototype.onFocus = function ()
{
this.key.focus(true);
};