Code refactoring (5) (es5 -> es2015)

This commit is contained in:
RainLoop Team 2016-07-16 00:29:42 +03:00
parent c148e19ea3
commit cec53b111f
68 changed files with 2210 additions and 2472 deletions

View file

@ -1,76 +1,69 @@
var
_ = require('_'),
ko = require('ko'),
window = require('window'),
import _ from '_';
import ko from 'ko';
Utils = require('Common/Utils'),
import {delegateRunOnDestroy} from 'Common/Utils';
import {bIsHttps} from 'Common/Globals';
kn = require('Knoin/Knoin'),
import {showScreenPopup} from 'Knoin/Knoin';
PgpStore = require('Stores/User/Pgp');
import PgpStore from 'Stores/User/Pgp';
/**
* @constructor
*/
function OpenPgpUserSettings()
class OpenPgpUserSettings
{
this.openpgpkeys = PgpStore.openpgpkeys;
this.openpgpkeysPublic = PgpStore.openpgpkeysPublic;
this.openpgpkeysPrivate = PgpStore.openpgpkeysPrivate;
constructor() {
this.openpgpkeys = PgpStore.openpgpkeys;
this.openpgpkeysPublic = PgpStore.openpgpkeysPublic;
this.openpgpkeysPrivate = PgpStore.openpgpkeysPrivate;
this.openPgpKeyForDeletion = ko.observable(null).deleteAccessHelper();
this.openPgpKeyForDeletion = ko.observable(null).deleteAccessHelper();
this.isHttps = window.document && window.document.location ? 'https:' === window.document.location.protocol : false;
}
OpenPgpUserSettings.prototype.addOpenPgpKey = function()
{
kn.showScreenPopup(require('View/Popup/AddOpenPgpKey'));
};
OpenPgpUserSettings.prototype.generateOpenPgpKey = function()
{
kn.showScreenPopup(require('View/Popup/NewOpenPgpKey'));
};
OpenPgpUserSettings.prototype.viewOpenPgpKey = function(oOpenPgpKey)
{
if (oOpenPgpKey)
{
kn.showScreenPopup(require('View/Popup/ViewOpenPgpKey'), [oOpenPgpKey]);
this.isHttps = bIsHttps;
}
};
/**
* @param {OpenPgpKeyModel} oOpenPgpKeyToRemove
*/
OpenPgpUserSettings.prototype.deleteOpenPgpKey = function(oOpenPgpKeyToRemove)
{
if (oOpenPgpKeyToRemove && oOpenPgpKeyToRemove.deleteAccess())
{
this.openPgpKeyForDeletion(null);
addOpenPgpKey() {
showScreenPopup(require('View/Popup/AddOpenPgpKey'));
}
if (oOpenPgpKeyToRemove && PgpStore.openpgpKeyring)
generateOpenPgpKey() {
showScreenPopup(require('View/Popup/NewOpenPgpKey'));
}
viewOpenPgpKey(openPgpKey) {
if (openPgpKey)
{
var oFindedItem = _.find(PgpStore.openpgpkeys(), function(oOpenPgpKey) {
return oOpenPgpKeyToRemove === oOpenPgpKey;
});
if (oFindedItem)
{
PgpStore.openpgpkeys.remove(oFindedItem);
Utils.delegateRunOnDestroy(oFindedItem);
PgpStore.openpgpKeyring[oFindedItem.isPrivate ? 'privateKeys' : 'publicKeys']
.removeForId(oFindedItem.guid);
PgpStore.openpgpKeyring.store();
}
require('App/User').default.reloadOpenPgpKeys();
showScreenPopup(require('View/Popup/ViewOpenPgpKey'), [openPgpKey]);
}
}
};
/**
* @param {OpenPgpKeyModel} openPgpKeyToRemove
* @returns {void}
*/
deleteOpenPgpKey(openPgpKeyToRemove) {
if (openPgpKeyToRemove && openPgpKeyToRemove.deleteAccess())
{
this.openPgpKeyForDeletion(null);
if (openPgpKeyToRemove && PgpStore.openpgpKeyring)
{
const findedItem = _.find(PgpStore.openpgpkeys(), (key) => openPgpKeyToRemove === key);
if (findedItem)
{
PgpStore.openpgpkeys.remove(findedItem);
delegateRunOnDestroy(findedItem);
PgpStore
.openpgpKeyring[findedItem.isPrivate ? 'privateKeys' : 'publicKeys']
.removeForId(findedItem.guid);
PgpStore.openpgpKeyring.store();
}
require('App/User').default.reloadOpenPgpKeys();
}
}
}
}
export {OpenPgpUserSettings, OpenPgpUserSettings as default};