2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2014-09-02 08:15:31 +08:00
|
|
|
|
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'),
|
2015-07-06 02:06:19 +08:00
|
|
|
window = require('window'),
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-10-04 19:58:01 +08:00
|
|
|
Utils = require('Common/Utils'),
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2015-02-03 07:58:58 +08:00
|
|
|
PgpStore = require('Stores/User/Pgp')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-10-30 21:59:25 +08:00
|
|
|
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
|
|
|
|
2015-02-17 20:04:03 +08:00
|
|
|
this.openPgpKeyForDeletion = ko.observable(null).deleteAccessHelper();
|
2015-07-06 02:06:19 +08:00
|
|
|
|
|
|
|
this.isHttps = window.document && window.document.location ? 'https:' === window.document.location.protocol : false;
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
OpenPgpUserSettings.prototype.addOpenPgpKey = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
kn.showScreenPopup(require('View/Popup/AddOpenPgpKey'));
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
OpenPgpUserSettings.prototype.generateOpenPgpKey = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
kn.showScreenPopup(require('View/Popup/NewOpenPgpKey'));
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
OpenPgpUserSettings.prototype.viewOpenPgpKey = function (oOpenPgpKey)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
if (oOpenPgpKey)
|
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
kn.showScreenPopup(require('View/Popup/ViewOpenPgpKey'), [oOpenPgpKey]);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {OpenPgpKeyModel} oOpenPgpKeyToRemove
|
|
|
|
*/
|
2014-10-30 21:59:25 +08:00
|
|
|
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
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
require('App/User').default.reloadOpenPgpKeys();
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
module.exports = OpenPgpUserSettings;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-28 04:54:38 +08:00
|
|
|
}());
|