2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import _ from '_';
|
|
|
|
import ko from 'ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2017-06-29 00:25:53 +08:00
|
|
|
import {delegateRunOnDestroy, boolToAjax} from 'Common/Utils';
|
|
|
|
import {Magics} from 'Common/Enums';
|
2016-07-16 05:29:42 +08:00
|
|
|
import {bIsHttps} from 'Common/Globals';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import PgpStore from 'Stores/User/Pgp';
|
2017-06-29 00:25:53 +08:00
|
|
|
import SettingsStore from 'Stores/User/Settings';
|
|
|
|
|
|
|
|
import Remote from 'Remote/User/Ajax';
|
2014-10-04 19:58:01 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import {getApp} from 'Helper/Apps/User';
|
|
|
|
|
|
|
|
import {showScreenPopup} from 'Knoin/Knoin';
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
class OpenPgpUserSettings
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
|
|
|
this.openpgpkeys = PgpStore.openpgpkeys;
|
|
|
|
this.openpgpkeysPublic = PgpStore.openpgpkeysPublic;
|
|
|
|
this.openpgpkeysPrivate = PgpStore.openpgpkeysPrivate;
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.openPgpKeyForDeletion = ko.observable(null).deleteAccessHelper();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2017-06-29 00:25:53 +08:00
|
|
|
this.allowDraftAutosave = SettingsStore.allowDraftAutosave;
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.isHttps = bIsHttps;
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
addOpenPgpKey() {
|
|
|
|
showScreenPopup(require('View/Popup/AddOpenPgpKey'));
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
generateOpenPgpKey() {
|
|
|
|
showScreenPopup(require('View/Popup/NewOpenPgpKey'));
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
viewOpenPgpKey(openPgpKey) {
|
|
|
|
if (openPgpKey)
|
|
|
|
{
|
|
|
|
showScreenPopup(require('View/Popup/ViewOpenPgpKey'), [openPgpKey]);
|
|
|
|
}
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
/**
|
|
|
|
* @param {OpenPgpKeyModel} openPgpKeyToRemove
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
deleteOpenPgpKey(openPgpKeyToRemove) {
|
|
|
|
if (openPgpKeyToRemove && openPgpKeyToRemove.deleteAccess())
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2016-07-16 05:29:42 +08:00
|
|
|
this.openPgpKeyForDeletion(null);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
if (openPgpKeyToRemove && PgpStore.openpgpKeyring)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2016-07-16 05:29:42 +08:00
|
|
|
const findedItem = _.find(PgpStore.openpgpkeys(), (key) => openPgpKeyToRemove === key);
|
|
|
|
if (findedItem)
|
|
|
|
{
|
|
|
|
PgpStore.openpgpkeys.remove(findedItem);
|
|
|
|
delegateRunOnDestroy(findedItem);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
PgpStore
|
|
|
|
.openpgpKeyring[findedItem.isPrivate ? 'privateKeys' : 'publicKeys']
|
|
|
|
.removeForId(findedItem.guid);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
PgpStore.openpgpKeyring.store();
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
getApp().reloadOpenPgpKeys();
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
}
|
2017-06-29 00:25:53 +08:00
|
|
|
|
|
|
|
onBuild() {
|
|
|
|
_.delay(() => {
|
|
|
|
|
|
|
|
this.allowDraftAutosave.subscribe(
|
|
|
|
Remote.saveSettingsHelper('AllowDraftAutosave', boolToAjax)
|
|
|
|
);
|
|
|
|
|
|
|
|
}, Magics.Time50ms);
|
|
|
|
}
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 03:54:37 +08:00
|
|
|
export {OpenPgpUserSettings, OpenPgpUserSettings as default};
|