snappymail/dev/Settings/User/OpenPgp.js

92 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-21 23:08:34 +08:00
var
2014-10-04 19:58:01 +08:00
_ = require('_'),
2014-08-25 23:49:01 +08:00
ko = require('ko'),
2014-10-04 19:58:01 +08:00
Utils = require('Common/Utils'),
kn = require('Knoin/Knoin'),
2014-10-18 21:43:44 +08:00
Data = require('Storage/User/Data')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
function OpenPgpUserSettings()
2014-08-21 23:08:34 +08:00
{
2014-08-22 23:08:56 +08:00
this.openpgpkeys = Data.openpgpkeys;
this.openpgpkeysPublic = Data.openpgpkeysPublic;
this.openpgpkeysPrivate = Data.openpgpkeysPrivate;
2014-08-21 23:08:34 +08:00
this.openPgpKeyForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this,
function (oPrev) {
if (oPrev)
{
oPrev.deleteAccess(false);
}
}, function (oNext) {
if (oNext)
{
oNext.deleteAccess(true);
}
}
]});
}
OpenPgpUserSettings.prototype.addOpenPgpKey = function ()
2014-08-21 23:08:34 +08:00
{
kn.showScreenPopup(require('View/Popup/AddOpenPgpKey'));
2014-08-21 23:08:34 +08:00
};
OpenPgpUserSettings.prototype.generateOpenPgpKey = function ()
2014-08-21 23:08:34 +08:00
{
kn.showScreenPopup(require('View/Popup/NewOpenPgpKey'));
2014-08-21 23:08:34 +08:00
};
OpenPgpUserSettings.prototype.viewOpenPgpKey = function (oOpenPgpKey)
2014-08-21 23:08:34 +08:00
{
if (oOpenPgpKey)
{
kn.showScreenPopup(require('View/Popup/ViewOpenPgpKey'), [oOpenPgpKey]);
2014-08-21 23:08:34 +08:00
}
};
/**
* @param {OpenPgpKeyModel} oOpenPgpKeyToRemove
*/
OpenPgpUserSettings.prototype.deleteOpenPgpKey = function (oOpenPgpKeyToRemove)
2014-08-21 23:08:34 +08:00
{
if (oOpenPgpKeyToRemove && oOpenPgpKeyToRemove.deleteAccess())
{
this.openPgpKeyForDeletion(null);
2014-08-22 23:08:56 +08:00
if (oOpenPgpKeyToRemove && Data.openpgpKeyring)
2014-08-21 23:08:34 +08:00
{
2014-10-04 19:58:01 +08:00
var oFindedItem = _.find(this.openpgpkeys(), function (oOpenPgpKey) {
2014-08-21 23:08:34 +08:00
return oOpenPgpKeyToRemove === oOpenPgpKey;
});
2014-10-04 19:58:01 +08:00
if (oFindedItem)
{
this.openpgpkeys.remove(oFindedItem);
Utils.delegateRunOnDestroy(oFindedItem);
Data.openpgpKeyring[oFindedItem.isPrivate ? 'privateKeys' : 'publicKeys']
.removeForId(oFindedItem.guid);
2014-08-21 23:08:34 +08:00
2014-10-04 19:58:01 +08:00
Data.openpgpKeyring.store();
}
2014-08-21 23:08:34 +08:00
2014-10-18 21:43:44 +08:00
require('App/User').reloadOpenPgpKeys();
2014-08-21 23:08:34 +08:00
}
}
};
module.exports = OpenPgpUserSettings;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());