snappymail/dev/Settings/User/OpenPgp.jsx

77 lines
1.8 KiB
React
Raw Normal View History

2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
var
_ = require('_'),
ko = require('ko'),
window = require('window'),
2016-06-30 08:02:45 +08:00
Utils = require('Common/Utils'),
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
kn = require('Knoin/Knoin'),
2016-06-30 08:02:45 +08:00
PgpStore = require('Stores/User/Pgp');
2014-10-04 19:58:01 +08:00
2016-06-30 08:02:45 +08:00
/**
* @constructor
*/
function OpenPgpUserSettings()
{
this.openpgpkeys = PgpStore.openpgpkeys;
this.openpgpkeysPublic = PgpStore.openpgpkeysPublic;
this.openpgpkeysPrivate = PgpStore.openpgpkeysPrivate;
2016-06-30 08:02:45 +08:00
this.openPgpKeyForDeletion = ko.observable(null).deleteAccessHelper();
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.isHttps = window.document && window.document.location ? 'https:' === window.document.location.protocol : false;
}
2015-07-06 02:06:19 +08:00
2016-06-30 08:02:45 +08:00
OpenPgpUserSettings.prototype.addOpenPgpKey = function()
{
kn.showScreenPopup(require('View/Popup/AddOpenPgpKey'));
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
OpenPgpUserSettings.prototype.generateOpenPgpKey = function()
{
kn.showScreenPopup(require('View/Popup/NewOpenPgpKey'));
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
OpenPgpUserSettings.prototype.viewOpenPgpKey = function(oOpenPgpKey)
{
if (oOpenPgpKey)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
kn.showScreenPopup(require('View/Popup/ViewOpenPgpKey'), [oOpenPgpKey]);
}
};
/**
* @param {OpenPgpKeyModel} oOpenPgpKeyToRemove
*/
OpenPgpUserSettings.prototype.deleteOpenPgpKey = function(oOpenPgpKeyToRemove)
{
if (oOpenPgpKeyToRemove && oOpenPgpKeyToRemove.deleteAccess())
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
this.openPgpKeyForDeletion(null);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
if (oOpenPgpKeyToRemove && PgpStore.openpgpKeyring)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
var oFindedItem = _.find(PgpStore.openpgpkeys(), function(oOpenPgpKey) {
return oOpenPgpKeyToRemove === oOpenPgpKey;
});
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
if (oFindedItem)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
PgpStore.openpgpkeys.remove(oFindedItem);
Utils.delegateRunOnDestroy(oFindedItem);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
PgpStore.openpgpKeyring[oFindedItem.isPrivate ? 'privateKeys' : 'publicKeys']
.removeForId(oFindedItem.guid);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
PgpStore.openpgpKeyring.store();
2014-08-21 23:08:34 +08:00
}
2016-06-30 08:02:45 +08:00
require('App/User').default.reloadOpenPgpKeys();
}
}
};
2014-08-21 23:08:34 +08:00
2016-07-16 03:54:37 +08:00
export {OpenPgpUserSettings, OpenPgpUserSettings as default};