snappymail/dev/Settings/App/OpenPGP.js

83 lines
1.7 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-08-25 23:49:01 +08:00
ko = require('ko'),
kn = require('Knoin/Knoin'),
Data = require('Storage/App/Data')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
function OpenPGPAppSetting()
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);
}
}
]});
}
OpenPGPAppSetting.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
};
OpenPGPAppSetting.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
};
OpenPGPAppSetting.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
*/
OpenPGPAppSetting.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
{
this.openpgpkeys.remove(function (oOpenPgpKey) {
return oOpenPgpKeyToRemove === oOpenPgpKey;
});
2014-08-22 23:08:56 +08:00
Data.openpgpKeyring[oOpenPgpKeyToRemove.isPrivate ? 'privateKeys' : 'publicKeys']
2014-08-21 23:08:34 +08:00
.removeForId(oOpenPgpKeyToRemove.guid);
2014-08-22 23:08:56 +08:00
Data.openpgpKeyring.store();
2014-08-21 23:08:34 +08:00
require('App/App').reloadOpenPgpKeys();
2014-08-21 23:08:34 +08:00
}
}
};
module.exports = OpenPGPAppSetting;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());