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'),
2015-02-03 07:58:58 +08:00
PgpStore = require('Stores/User/Pgp')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
function OpenPgpUserSettings()
2014-08-21 23:08:34 +08:00
{
2015-02-03 07:58:58 +08:00
this.openpgpkeys = PgpStore.openpgpkeys;
this.openpgpkeysPublic = PgpStore.openpgpkeysPublic;
this.openpgpkeysPrivate = PgpStore.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);
2015-02-03 07:58:58 +08:00
if (oOpenPgpKeyToRemove && PgpStore.openpgpKeyring)
2014-08-21 23:08:34 +08:00
{
2015-02-03 07:58:58 +08:00
var oFindedItem = _.find(PgpStore.openpgpkeys(), function (oOpenPgpKey) {
2014-08-21 23:08:34 +08:00
return oOpenPgpKeyToRemove === oOpenPgpKey;
});
2014-10-04 19:58:01 +08:00
if (oFindedItem)
{
2015-02-03 07:58:58 +08:00
PgpStore.openpgpkeys.remove(oFindedItem);
2014-10-04 19:58:01 +08:00
Utils.delegateRunOnDestroy(oFindedItem);
2015-02-03 07:58:58 +08:00
PgpStore.openpgpKeyring[oFindedItem.isPrivate ? 'privateKeys' : 'publicKeys']
2014-10-04 19:58:01 +08:00
.removeForId(oFindedItem.guid);
2014-08-21 23:08:34 +08:00
2015-02-03 07:58:58 +08:00
PgpStore.openpgpKeyring.store();
2014-10-04 19:58:01 +08:00
}
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
}());