mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 04:29:21 +03:00
Code refactoring (5) (es5 -> es2015)
This commit is contained in:
parent
c148e19ea3
commit
cec53b111f
68 changed files with 2210 additions and 2472 deletions
|
|
@ -1,154 +1,135 @@
|
|||
|
||||
var
|
||||
window = require('window'),
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import window from 'window';
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Links = require('Common/Links'),
|
||||
import {Capa, StorageResultType} from 'Common/Enums';
|
||||
import {root} from 'Common/Links';
|
||||
|
||||
AccountStore = require('Stores/User/Account'),
|
||||
IdentityStore = require('Stores/User/Identity'),
|
||||
import {capa} from 'Storage/Settings';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import {showScreenPopup, routeOff, setHash} from 'Knoin/Knoin';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function AccountsUserSettings()
|
||||
import AccountStore from 'Stores/User/Account';
|
||||
import IdentityStore from 'Stores/User/Identity';
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
class AccountsUserSettings
|
||||
{
|
||||
this.allowAdditionalAccount = Settings.capa(Enums.Capa.AdditionalAccounts);
|
||||
this.allowIdentities = Settings.capa(Enums.Capa.Identities);
|
||||
constructor() {
|
||||
this.allowAdditionalAccount = capa(Capa.AdditionalAccounts);
|
||||
this.allowIdentities = capa(Capa.Identities);
|
||||
|
||||
this.accounts = AccountStore.accounts;
|
||||
this.identities = IdentityStore.identities;
|
||||
this.accounts = AccountStore.accounts;
|
||||
this.identities = IdentityStore.identities;
|
||||
|
||||
this.accountForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
this.identityForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
this.accountForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
this.identityForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
}
|
||||
|
||||
scrollableOptions(wrapper) {
|
||||
return {
|
||||
handle: '.drag-handle',
|
||||
containment: wrapper || 'parent',
|
||||
axis: 'y'
|
||||
};
|
||||
}
|
||||
|
||||
addNewAccount() {
|
||||
showScreenPopup(require('View/Popup/Account'));
|
||||
}
|
||||
|
||||
editAccount(account) {
|
||||
if (account && account.canBeEdit())
|
||||
{
|
||||
showScreenPopup(require('View/Popup/Account'), [account]);
|
||||
}
|
||||
}
|
||||
|
||||
addNewIdentity() {
|
||||
showScreenPopup(require('View/Popup/Identity'));
|
||||
}
|
||||
|
||||
editIdentity(identity) {
|
||||
showScreenPopup(require('View/Popup/Identity'), [identity]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {AccountModel} accountToRemove
|
||||
* @returns {void}
|
||||
*/
|
||||
deleteAccount(accountToRemove) {
|
||||
if (accountToRemove && accountToRemove.deleteAccess())
|
||||
{
|
||||
this.accountForDeletion(null);
|
||||
if (accountToRemove)
|
||||
{
|
||||
this.accounts.remove((account) => accountToRemove === account);
|
||||
|
||||
Remote.accountDelete(function(result, data) {
|
||||
|
||||
if (StorageResultType.Success === result && data && data.Result && data.Reload)
|
||||
{
|
||||
routeOff();
|
||||
setHash(root(), true);
|
||||
routeOff();
|
||||
|
||||
_.defer(() => window.location.reload());
|
||||
}
|
||||
else
|
||||
{
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
}
|
||||
|
||||
}, accountToRemove.email);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {IdentityModel} identityToRemove
|
||||
* @returns {void}
|
||||
*/
|
||||
deleteIdentity(identityToRemove) {
|
||||
if (identityToRemove && identityToRemove.deleteAccess())
|
||||
{
|
||||
this.identityForDeletion(null);
|
||||
|
||||
if (identityToRemove)
|
||||
{
|
||||
IdentityStore.identities.remove((oIdentity) => identityToRemove === oIdentity);
|
||||
|
||||
Remote.identityDelete(() => {
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
}, identityToRemove.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
accountsAndIdentitiesAfterMove() {
|
||||
Remote.accountsAndIdentitiesSortOrder(null,
|
||||
AccountStore.accountsEmails.peek(), IdentityStore.identitiesIDS.peek());
|
||||
}
|
||||
|
||||
onBuild(oDom) {
|
||||
var self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.accounts-list .account-item .e-action', function() {
|
||||
const account = ko.dataFor(this);
|
||||
if (account)
|
||||
{
|
||||
self.editAccount(account);
|
||||
}
|
||||
})
|
||||
.on('click', '.identities-list .identity-item .e-action', function() {
|
||||
const identity = ko.dataFor(this);
|
||||
if (identity)
|
||||
{
|
||||
self.editIdentity(identity);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
AccountsUserSettings.prototype.scrollableOptions = function(sWrapper)
|
||||
{
|
||||
return {
|
||||
handle: '.drag-handle',
|
||||
containment: sWrapper || 'parent',
|
||||
axis: 'y'
|
||||
};
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.addNewAccount = function()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'));
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.editAccount = function(oAccountItem)
|
||||
{
|
||||
if (oAccountItem && oAccountItem.canBeEdit())
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'), [oAccountItem]);
|
||||
}
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.addNewIdentity = function()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Identity'));
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.editIdentity = function(oIdentity)
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Identity'), [oIdentity]);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {AccountModel} oAccountToRemove
|
||||
*/
|
||||
AccountsUserSettings.prototype.deleteAccount = function(oAccountToRemove)
|
||||
{
|
||||
if (oAccountToRemove && oAccountToRemove.deleteAccess())
|
||||
{
|
||||
this.accountForDeletion(null);
|
||||
|
||||
var
|
||||
kn = require('Knoin/Knoin'),
|
||||
fRemoveAccount = function(oAccount) {
|
||||
return oAccountToRemove === oAccount;
|
||||
};
|
||||
|
||||
if (oAccountToRemove)
|
||||
{
|
||||
this.accounts.remove(fRemoveAccount);
|
||||
|
||||
Remote.accountDelete(function(sResult, oData) {
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData &&
|
||||
oData.Result && oData.Reload)
|
||||
{
|
||||
kn.routeOff();
|
||||
kn.setHash(Links.root(), true);
|
||||
kn.routeOff();
|
||||
|
||||
_.defer(function() {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
}
|
||||
|
||||
}, oAccountToRemove.email);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {IdentityModel} oIdentityToRemove
|
||||
*/
|
||||
AccountsUserSettings.prototype.deleteIdentity = function(oIdentityToRemove)
|
||||
{
|
||||
if (oIdentityToRemove && oIdentityToRemove.deleteAccess())
|
||||
{
|
||||
this.identityForDeletion(null);
|
||||
|
||||
if (oIdentityToRemove)
|
||||
{
|
||||
IdentityStore.identities.remove(function(oIdentity) {
|
||||
return oIdentityToRemove === oIdentity;
|
||||
});
|
||||
|
||||
Remote.identityDelete(function() {
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
}, oIdentityToRemove.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.accountsAndIdentitiesAfterMove = function()
|
||||
{
|
||||
Remote.accountsAndIdentitiesSortOrder(null,
|
||||
AccountStore.accountsEmails.peek(), IdentityStore.identitiesIDS.peek());
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.onBuild = function(oDom)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.accounts-list .account-item .e-action', function() {
|
||||
var oAccountItem = ko.dataFor(this);
|
||||
if (oAccountItem)
|
||||
{
|
||||
self.editAccount(oAccountItem);
|
||||
}
|
||||
})
|
||||
.on('click', '.identities-list .identity-item .e-action', function() {
|
||||
var oIdentityItem = ko.dataFor(this);
|
||||
if (oIdentityItem)
|
||||
{
|
||||
self.editIdentity(oIdentityItem);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export {AccountsUserSettings, AccountsUserSettings as default};
|
||||
|
|
|
|||
|
|
@ -1,117 +1,108 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {createCommand} from 'Common/Utils';
|
||||
import {getNotificationFromResponse, i18n} from 'Common/Translator';
|
||||
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function ChangePasswordUserSettings()
|
||||
class ChangePasswordUserSettings
|
||||
{
|
||||
this.changeProcess = ko.observable(false);
|
||||
constructor() {
|
||||
this.changeProcess = ko.observable(false);
|
||||
|
||||
this.errorDescription = ko.observable('');
|
||||
this.passwordMismatch = ko.observable(false);
|
||||
this.passwordUpdateError = ko.observable(false);
|
||||
this.passwordUpdateSuccess = ko.observable(false);
|
||||
this.errorDescription = ko.observable('');
|
||||
this.passwordMismatch = ko.observable(false);
|
||||
this.passwordUpdateError = ko.observable(false);
|
||||
this.passwordUpdateSuccess = ko.observable(false);
|
||||
|
||||
this.currentPassword = ko.observable('');
|
||||
this.currentPassword.error = ko.observable(false);
|
||||
this.newPassword = ko.observable('');
|
||||
this.newPassword2 = ko.observable('');
|
||||
|
||||
this.currentPassword.subscribe(function() {
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
this.currentPassword.error(false);
|
||||
}, this);
|
||||
|
||||
this.newPassword.subscribe(function() {
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
this.passwordMismatch(false);
|
||||
}, this);
|
||||
|
||||
this.newPassword2.subscribe(function() {
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
this.passwordMismatch(false);
|
||||
}, this);
|
||||
|
||||
this.saveNewPasswordCommand = Utils.createCommand(this, function() {
|
||||
|
||||
if (this.newPassword() !== this.newPassword2())
|
||||
{
|
||||
this.passwordMismatch(true);
|
||||
this.errorDescription(Translator.i18n('SETTINGS_CHANGE_PASSWORD/ERROR_PASSWORD_MISMATCH'));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.changeProcess(true);
|
||||
this.currentPassword = ko.observable('');
|
||||
this.currentPassword.error = ko.observable(false);
|
||||
this.newPassword = ko.observable('');
|
||||
this.newPassword2 = ko.observable('');
|
||||
|
||||
this.currentPassword.subscribe(() => {
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
this.currentPassword.error(false);
|
||||
});
|
||||
|
||||
this.newPassword.subscribe(() => {
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
this.passwordMismatch(false);
|
||||
this.errorDescription('');
|
||||
});
|
||||
|
||||
Remote.changePassword(this.onChangePasswordResponse, this.currentPassword(), this.newPassword());
|
||||
}
|
||||
this.newPassword2.subscribe(() => {
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
this.passwordMismatch(false);
|
||||
});
|
||||
|
||||
}, function() {
|
||||
return !this.changeProcess() && '' !== this.currentPassword() &&
|
||||
'' !== this.newPassword() && '' !== this.newPassword2();
|
||||
});
|
||||
this.saveNewPasswordCommand = createCommand(this, () => {
|
||||
if (this.newPassword() !== this.newPassword2())
|
||||
{
|
||||
this.passwordMismatch(true);
|
||||
this.errorDescription(i18n('SETTINGS_CHANGE_PASSWORD/ERROR_PASSWORD_MISMATCH'));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.changeProcess(true);
|
||||
|
||||
this.onChangePasswordResponse = _.bind(this.onChangePasswordResponse, this);
|
||||
}
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
this.currentPassword.error(false);
|
||||
this.passwordMismatch(false);
|
||||
this.errorDescription('');
|
||||
|
||||
ChangePasswordUserSettings.prototype.onHide = function()
|
||||
{
|
||||
this.changeProcess(false);
|
||||
this.currentPassword('');
|
||||
this.newPassword('');
|
||||
this.newPassword2('');
|
||||
this.errorDescription('');
|
||||
this.passwordMismatch(false);
|
||||
this.currentPassword.error(false);
|
||||
};
|
||||
Remote.changePassword(this.onChangePasswordResponse, this.currentPassword(), this.newPassword());
|
||||
}
|
||||
|
||||
ChangePasswordUserSettings.prototype.onChangePasswordResponse = function(sResult, oData)
|
||||
{
|
||||
this.changeProcess(false);
|
||||
this.passwordMismatch(false);
|
||||
this.errorDescription('');
|
||||
this.currentPassword.error(false);
|
||||
}, () => !this.changeProcess() && '' !== this.currentPassword() && '' !== this.newPassword() && '' !== this.newPassword2());
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
this.onChangePasswordResponse = _.bind(this.onChangePasswordResponse, this);
|
||||
}
|
||||
|
||||
onHide() {
|
||||
this.changeProcess(false);
|
||||
this.currentPassword('');
|
||||
this.newPassword('');
|
||||
this.newPassword2('');
|
||||
this.errorDescription('');
|
||||
this.passwordMismatch(false);
|
||||
this.currentPassword.error(false);
|
||||
}
|
||||
|
||||
this.passwordUpdateSuccess(true);
|
||||
onChangePasswordResponse(result, data) {
|
||||
this.changeProcess(false);
|
||||
this.passwordMismatch(false);
|
||||
this.errorDescription('');
|
||||
this.currentPassword.error(false);
|
||||
|
||||
require('App/User').default.setClientSideToken(oData.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oData && Enums.Notification.CurrentPasswordIncorrect === oData.ErrorCode)
|
||||
if (StorageResultType.Success === result && data && data.Result)
|
||||
{
|
||||
this.currentPassword.error(true);
|
||||
}
|
||||
this.currentPassword('');
|
||||
this.newPassword('');
|
||||
this.newPassword2('');
|
||||
|
||||
this.passwordUpdateError(true);
|
||||
this.errorDescription(
|
||||
Translator.getNotificationFromResponse(oData, Enums.Notification.CouldNotSaveNewPassword));
|
||||
this.passwordUpdateSuccess(true);
|
||||
this.currentPassword.error(false);
|
||||
|
||||
require('App/User').default.setClientSideToken(data.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data && Notification.CurrentPasswordIncorrect === data.ErrorCode)
|
||||
{
|
||||
this.currentPassword.error(true);
|
||||
}
|
||||
|
||||
this.passwordUpdateError(true);
|
||||
this.errorDescription(getNotificationFromResponse(data, Notification.CouldNotSaveNewPassword));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export {ChangePasswordUserSettings, ChangePasswordUserSettings as default};
|
||||
|
|
|
|||
|
|
@ -1,51 +1,48 @@
|
|||
|
||||
var
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
AppStore = require('Stores/User/App'),
|
||||
ContactStore = require('Stores/User/Contact'),
|
||||
import {Magics} from 'Common/Enums';
|
||||
import {boolToAjax} from 'Common/Utils';
|
||||
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import AppStore from 'Stores/User/App';
|
||||
import ContactStore from 'Stores/User/Contact';
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function ContactsUserSettings()
|
||||
class ContactsUserSettings
|
||||
{
|
||||
this.contactsAutosave = AppStore.contactsAutosave;
|
||||
constructor() {
|
||||
this.contactsAutosave = AppStore.contactsAutosave;
|
||||
|
||||
this.allowContactsSync = ContactStore.allowContactsSync;
|
||||
this.enableContactsSync = ContactStore.enableContactsSync;
|
||||
this.contactsSyncUrl = ContactStore.contactsSyncUrl;
|
||||
this.contactsSyncUser = ContactStore.contactsSyncUser;
|
||||
this.contactsSyncPass = ContactStore.contactsSyncPass;
|
||||
this.allowContactsSync = ContactStore.allowContactsSync;
|
||||
this.enableContactsSync = ContactStore.enableContactsSync;
|
||||
this.contactsSyncUrl = ContactStore.contactsSyncUrl;
|
||||
this.contactsSyncUser = ContactStore.contactsSyncUser;
|
||||
this.contactsSyncPass = ContactStore.contactsSyncPass;
|
||||
|
||||
this.saveTrigger = ko.computed(function() {
|
||||
return [
|
||||
this.saveTrigger = ko.computed(() => [
|
||||
this.enableContactsSync() ? '1' : '0',
|
||||
this.contactsSyncUrl(),
|
||||
this.contactsSyncUser(),
|
||||
this.contactsSyncPass()
|
||||
].join('|');
|
||||
}, this).extend({'throttle': 500});
|
||||
].join('|')).extend({throttle: Magics.Time500ms});
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
this.contactsAutosave.subscribe((value) => {
|
||||
Remote.saveSettings(null, {
|
||||
'ContactsAutosave': boolToAjax(value)
|
||||
});
|
||||
});
|
||||
|
||||
this.saveTrigger.subscribe(() => {
|
||||
Remote.saveContactsSyncData(null,
|
||||
this.enableContactsSync(),
|
||||
this.contactsSyncUrl(),
|
||||
this.contactsSyncUser(),
|
||||
this.contactsSyncPass()
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ContactsUserSettings.prototype.onBuild = function()
|
||||
{
|
||||
this.contactsAutosave.subscribe(function(bValue) {
|
||||
Remote.saveSettings(null, {
|
||||
'ContactsAutosave': bValue ? '1' : '0'
|
||||
});
|
||||
});
|
||||
|
||||
this.saveTrigger.subscribe(function() {
|
||||
Remote.saveContactsSyncData(null,
|
||||
this.enableContactsSync(),
|
||||
this.contactsSyncUrl(),
|
||||
this.contactsSyncUser(),
|
||||
this.contactsSyncPass()
|
||||
);
|
||||
}, this);
|
||||
};
|
||||
|
||||
export {ContactsUserSettings, ContactsUserSettings as default};
|
||||
|
|
|
|||
|
|
@ -1,234 +1,207 @@
|
|||
|
||||
var
|
||||
ko = require('ko'),
|
||||
_ = require('_'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {getNotification} from 'Common/Translator';
|
||||
|
||||
FilterStore = require('Stores/User/Filter'),
|
||||
import {
|
||||
windowResizeCallback, createCommand, isArray, trim, delegateRunOnDestroy
|
||||
} from 'Common/Utils';
|
||||
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import {showScreenPopup} from 'Knoin/Knoin';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function FiltersUserSettings()
|
||||
import FilterStore from 'Stores/User/Filter';
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
import {FilterModel} from 'Model/Filter';
|
||||
|
||||
class FiltersUserSettings
|
||||
{
|
||||
var self = this;
|
||||
constructor() {
|
||||
this.modules = FilterStore.modules;
|
||||
this.filters = FilterStore.filters;
|
||||
|
||||
this.modules = FilterStore.modules;
|
||||
this.filters = FilterStore.filters;
|
||||
this.inited = ko.observable(false);
|
||||
this.serverError = ko.observable(false);
|
||||
this.serverErrorDesc = ko.observable('');
|
||||
this.haveChanges = ko.observable(false);
|
||||
|
||||
this.inited = ko.observable(false);
|
||||
this.serverError = ko.observable(false);
|
||||
this.serverErrorDesc = ko.observable('');
|
||||
this.haveChanges = ko.observable(false);
|
||||
this.saveErrorText = ko.observable('');
|
||||
|
||||
this.saveErrorText = ko.observable('');
|
||||
this.filters.subscribe(windowResizeCallback);
|
||||
|
||||
this.filters.subscribe(Utils.windowResizeCallback);
|
||||
|
||||
this.serverError.subscribe(function(bValue) {
|
||||
if (!bValue)
|
||||
{
|
||||
this.serverErrorDesc('');
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.filterRaw = FilterStore.raw;
|
||||
this.filterRaw.capa = FilterStore.capa;
|
||||
this.filterRaw.active = ko.observable(false);
|
||||
this.filterRaw.allow = ko.observable(false);
|
||||
this.filterRaw.error = ko.observable(false);
|
||||
|
||||
this.filterForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend(
|
||||
{'toggleSubscribeProperty': [this, 'deleteAccess']});
|
||||
|
||||
this.saveChanges = Utils.createCommand(this, function() {
|
||||
|
||||
if (!this.filters.saving())
|
||||
{
|
||||
if (this.filterRaw.active() && '' === Utils.trim(this.filterRaw()))
|
||||
this.serverError.subscribe((value) => {
|
||||
if (!value)
|
||||
{
|
||||
this.filterRaw.error(true);
|
||||
return false;
|
||||
this.serverErrorDesc('');
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.filterRaw = FilterStore.raw;
|
||||
this.filterRaw.capa = FilterStore.capa;
|
||||
this.filterRaw.active = ko.observable(false);
|
||||
this.filterRaw.allow = ko.observable(false);
|
||||
this.filterRaw.error = ko.observable(false);
|
||||
|
||||
this.filterForDeletion = ko.observable(null)
|
||||
.extend({falseTimeout: 3000}).extend({toggleSubscribeProperty: [this, 'deleteAccess']});
|
||||
|
||||
this.saveChanges = createCommand(this, () => {
|
||||
if (!this.filters.saving())
|
||||
{
|
||||
if (this.filterRaw.active() && '' === trim(this.filterRaw()))
|
||||
{
|
||||
this.filterRaw.error(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.filters.saving(true);
|
||||
this.saveErrorText('');
|
||||
|
||||
Remote.filtersSave((result, data) => {
|
||||
this.filters.saving(false);
|
||||
|
||||
if (StorageResultType.Success === result && data && data.Result)
|
||||
{
|
||||
this.haveChanges(false);
|
||||
this.updateList();
|
||||
}
|
||||
else if (data && data.ErrorCode)
|
||||
{
|
||||
this.saveErrorText(data.ErrorMessageAdditional || getNotification(data.ErrorCode));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.saveErrorText(getNotification(Notification.CantSaveFilters));
|
||||
}
|
||||
|
||||
}, this.filters(), this.filterRaw(), this.filterRaw.active());
|
||||
}
|
||||
|
||||
this.filters.saving(true);
|
||||
return true;
|
||||
}, () => this.haveChanges());
|
||||
|
||||
this.filters.subscribe(() => {
|
||||
this.haveChanges(true);
|
||||
});
|
||||
|
||||
this.filterRaw.subscribe(() => {
|
||||
this.haveChanges(true);
|
||||
this.filterRaw.error(false);
|
||||
});
|
||||
|
||||
this.haveChanges.subscribe(() => {
|
||||
this.saveErrorText('');
|
||||
});
|
||||
|
||||
Remote.filtersSave(function(sResult, oData) {
|
||||
this.filterRaw.active.subscribe(() => {
|
||||
this.haveChanges(true);
|
||||
this.filterRaw.error(false);
|
||||
});
|
||||
}
|
||||
|
||||
self.filters.saving(false);
|
||||
scrollableOptions(wrapper) {
|
||||
return {
|
||||
handle: '.drag-handle',
|
||||
containment: wrapper || 'parent',
|
||||
axis: 'y'
|
||||
};
|
||||
}
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
updateList() {
|
||||
if (!this.filters.loading())
|
||||
{
|
||||
this.filters.loading(true);
|
||||
|
||||
Remote.filtersGet((result, data) => {
|
||||
|
||||
this.filters.loading(false);
|
||||
this.serverError(false);
|
||||
|
||||
if (StorageResultType.Success === result && data && data.Result && isArray(data.Result.Filters))
|
||||
{
|
||||
self.haveChanges(false);
|
||||
self.updateList();
|
||||
}
|
||||
else if (oData && oData.ErrorCode)
|
||||
{
|
||||
self.saveErrorText(oData.ErrorMessageAdditional || Translator.getNotification(oData.ErrorCode));
|
||||
this.inited(true);
|
||||
this.serverError(false);
|
||||
|
||||
this.filters(_.compact(_.map(data.Result.Filters, (aItem) => {
|
||||
const filter = new FilterModel();
|
||||
return (filter && filter.parse(aItem)) ? filter : null;
|
||||
})));
|
||||
|
||||
this.modules(data.Result.Modules ? data.Result.Modules : {});
|
||||
|
||||
this.filterRaw(data.Result.Raw || '');
|
||||
this.filterRaw.capa(isArray(data.Result.Capa) ? data.Result.Capa.join(' ') : '');
|
||||
this.filterRaw.active(!!data.Result.RawIsActive);
|
||||
this.filterRaw.allow(!!data.Result.RawIsAllow);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.saveErrorText(Translator.getNotification(Enums.Notification.CantSaveFilters));
|
||||
this.filters([]);
|
||||
this.modules({});
|
||||
this.filterRaw('');
|
||||
this.filterRaw.capa({});
|
||||
|
||||
this.serverError(true);
|
||||
this.serverErrorDesc(data && data.ErrorCode ? getNotification(data.ErrorCode) : getNotification(Notification.CantGetFilters));
|
||||
}
|
||||
|
||||
}, this.filters(), this.filterRaw(), this.filterRaw.active());
|
||||
this.haveChanges(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
deleteFilter(filter) {
|
||||
this.filters.remove(filter);
|
||||
delegateRunOnDestroy(filter);
|
||||
}
|
||||
|
||||
}, function() {
|
||||
return this.haveChanges();
|
||||
});
|
||||
addFilter() {
|
||||
const filter = new FilterModel();
|
||||
|
||||
this.filters.subscribe(function() {
|
||||
this.haveChanges(true);
|
||||
}, this);
|
||||
filter.generateID();
|
||||
showScreenPopup(require('View/Popup/Filter'), [filter, () => {
|
||||
this.filters.push(filter);
|
||||
this.filterRaw.active(false);
|
||||
}, false]);
|
||||
}
|
||||
|
||||
this.filterRaw.subscribe(function() {
|
||||
this.haveChanges(true);
|
||||
this.filterRaw.error(false);
|
||||
}, this);
|
||||
editFilter(filter) {
|
||||
const clonedFilter = filter.cloneSelf();
|
||||
|
||||
this.haveChanges.subscribe(function() {
|
||||
this.saveErrorText('');
|
||||
}, this);
|
||||
showScreenPopup(require('View/Popup/Filter'), [clonedFilter, () => {
|
||||
const
|
||||
filters = this.filters(),
|
||||
index = filters.indexOf(filter);
|
||||
|
||||
this.filterRaw.active.subscribe(function() {
|
||||
this.haveChanges(true);
|
||||
this.filterRaw.error(false);
|
||||
}, this);
|
||||
if (-1 < index && filters[index])
|
||||
{
|
||||
delegateRunOnDestroy(filters[index]);
|
||||
filters[index] = clonedFilter;
|
||||
|
||||
this.filters(filters);
|
||||
this.haveChanges(true);
|
||||
}
|
||||
}, true]);
|
||||
}
|
||||
|
||||
onBuild(oDom) {
|
||||
const self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.filter-item .e-action', function() {
|
||||
const filter = ko.dataFor(this);
|
||||
if (filter)
|
||||
{
|
||||
self.editFilter(filter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.updateList();
|
||||
}
|
||||
}
|
||||
|
||||
FiltersUserSettings.prototype.scrollableOptions = function(sWrapper)
|
||||
{
|
||||
return {
|
||||
handle: '.drag-handle',
|
||||
containment: sWrapper || 'parent',
|
||||
axis: 'y'
|
||||
};
|
||||
};
|
||||
|
||||
FiltersUserSettings.prototype.updateList = function()
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
FilterModel = require('Model/Filter').default;
|
||||
|
||||
if (!this.filters.loading())
|
||||
{
|
||||
this.filters.loading(true);
|
||||
|
||||
Remote.filtersGet(function(sResult, oData) {
|
||||
|
||||
self.filters.loading(false);
|
||||
self.serverError(false);
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData &&
|
||||
oData.Result && Utils.isArray(oData.Result.Filters))
|
||||
{
|
||||
self.inited(true);
|
||||
self.serverError(false);
|
||||
|
||||
var aResult = _.compact(_.map(oData.Result.Filters, function(aItem) {
|
||||
var oNew = new FilterModel();
|
||||
return (oNew && oNew.parse(aItem)) ? oNew : null;
|
||||
}));
|
||||
|
||||
self.filters(aResult);
|
||||
|
||||
self.modules(oData.Result.Modules ? oData.Result.Modules : {});
|
||||
|
||||
self.filterRaw(oData.Result.Raw || '');
|
||||
self.filterRaw.capa(Utils.isArray(oData.Result.Capa) ? oData.Result.Capa.join(' ') : '');
|
||||
self.filterRaw.active(!!oData.Result.RawIsActive);
|
||||
self.filterRaw.allow(!!oData.Result.RawIsAllow);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.filters([]);
|
||||
self.modules({});
|
||||
self.filterRaw('');
|
||||
self.filterRaw.capa({});
|
||||
|
||||
self.serverError(true);
|
||||
self.serverErrorDesc(oData && oData.ErrorCode ? Translator.getNotification(oData.ErrorCode) :
|
||||
Translator.getNotification(Enums.Notification.CantGetFilters));
|
||||
}
|
||||
|
||||
self.haveChanges(false);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
FiltersUserSettings.prototype.deleteFilter = function(oFilter)
|
||||
{
|
||||
this.filters.remove(oFilter);
|
||||
Utils.delegateRunOnDestroy(oFilter);
|
||||
};
|
||||
|
||||
FiltersUserSettings.prototype.addFilter = function()
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
FilterModel = require('Model/Filter').default,
|
||||
oNew = new FilterModel();
|
||||
|
||||
oNew.generateID();
|
||||
require('Knoin/Knoin').showScreenPopup(
|
||||
require('View/Popup/Filter'), [oNew, function() {
|
||||
self.filters.push(oNew);
|
||||
self.filterRaw.active(false);
|
||||
}, false]);
|
||||
};
|
||||
|
||||
FiltersUserSettings.prototype.editFilter = function(oEdit)
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
oCloned = oEdit.cloneSelf();
|
||||
|
||||
require('Knoin/Knoin').showScreenPopup(
|
||||
require('View/Popup/Filter'), [oCloned, function() {
|
||||
|
||||
var
|
||||
aFilters = self.filters(),
|
||||
iIndex = aFilters.indexOf(oEdit);
|
||||
|
||||
if (-1 < iIndex && aFilters[iIndex])
|
||||
{
|
||||
Utils.delegateRunOnDestroy(aFilters[iIndex]);
|
||||
aFilters[iIndex] = oCloned;
|
||||
|
||||
self.filters(aFilters);
|
||||
self.haveChanges(true);
|
||||
}
|
||||
|
||||
}, true]);
|
||||
};
|
||||
|
||||
FiltersUserSettings.prototype.onBuild = function(oDom)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.filter-item .e-action', function() {
|
||||
var oFilterItem = ko.dataFor(this);
|
||||
if (oFilterItem)
|
||||
{
|
||||
self.editFilter(oFilterItem);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
FiltersUserSettings.prototype.onShow = function()
|
||||
{
|
||||
this.updateList();
|
||||
};
|
||||
|
||||
export {FiltersUserSettings, FiltersUserSettings as default};
|
||||
|
|
|
|||
|
|
@ -1,192 +1,171 @@
|
|||
|
||||
var
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {ClientSideKeyName, Notification} from 'Common/Enums';
|
||||
import {trim, noop} from 'Common/Utils';
|
||||
import {getNotification, i18n} from 'Common/Translator';
|
||||
|
||||
Cache = require('Common/Cache'),
|
||||
import {removeFolderFromCacheList} from 'Common/Cache';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
Local = require('Storage/Client'),
|
||||
import {appSettingsGet} from 'Storage/Settings';
|
||||
import * as Local from 'Storage/Client';
|
||||
|
||||
FolderStore = require('Stores/User/Folder'),
|
||||
import {showScreenPopup} from 'Knoin/Knoin';
|
||||
|
||||
Promises = require('Promises/User/Ajax'),
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import FolderStore from 'Stores/User/Folder';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function FoldersUserSettings()
|
||||
import Promises from 'Promises/User/Ajax';
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
class FoldersUserSettings
|
||||
{
|
||||
this.displaySpecSetting = FolderStore.displaySpecSetting;
|
||||
this.folderList = FolderStore.folderList;
|
||||
constructor() {
|
||||
this.displaySpecSetting = FolderStore.displaySpecSetting;
|
||||
this.folderList = FolderStore.folderList;
|
||||
|
||||
this.folderListHelp = ko.observable('').extend({'throttle': 100});
|
||||
this.folderListHelp = ko.observable('').extend({throttle: 100});
|
||||
|
||||
this.loading = ko.computed(function() {
|
||||
this.loading = ko.computed(() => {
|
||||
const
|
||||
bLoading = FolderStore.foldersLoading(),
|
||||
bCreating = FolderStore.foldersCreating(),
|
||||
bDeleting = FolderStore.foldersDeleting(),
|
||||
bRenaming = FolderStore.foldersRenaming();
|
||||
|
||||
var
|
||||
bLoading = FolderStore.foldersLoading(),
|
||||
bCreating = FolderStore.foldersCreating(),
|
||||
bDeleting = FolderStore.foldersDeleting(),
|
||||
bRenaming = FolderStore.foldersRenaming();
|
||||
|
||||
return bLoading || bCreating || bDeleting || bRenaming;
|
||||
|
||||
}, this);
|
||||
|
||||
this.folderForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
|
||||
this.folderForEdit = ko.observable(null).extend({'toggleSubscribe': [this,
|
||||
function(oPrev) {
|
||||
if (oPrev)
|
||||
{
|
||||
oPrev.edited(false);
|
||||
}
|
||||
}, function(oNext) {
|
||||
if (oNext && oNext.canBeEdited())
|
||||
{
|
||||
oNext.edited(true);
|
||||
}
|
||||
}
|
||||
]});
|
||||
|
||||
this.useImapSubscribe = !!Settings.appSettingsGet('useImapSubscribe');
|
||||
}
|
||||
|
||||
FoldersUserSettings.prototype.folderEditOnEnter = function(oFolder)
|
||||
{
|
||||
var
|
||||
sEditName = oFolder ? Utils.trim(oFolder.nameForEdit()) : '';
|
||||
|
||||
if ('' !== sEditName && oFolder.name() !== sEditName)
|
||||
{
|
||||
Local.set(Enums.ClientSideKeyName.FoldersLashHash, '');
|
||||
|
||||
require('App/User').default.foldersPromisesActionHelper(
|
||||
Promises.folderRename(oFolder.fullNameRaw, sEditName, FolderStore.foldersRenaming),
|
||||
Enums.Notification.CantRenameFolder
|
||||
);
|
||||
|
||||
Cache.removeFolderFromCacheList(oFolder.fullNameRaw);
|
||||
|
||||
oFolder.name(sEditName);
|
||||
}
|
||||
|
||||
oFolder.edited(false);
|
||||
};
|
||||
|
||||
FoldersUserSettings.prototype.folderEditOnEsc = function(oFolder)
|
||||
{
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.edited(false);
|
||||
}
|
||||
};
|
||||
|
||||
FoldersUserSettings.prototype.onShow = function()
|
||||
{
|
||||
FolderStore.folderList.error('');
|
||||
};
|
||||
|
||||
FoldersUserSettings.prototype.onBuild = function(oDom)
|
||||
{
|
||||
var self = this;
|
||||
oDom
|
||||
.on('mouseover', '.delete-folder-parent', function() {
|
||||
self.folderListHelp(Translator.i18n('SETTINGS_FOLDERS/HELP_DELETE_FOLDER'));
|
||||
})
|
||||
.on('mouseover', '.subscribe-folder-parent', function() {
|
||||
self.folderListHelp(Translator.i18n('SETTINGS_FOLDERS/HELP_SHOW_HIDE_FOLDER'));
|
||||
})
|
||||
.on('mouseover', '.check-folder-parent', function() {
|
||||
self.folderListHelp(Translator.i18n('SETTINGS_FOLDERS/HELP_CHECK_FOR_NEW_MESSAGES'));
|
||||
})
|
||||
.on('mouseout', '.subscribe-folder-parent, .check-folder-parent, .delete-folder-parent', function() {
|
||||
self.folderListHelp('');
|
||||
return bLoading || bCreating || bDeleting || bRenaming;
|
||||
});
|
||||
};
|
||||
|
||||
FoldersUserSettings.prototype.createFolder = function()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/FolderCreate'));
|
||||
};
|
||||
this.folderForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
|
||||
FoldersUserSettings.prototype.systemFolder = function()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/FolderSystem'));
|
||||
};
|
||||
|
||||
FoldersUserSettings.prototype.deleteFolder = function(oFolderToRemove)
|
||||
{
|
||||
if (oFolderToRemove && oFolderToRemove.canBeDeleted() && oFolderToRemove.deleteAccess() &&
|
||||
0 === oFolderToRemove.privateMessageCountAll())
|
||||
{
|
||||
this.folderForDeletion(null);
|
||||
|
||||
var
|
||||
fRemoveFolder = function(oFolder) {
|
||||
|
||||
if (oFolderToRemove === oFolder)
|
||||
this.folderForEdit = ko.observable(null).extend({toggleSubscribe: [this,
|
||||
(prev) => {
|
||||
if (prev)
|
||||
{
|
||||
return true;
|
||||
prev.edited(false);
|
||||
}
|
||||
}, (next) => {
|
||||
if (next && next.canBeEdited())
|
||||
{
|
||||
next.edited(true);
|
||||
}
|
||||
}
|
||||
]});
|
||||
|
||||
oFolder.subFolders.remove(fRemoveFolder);
|
||||
return false;
|
||||
};
|
||||
this.useImapSubscribe = !!appSettingsGet('useImapSubscribe');
|
||||
}
|
||||
|
||||
if (oFolderToRemove)
|
||||
folderEditOnEnter(folder) {
|
||||
const nameToEdit = folder ? trim(folder.nameForEdit()) : '';
|
||||
|
||||
if ('' !== nameToEdit && folder.name() !== nameToEdit)
|
||||
{
|
||||
Local.set(Enums.ClientSideKeyName.FoldersLashHash, '');
|
||||
|
||||
FolderStore.folderList.remove(fRemoveFolder);
|
||||
Local.set(ClientSideKeyName.FoldersLashHash, '');
|
||||
|
||||
require('App/User').default.foldersPromisesActionHelper(
|
||||
Promises.folderDelete(oFolderToRemove.fullNameRaw, FolderStore.foldersDeleting),
|
||||
Enums.Notification.CantDeleteFolder
|
||||
Promises.folderRename(folder.fullNameRaw, nameToEdit, FolderStore.foldersRenaming),
|
||||
Notification.CantRenameFolder
|
||||
);
|
||||
|
||||
Cache.removeFolderFromCacheList(oFolderToRemove.fullNameRaw);
|
||||
removeFolderFromCacheList(folder.fullNameRaw);
|
||||
|
||||
folder.name(nameToEdit);
|
||||
}
|
||||
|
||||
folder.edited(false);
|
||||
}
|
||||
|
||||
folderEditOnEsc(folder) {
|
||||
if (folder)
|
||||
{
|
||||
folder.edited(false);
|
||||
}
|
||||
}
|
||||
else if (0 < oFolderToRemove.privateMessageCountAll())
|
||||
{
|
||||
FolderStore.folderList.error(Translator.getNotification(Enums.Notification.CantDeleteNonEmptyFolder));
|
||||
|
||||
onShow() {
|
||||
FolderStore.folderList.error('');
|
||||
}
|
||||
};
|
||||
|
||||
FoldersUserSettings.prototype.subscribeFolder = function(oFolder)
|
||||
{
|
||||
Local.set(Enums.ClientSideKeyName.FoldersLashHash, '');
|
||||
Remote.folderSetSubscribe(Utils.noop, oFolder.fullNameRaw, true);
|
||||
onBuild(oDom) {
|
||||
oDom
|
||||
.on('mouseover', '.delete-folder-parent', () => {
|
||||
this.folderListHelp(i18n('SETTINGS_FOLDERS/HELP_DELETE_FOLDER'));
|
||||
})
|
||||
.on('mouseover', '.subscribe-folder-parent', () => {
|
||||
this.folderListHelp(i18n('SETTINGS_FOLDERS/HELP_SHOW_HIDE_FOLDER'));
|
||||
})
|
||||
.on('mouseover', '.check-folder-parent', () => {
|
||||
this.folderListHelp(i18n('SETTINGS_FOLDERS/HELP_CHECK_FOR_NEW_MESSAGES'));
|
||||
})
|
||||
.on('mouseout', '.subscribe-folder-parent, .check-folder-parent, .delete-folder-parent', () => {
|
||||
this.folderListHelp('');
|
||||
});
|
||||
}
|
||||
|
||||
oFolder.subScribed(true);
|
||||
};
|
||||
createFolder() {
|
||||
showScreenPopup(require('View/Popup/FolderCreate'));
|
||||
}
|
||||
|
||||
FoldersUserSettings.prototype.unSubscribeFolder = function(oFolder)
|
||||
{
|
||||
Local.set(Enums.ClientSideKeyName.FoldersLashHash, '');
|
||||
Remote.folderSetSubscribe(Utils.noop, oFolder.fullNameRaw, false);
|
||||
systemFolder() {
|
||||
showScreenPopup(require('View/Popup/FolderSystem'));
|
||||
}
|
||||
|
||||
oFolder.subScribed(false);
|
||||
};
|
||||
deleteFolder(folderToRemove) {
|
||||
if (folderToRemove && folderToRemove.canBeDeleted() && folderToRemove.deleteAccess() &&
|
||||
0 === folderToRemove.privateMessageCountAll())
|
||||
{
|
||||
this.folderForDeletion(null);
|
||||
|
||||
FoldersUserSettings.prototype.checkableTrueFolder = function(oFolder)
|
||||
{
|
||||
Remote.folderSetCheckable(Utils.noop, oFolder.fullNameRaw, true);
|
||||
if (folderToRemove)
|
||||
{
|
||||
const
|
||||
fRemoveFolder = function(folder) {
|
||||
if (folderToRemove === folder)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
folder.subFolders.remove(fRemoveFolder);
|
||||
return false;
|
||||
};
|
||||
|
||||
oFolder.checkable(true);
|
||||
};
|
||||
Local.set(ClientSideKeyName.FoldersLashHash, '');
|
||||
|
||||
FoldersUserSettings.prototype.checkableFalseFolder = function(oFolder)
|
||||
{
|
||||
Remote.folderSetCheckable(Utils.noop, oFolder.fullNameRaw, false);
|
||||
FolderStore.folderList.remove(fRemoveFolder);
|
||||
|
||||
oFolder.checkable(false);
|
||||
};
|
||||
require('App/User').default.foldersPromisesActionHelper(
|
||||
Promises.folderDelete(folderToRemove.fullNameRaw, FolderStore.foldersDeleting),
|
||||
Notification.CantDeleteFolder
|
||||
);
|
||||
|
||||
removeFolderFromCacheList(folderToRemove.fullNameRaw);
|
||||
}
|
||||
}
|
||||
else if (0 < folderToRemove.privateMessageCountAll())
|
||||
{
|
||||
FolderStore.folderList.error(getNotification(Notification.CantDeleteNonEmptyFolder));
|
||||
}
|
||||
}
|
||||
|
||||
subscribeFolder(folder) {
|
||||
Local.set(ClientSideKeyName.FoldersLashHash, '');
|
||||
Remote.folderSetSubscribe(noop, folder.fullNameRaw, true);
|
||||
folder.subScribed(true);
|
||||
}
|
||||
|
||||
unSubscribeFolder(folder) {
|
||||
Local.set(ClientSideKeyName.FoldersLashHash, '');
|
||||
Remote.folderSetSubscribe(noop, folder.fullNameRaw, false);
|
||||
folder.subScribed(false);
|
||||
}
|
||||
|
||||
checkableTrueFolder(folder) {
|
||||
Remote.folderSetCheckable(noop, folder.fullNameRaw, true);
|
||||
folder.checkable(true);
|
||||
}
|
||||
|
||||
checkableFalseFolder(folder) {
|
||||
Remote.folderSetCheckable(noop, folder.fullNameRaw, false);
|
||||
folder.checkable(false);
|
||||
}
|
||||
}
|
||||
|
||||
export {FoldersUserSettings, FoldersUserSettings as default};
|
||||
|
|
|
|||
|
|
@ -1,224 +1,188 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Consts = require('Common/Consts'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {MESSAGES_PER_PAGE_VALUES} from 'Common/Consts';
|
||||
import {bAnimationSupported} from 'Common/Globals';
|
||||
|
||||
AppStore = require('Stores/User/App'),
|
||||
LanguageStore = require('Stores/Language'),
|
||||
SettingsStore = require('Stores/User/Settings'),
|
||||
IdentityStore = require('Stores/User/Identity'),
|
||||
NotificationStore = require('Stores/User/Notification'),
|
||||
MessageStore = require('Stores/User/Message'),
|
||||
import {SaveSettingsStep, Magics, EditorDefaultType, Layout} from 'Common/Enums';
|
||||
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import {
|
||||
settingsSaveHelperSimpleFunction,
|
||||
convertLangName, isArray, timeOutAction, boolToAjax
|
||||
} from 'Common/Utils';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function GeneralUserSettings()
|
||||
import {i18n, trigger as translatorTrigger, reload as translatorReload} from 'Common/Translator';
|
||||
|
||||
import {showScreenPopup} from 'Knoin/Knoin';
|
||||
|
||||
import AppStore from 'Stores/User/App';
|
||||
import LanguageStore from 'Stores/Language';
|
||||
import SettingsStore from 'Stores/User/Settings';
|
||||
import IdentityStore from 'Stores/User/Identity';
|
||||
import NotificationStore from 'Stores/User/Notification';
|
||||
import MessageStore from 'Stores/User/Message';
|
||||
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
class GeneralUserSettings
|
||||
{
|
||||
this.language = LanguageStore.language;
|
||||
this.languages = LanguageStore.languages;
|
||||
this.messagesPerPage = SettingsStore.messagesPerPage;
|
||||
this.messagesPerPageArray = Consts.MESSAGES_PER_PAGE_VALUES;
|
||||
constructor() {
|
||||
this.language = LanguageStore.language;
|
||||
this.languages = LanguageStore.languages;
|
||||
this.messagesPerPage = SettingsStore.messagesPerPage;
|
||||
this.messagesPerPageArray = MESSAGES_PER_PAGE_VALUES;
|
||||
|
||||
this.editorDefaultType = SettingsStore.editorDefaultType;
|
||||
this.layout = SettingsStore.layout;
|
||||
this.usePreviewPane = SettingsStore.usePreviewPane;
|
||||
this.editorDefaultType = SettingsStore.editorDefaultType;
|
||||
this.layout = SettingsStore.layout;
|
||||
this.usePreviewPane = SettingsStore.usePreviewPane;
|
||||
|
||||
this.soundNotificationIsSupported = NotificationStore.soundNotificationIsSupported;
|
||||
this.enableSoundNotification = NotificationStore.enableSoundNotification;
|
||||
this.soundNotificationIsSupported = NotificationStore.soundNotificationIsSupported;
|
||||
this.enableSoundNotification = NotificationStore.enableSoundNotification;
|
||||
|
||||
this.enableDesktopNotification = NotificationStore.enableDesktopNotification;
|
||||
this.isDesktopNotificationSupported = NotificationStore.isDesktopNotificationSupported;
|
||||
this.isDesktopNotificationDenied = NotificationStore.isDesktopNotificationDenied;
|
||||
this.enableDesktopNotification = NotificationStore.enableDesktopNotification;
|
||||
this.isDesktopNotificationSupported = NotificationStore.isDesktopNotificationSupported;
|
||||
this.isDesktopNotificationDenied = NotificationStore.isDesktopNotificationDenied;
|
||||
|
||||
this.showImages = SettingsStore.showImages;
|
||||
this.useCheckboxesInList = SettingsStore.useCheckboxesInList;
|
||||
this.threadsAllowed = AppStore.threadsAllowed;
|
||||
this.useThreads = SettingsStore.useThreads;
|
||||
this.replySameFolder = SettingsStore.replySameFolder;
|
||||
this.allowLanguagesOnSettings = AppStore.allowLanguagesOnSettings;
|
||||
this.showImages = SettingsStore.showImages;
|
||||
this.useCheckboxesInList = SettingsStore.useCheckboxesInList;
|
||||
this.threadsAllowed = AppStore.threadsAllowed;
|
||||
this.useThreads = SettingsStore.useThreads;
|
||||
this.replySameFolder = SettingsStore.replySameFolder;
|
||||
this.allowLanguagesOnSettings = AppStore.allowLanguagesOnSettings;
|
||||
|
||||
this.languageFullName = ko.computed(function() {
|
||||
return Utils.convertLangName(this.language());
|
||||
}, this);
|
||||
this.languageFullName = ko.computed(() => convertLangName(this.language()));
|
||||
this.languageTrigger = ko.observable(SaveSettingsStep.Idle).extend({throttle: Magics.Time100ms});
|
||||
|
||||
this.languageTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': Enums.Magics.Time100ms});
|
||||
this.mppTrigger = ko.observable(SaveSettingsStep.Idle);
|
||||
this.editorDefaultTypeTrigger = ko.observable(SaveSettingsStep.Idle);
|
||||
this.layoutTrigger = ko.observable(SaveSettingsStep.Idle);
|
||||
|
||||
this.mppTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||
this.editorDefaultTypeTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||
this.layoutTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||
this.isAnimationSupported = bAnimationSupported;
|
||||
|
||||
this.isAnimationSupported = Globals.bAnimationSupported;
|
||||
this.identities = IdentityStore.identities;
|
||||
|
||||
this.identities = IdentityStore.identities;
|
||||
this.identityMain = ko.computed(() => {
|
||||
const list = this.identities();
|
||||
return isArray(list) ? _.find(list, (item) => item && '' === item.id()) : null;
|
||||
});
|
||||
|
||||
this.identityMain = ko.computed(function() {
|
||||
var aList = this.identities();
|
||||
return Utils.isArray(aList) ? _.find(aList, function(oItem) {
|
||||
return oItem && '' === oItem.id();
|
||||
}) : null;
|
||||
}, this);
|
||||
this.identityMainDesc = ko.computed(() => {
|
||||
const identity = this.identityMain();
|
||||
return identity ? identity.formattedName() : '---';
|
||||
});
|
||||
|
||||
this.identityMainDesc = ko.computed(function() {
|
||||
var oIdentity = this.identityMain();
|
||||
return oIdentity ? oIdentity.formattedName() : '---';
|
||||
}, this);
|
||||
this.editorDefaultTypes = ko.computed(() => {
|
||||
translatorTrigger();
|
||||
return [
|
||||
{'id': EditorDefaultType.Html, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML')},
|
||||
{'id': EditorDefaultType.Plain, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN')},
|
||||
{'id': EditorDefaultType.HtmlForced, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML_FORCED')},
|
||||
{'id': EditorDefaultType.PlainForced, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN_FORCED')}
|
||||
];
|
||||
});
|
||||
|
||||
this.editorDefaultTypes = ko.computed(function() {
|
||||
Translator.trigger();
|
||||
return [
|
||||
{'id': Enums.EditorDefaultType.Html, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML')},
|
||||
{'id': Enums.EditorDefaultType.Plain, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN')},
|
||||
{'id': Enums.EditorDefaultType.HtmlForced, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML_FORCED')},
|
||||
{'id': Enums.EditorDefaultType.PlainForced, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN_FORCED')}
|
||||
];
|
||||
}, this);
|
||||
this.layoutTypes = ko.computed(() => {
|
||||
translatorTrigger();
|
||||
return [
|
||||
{'id': Layout.NoPreview, 'name': i18n('SETTINGS_GENERAL/LABEL_LAYOUT_NO_SPLIT')},
|
||||
{'id': Layout.SidePreview, 'name': i18n('SETTINGS_GENERAL/LABEL_LAYOUT_VERTICAL_SPLIT')},
|
||||
{'id': Layout.BottomPreview, 'name': i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT')}
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
this.layoutTypes = ko.computed(function() {
|
||||
Translator.trigger();
|
||||
return [
|
||||
{'id': Enums.Layout.NoPreview, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_NO_SPLIT')},
|
||||
{'id': Enums.Layout.SidePreview, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_VERTICAL_SPLIT')},
|
||||
{'id': Enums.Layout.BottomPreview, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT')}
|
||||
];
|
||||
}, this);
|
||||
editMainIdentity() {
|
||||
const identity = this.identityMain();
|
||||
if (identity)
|
||||
{
|
||||
showScreenPopup(require('View/Popup/Identity'), [identity]);
|
||||
}
|
||||
}
|
||||
|
||||
testSoundNotification() {
|
||||
NotificationStore.playSoundNotification(true);
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
_.delay(() => {
|
||||
const
|
||||
f0 = settingsSaveHelperSimpleFunction(this.editorDefaultTypeTrigger, this),
|
||||
f1 = settingsSaveHelperSimpleFunction(this.mppTrigger, this),
|
||||
f2 = settingsSaveHelperSimpleFunction(this.layoutTrigger, this),
|
||||
fReloadLanguageHelper = (saveSettingsStep) => () => {
|
||||
this.languageTrigger(saveSettingsStep);
|
||||
_.delay(() => this.languageTrigger(SaveSettingsStep.Idle), Magics.Time1s);
|
||||
};
|
||||
|
||||
this.language.subscribe((value) => {
|
||||
this.languageTrigger(SaveSettingsStep.Animate);
|
||||
translatorReload(false, value).then(
|
||||
fReloadLanguageHelper(SaveSettingsStep.TrueResult),
|
||||
fReloadLanguageHelper(SaveSettingsStep.FalseResult)
|
||||
).then(() => {
|
||||
Remote.saveSettings(null, {
|
||||
'Language': value
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
this.editorDefaultType.subscribe(Remote.saveSettingsHelper('EditorDefaultType', null, f0));
|
||||
this.messagesPerPage.subscribe(Remote.saveSettingsHelper('MPP', null, f1));
|
||||
this.showImages.subscribe(Remote.saveSettingsHelper('ShowImages', boolToAjax));
|
||||
|
||||
this.useCheckboxesInList.subscribe(Remote.saveSettingsHelper('UseCheckboxesInList', boolToAjax));
|
||||
|
||||
this.enableDesktopNotification.subscribe((value) => {
|
||||
timeOutAction('SaveDesktopNotifications', () => {
|
||||
Remote.saveSettings(null, {
|
||||
'DesktopNotifications': boolToAjax(value)
|
||||
});
|
||||
}, Magics.Time3s);
|
||||
});
|
||||
|
||||
this.enableSoundNotification.subscribe((value) => {
|
||||
timeOutAction('SaveSoundNotification', () => {
|
||||
Remote.saveSettings(null, {
|
||||
'SoundNotification': boolToAjax(value)
|
||||
});
|
||||
}, Magics.Time3s);
|
||||
});
|
||||
|
||||
this.replySameFolder.subscribe((value) => {
|
||||
timeOutAction('SaveReplySameFolder', () => {
|
||||
Remote.saveSettings(null, {
|
||||
'ReplySameFolder': boolToAjax(value)
|
||||
});
|
||||
}, Magics.Time3s);
|
||||
});
|
||||
|
||||
this.useThreads.subscribe((value) => {
|
||||
MessageStore.messageList([]);
|
||||
Remote.saveSettings(null, {
|
||||
'UseThreads': boolToAjax(value)
|
||||
});
|
||||
});
|
||||
|
||||
this.layout.subscribe(function(value) {
|
||||
MessageStore.messageList([]);
|
||||
Remote.saveSettings(f2, {
|
||||
'Layout': value
|
||||
});
|
||||
});
|
||||
}, Magics.Time50ms);
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.enableDesktopNotification.valueHasMutated();
|
||||
}
|
||||
|
||||
selectLanguage() {
|
||||
showScreenPopup(require('View/Popup/Languages'), [
|
||||
this.language, this.languages(), LanguageStore.userLanguage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
GeneralUserSettings.prototype.editMainIdentity = function()
|
||||
{
|
||||
var oIdentity = this.identityMain();
|
||||
if (oIdentity)
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Identity'), [oIdentity]);
|
||||
}
|
||||
};
|
||||
|
||||
GeneralUserSettings.prototype.testSoundNotification = function()
|
||||
{
|
||||
NotificationStore.playSoundNotification(true);
|
||||
};
|
||||
|
||||
GeneralUserSettings.prototype.onBuild = function()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
_.delay(function() {
|
||||
|
||||
var
|
||||
f0 = Utils.settingsSaveHelperSimpleFunction(self.editorDefaultTypeTrigger, self),
|
||||
f1 = Utils.settingsSaveHelperSimpleFunction(self.mppTrigger, self),
|
||||
f2 = Utils.settingsSaveHelperSimpleFunction(self.layoutTrigger, self),
|
||||
fReloadLanguageHelper = function(iSaveSettingsStep) {
|
||||
return function() {
|
||||
self.languageTrigger(iSaveSettingsStep);
|
||||
_.delay(function() {
|
||||
self.languageTrigger(Enums.SaveSettingsStep.Idle);
|
||||
}, Enums.Magics.Time1s);
|
||||
};
|
||||
};
|
||||
|
||||
self.language.subscribe(function(sValue) {
|
||||
|
||||
self.languageTrigger(Enums.SaveSettingsStep.Animate);
|
||||
|
||||
Translator.reload(false, sValue).then(
|
||||
fReloadLanguageHelper(Enums.SaveSettingsStep.TrueResult),
|
||||
fReloadLanguageHelper(Enums.SaveSettingsStep.FalseResult)
|
||||
).then(function() {
|
||||
Remote.saveSettings(null, {
|
||||
'Language': sValue
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
self.editorDefaultType.subscribe(function(sValue) {
|
||||
Remote.saveSettings(f0, {
|
||||
'EditorDefaultType': sValue
|
||||
});
|
||||
});
|
||||
|
||||
self.messagesPerPage.subscribe(function(iValue) {
|
||||
Remote.saveSettings(f1, {
|
||||
'MPP': iValue
|
||||
});
|
||||
});
|
||||
|
||||
self.showImages.subscribe(function(bValue) {
|
||||
Remote.saveSettings(null, {
|
||||
'ShowImages': bValue ? '1' : '0'
|
||||
});
|
||||
});
|
||||
|
||||
self.enableDesktopNotification.subscribe(function(bValue) {
|
||||
Utils.timeOutAction('SaveDesktopNotifications', function() {
|
||||
Remote.saveSettings(null, {
|
||||
'DesktopNotifications': bValue ? '1' : '0'
|
||||
});
|
||||
}, Enums.Magics.Time3s);
|
||||
});
|
||||
|
||||
self.enableSoundNotification.subscribe(function(bValue) {
|
||||
Utils.timeOutAction('SaveSoundNotification', function() {
|
||||
Remote.saveSettings(null, {
|
||||
'SoundNotification': bValue ? '1' : '0'
|
||||
});
|
||||
}, Enums.Magics.Time3s);
|
||||
});
|
||||
|
||||
self.replySameFolder.subscribe(function(bValue) {
|
||||
Utils.timeOutAction('SaveReplySameFolder', function() {
|
||||
Remote.saveSettings(null, {
|
||||
'ReplySameFolder': bValue ? '1' : '0'
|
||||
});
|
||||
}, Enums.Magics.Time3s);
|
||||
});
|
||||
|
||||
self.useThreads.subscribe(function(bValue) {
|
||||
|
||||
MessageStore.messageList([]);
|
||||
|
||||
Remote.saveSettings(null, {
|
||||
'UseThreads': bValue ? '1' : '0'
|
||||
});
|
||||
});
|
||||
|
||||
self.layout.subscribe(function(nValue) {
|
||||
|
||||
MessageStore.messageList([]);
|
||||
|
||||
Remote.saveSettings(f2, {
|
||||
'Layout': nValue
|
||||
});
|
||||
});
|
||||
|
||||
self.useCheckboxesInList.subscribe(function(bValue) {
|
||||
Remote.saveSettings(null, {
|
||||
'UseCheckboxesInList': bValue ? '1' : '0'
|
||||
});
|
||||
});
|
||||
|
||||
}, Enums.Magics.Time50ms);
|
||||
};
|
||||
|
||||
GeneralUserSettings.prototype.onShow = function()
|
||||
{
|
||||
this.enableDesktopNotification.valueHasMutated();
|
||||
};
|
||||
|
||||
GeneralUserSettings.prototype.selectLanguage = function()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Languages'), [
|
||||
this.language, this.languages(), LanguageStore.userLanguage()
|
||||
]);
|
||||
};
|
||||
|
||||
export {GeneralUserSettings, GeneralUserSettings as default};
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -1,68 +1,57 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {pInt, settingsSaveHelperSimpleFunction} from 'Common/Utils';
|
||||
import {Capa, SaveSettingsStep} from 'Common/Enums';
|
||||
import {i18n, trigger as translatorTrigger} from 'Common/Translator';
|
||||
|
||||
SettinsStore = require('Stores/User/Settings'),
|
||||
import {capa} from 'Storage/Settings';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
import {showScreenPopup} from 'Knoin/Knoin';
|
||||
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import SettinsStore from 'Stores/User/Settings';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function SecurityUserSettings()
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
class SecurityUserSettings
|
||||
{
|
||||
this.capaAutoLogout = Settings.capa(Enums.Capa.AutoLogout);
|
||||
this.capaTwoFactor = Settings.capa(Enums.Capa.TwoFactor);
|
||||
constructor() {
|
||||
this.capaAutoLogout = capa(Capa.AutoLogout);
|
||||
this.capaTwoFactor = capa(Capa.TwoFactor);
|
||||
|
||||
this.autoLogout = SettinsStore.autoLogout;
|
||||
this.autoLogout.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||
|
||||
this.autoLogoutOptions = ko.computed(function() {
|
||||
Translator.trigger();
|
||||
return [
|
||||
{'id': 0, 'name': Translator.i18n('SETTINGS_SECURITY/AUTOLOGIN_NEVER_OPTION_NAME')},
|
||||
{'id': 5, 'name': Translator.i18n('SETTINGS_SECURITY/AUTOLOGIN_MINUTES_OPTION_NAME', {'MINUTES': 5})},
|
||||
{'id': 10, 'name': Translator.i18n('SETTINGS_SECURITY/AUTOLOGIN_MINUTES_OPTION_NAME', {'MINUTES': 10})},
|
||||
{'id': 30, 'name': Translator.i18n('SETTINGS_SECURITY/AUTOLOGIN_MINUTES_OPTION_NAME', {'MINUTES': 30})},
|
||||
{'id': 60, 'name': Translator.i18n('SETTINGS_SECURITY/AUTOLOGIN_MINUTES_OPTION_NAME', {'MINUTES': 60})},
|
||||
{'id': 60 * 2, 'name': Translator.i18n('SETTINGS_SECURITY/AUTOLOGIN_HOURS_OPTION_NAME', {'HOURS': 2})},
|
||||
{'id': 60 * 5, 'name': Translator.i18n('SETTINGS_SECURITY/AUTOLOGIN_HOURS_OPTION_NAME', {'HOURS': 5})},
|
||||
{'id': 60 * 10, 'name': Translator.i18n('SETTINGS_SECURITY/AUTOLOGIN_HOURS_OPTION_NAME', {'HOURS': 10})}
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
SecurityUserSettings.prototype.configureTwoFactor = function()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/TwoFactorConfiguration'));
|
||||
};
|
||||
|
||||
SecurityUserSettings.prototype.onBuild = function()
|
||||
{
|
||||
if (this.capaAutoLogout)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
_.delay(function() {
|
||||
|
||||
var
|
||||
f0 = Utils.settingsSaveHelperSimpleFunction(self.autoLogout.trigger, self);
|
||||
|
||||
self.autoLogout.subscribe(function(sValue) {
|
||||
Remote.saveSettings(f0, {
|
||||
'AutoLogout': Utils.pInt(sValue)
|
||||
});
|
||||
});
|
||||
this.autoLogout = SettinsStore.autoLogout;
|
||||
this.autoLogout.trigger = ko.observable(SaveSettingsStep.Idle);
|
||||
|
||||
this.autoLogoutOptions = ko.computed(() => {
|
||||
translatorTrigger();
|
||||
return [
|
||||
{'id': 0, 'name': i18n('SETTINGS_SECURITY/AUTOLOGIN_NEVER_OPTION_NAME')},
|
||||
{'id': 5, 'name': i18n('SETTINGS_SECURITY/AUTOLOGIN_MINUTES_OPTION_NAME', {'MINUTES': 5})},
|
||||
{'id': 10, 'name': i18n('SETTINGS_SECURITY/AUTOLOGIN_MINUTES_OPTION_NAME', {'MINUTES': 10})},
|
||||
{'id': 30, 'name': i18n('SETTINGS_SECURITY/AUTOLOGIN_MINUTES_OPTION_NAME', {'MINUTES': 30})},
|
||||
{'id': 60, 'name': i18n('SETTINGS_SECURITY/AUTOLOGIN_MINUTES_OPTION_NAME', {'MINUTES': 60})},
|
||||
{'id': 60 * 2, 'name': i18n('SETTINGS_SECURITY/AUTOLOGIN_HOURS_OPTION_NAME', {'HOURS': 2})},
|
||||
{'id': 60 * 5, 'name': i18n('SETTINGS_SECURITY/AUTOLOGIN_HOURS_OPTION_NAME', {'HOURS': 5})},
|
||||
{'id': 60 * 10, 'name': i18n('SETTINGS_SECURITY/AUTOLOGIN_HOURS_OPTION_NAME', {'HOURS': 10})}
|
||||
];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
configureTwoFactor() {
|
||||
showScreenPopup(require('View/Popup/TwoFactorConfiguration'));
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
if (this.capaAutoLogout)
|
||||
{
|
||||
_.delay(() => {
|
||||
const f0 = settingsSaveHelperSimpleFunction(this.autoLogout.trigger, this);
|
||||
|
||||
this.autoLogout.subscribe(Remote.saveSettingsHelper('AutoLogout', pInt, f0));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {SecurityUserSettings, SecurityUserSettings as default};
|
||||
|
|
|
|||
|
|
@ -1,73 +1,70 @@
|
|||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function SocialUserSettings()
|
||||
import {createCommand} from 'Common/Utils';
|
||||
|
||||
import SocialStore from 'Stores/Social';
|
||||
|
||||
class SocialUserSettings
|
||||
{
|
||||
var
|
||||
Utils = require('Common/Utils'),
|
||||
SocialStore = require('Stores/Social');
|
||||
constructor() {
|
||||
this.googleEnable = SocialStore.google.enabled;
|
||||
this.googleEnableAuth = SocialStore.google.capa.auth;
|
||||
this.googleEnableAuthFast = SocialStore.google.capa.authFast;
|
||||
this.googleEnableDrive = SocialStore.google.capa.drive;
|
||||
this.googleEnablePreview = SocialStore.google.capa.preview;
|
||||
|
||||
this.googleEnable = SocialStore.google.enabled;
|
||||
this.googleEnableAuth = SocialStore.google.capa.auth;
|
||||
this.googleEnableAuthFast = SocialStore.google.capa.authFast;
|
||||
this.googleEnableDrive = SocialStore.google.capa.drive;
|
||||
this.googleEnablePreview = SocialStore.google.capa.preview;
|
||||
this.googleActions = SocialStore.google.loading;
|
||||
this.googleLoggined = SocialStore.google.loggined;
|
||||
this.googleUserName = SocialStore.google.userName;
|
||||
|
||||
this.googleActions = SocialStore.google.loading;
|
||||
this.googleLoggined = SocialStore.google.loggined;
|
||||
this.googleUserName = SocialStore.google.userName;
|
||||
this.facebookEnable = SocialStore.facebook.enabled;
|
||||
|
||||
this.facebookEnable = SocialStore.facebook.enabled;
|
||||
this.facebookActions = SocialStore.facebook.loading;
|
||||
this.facebookLoggined = SocialStore.facebook.loggined;
|
||||
this.facebookUserName = SocialStore.facebook.userName;
|
||||
|
||||
this.facebookActions = SocialStore.facebook.loading;
|
||||
this.facebookLoggined = SocialStore.facebook.loggined;
|
||||
this.facebookUserName = SocialStore.facebook.userName;
|
||||
this.twitterEnable = SocialStore.twitter.enabled;
|
||||
|
||||
this.twitterEnable = SocialStore.twitter.enabled;
|
||||
this.twitterActions = SocialStore.twitter.loading;
|
||||
this.twitterLoggined = SocialStore.twitter.loggined;
|
||||
this.twitterUserName = SocialStore.twitter.userName;
|
||||
|
||||
this.twitterActions = SocialStore.twitter.loading;
|
||||
this.twitterLoggined = SocialStore.twitter.loggined;
|
||||
this.twitterUserName = SocialStore.twitter.userName;
|
||||
this.connectGoogle = createCommand(this, () => {
|
||||
if (!this.googleLoggined())
|
||||
{
|
||||
this.getApp().googleConnect();
|
||||
}
|
||||
}, () => !this.googleLoggined() && !this.googleActions());
|
||||
|
||||
this.connectGoogle = Utils.createCommand(this, function() {
|
||||
if (!this.googleLoggined())
|
||||
{
|
||||
require('App/User').default.googleConnect();
|
||||
}
|
||||
}, function() {
|
||||
return !this.googleLoggined() && !this.googleActions();
|
||||
});
|
||||
this.disconnectGoogle = createCommand(this, () => {
|
||||
this.getApp().googleDisconnect();
|
||||
});
|
||||
|
||||
this.disconnectGoogle = Utils.createCommand(this, function() {
|
||||
require('App/User').default.googleDisconnect();
|
||||
});
|
||||
this.connectFacebook = createCommand(this, () => {
|
||||
if (!this.facebookLoggined())
|
||||
{
|
||||
this.getApp().facebookConnect();
|
||||
}
|
||||
}, () => !this.facebookLoggined() && !this.facebookActions());
|
||||
|
||||
this.connectFacebook = Utils.createCommand(this, function() {
|
||||
if (!this.facebookLoggined())
|
||||
{
|
||||
require('App/User').default.facebookConnect();
|
||||
}
|
||||
}, function() {
|
||||
return !this.facebookLoggined() && !this.facebookActions();
|
||||
});
|
||||
this.disconnectFacebook = createCommand(this, () => {
|
||||
this.getApp().facebookDisconnect();
|
||||
});
|
||||
|
||||
this.disconnectFacebook = Utils.createCommand(this, function() {
|
||||
require('App/User').default.facebookDisconnect();
|
||||
});
|
||||
this.connectTwitter = createCommand(this, () => {
|
||||
if (!this.twitterLoggined())
|
||||
{
|
||||
this.getApp().twitterConnect();
|
||||
}
|
||||
}, () => !this.twitterLoggined() && !this.twitterActions());
|
||||
|
||||
this.connectTwitter = Utils.createCommand(this, function() {
|
||||
if (!this.twitterLoggined())
|
||||
{
|
||||
require('App/User').default.twitterConnect();
|
||||
}
|
||||
}, function() {
|
||||
return !this.twitterLoggined() && !this.twitterActions();
|
||||
});
|
||||
this.disconnectTwitter = createCommand(this, () => {
|
||||
this.getApp().twitterDisconnect();
|
||||
});
|
||||
}
|
||||
|
||||
this.disconnectTwitter = Utils.createCommand(this, function() {
|
||||
require('App/User').default.twitterDisconnect();
|
||||
});
|
||||
getApp() {
|
||||
return require('App/User').default;
|
||||
}
|
||||
}
|
||||
|
||||
export {SocialUserSettings, SocialUserSettings as default};
|
||||
|
|
|
|||
|
|
@ -1,98 +1,81 @@
|
|||
|
||||
var
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Translator = require('Common/Translator'),
|
||||
import {i18n} from 'Common/Translator';
|
||||
|
||||
TemplateStore = require('Stores/User/Template'),
|
||||
import {showScreenPopup} from 'Knoin/Knoin';
|
||||
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import TemplateStore from 'Stores/User/Template';
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function TemplatesUserSettings()
|
||||
class TemplatesUserSettings
|
||||
{
|
||||
this.templates = TemplateStore.templates;
|
||||
constructor() {
|
||||
this.templates = TemplateStore.templates;
|
||||
|
||||
this.processText = ko.computed(function() {
|
||||
return TemplateStore.templates.loading() ? Translator.i18n('SETTINGS_TEMPLETS/LOADING_PROCESS') : '';
|
||||
}, this);
|
||||
this.processText = ko.computed(() => (TemplateStore.templates.loading() ? i18n('SETTINGS_TEMPLETS/LOADING_PROCESS') : ''));
|
||||
this.visibility = ko.computed(() => ('' === this.processText() ? 'hidden' : 'visible'));
|
||||
|
||||
this.visibility = ko.computed(function() {
|
||||
return '' === this.processText() ? 'hidden' : 'visible';
|
||||
}, this);
|
||||
|
||||
this.templateForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
}
|
||||
|
||||
TemplatesUserSettings.prototype.scrollableOptions = function(sWrapper)
|
||||
{
|
||||
return {
|
||||
handle: '.drag-handle',
|
||||
containment: sWrapper || 'parent',
|
||||
axis: 'y'
|
||||
};
|
||||
};
|
||||
|
||||
TemplatesUserSettings.prototype.addNewTemplate = function()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Template'));
|
||||
};
|
||||
|
||||
TemplatesUserSettings.prototype.editTemplate = function(oTemplateItem)
|
||||
{
|
||||
if (oTemplateItem)
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Template'), [oTemplateItem]);
|
||||
this.templateForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {AccountModel} oTemplateToRemove
|
||||
*/
|
||||
TemplatesUserSettings.prototype.deleteTemplate = function(oTemplateToRemove)
|
||||
{
|
||||
if (oTemplateToRemove && oTemplateToRemove.deleteAccess())
|
||||
{
|
||||
this.templateForDeletion(null);
|
||||
scrollableOptions(sWrapper) {
|
||||
return {
|
||||
handle: '.drag-handle',
|
||||
containment: sWrapper || 'parent',
|
||||
axis: 'y'
|
||||
};
|
||||
}
|
||||
|
||||
var
|
||||
self = this,
|
||||
fRemoveAccount = function(oAccount) {
|
||||
return oTemplateToRemove === oAccount;
|
||||
};
|
||||
addNewTemplate() {
|
||||
showScreenPopup(require('View/Popup/Template'));
|
||||
}
|
||||
|
||||
if (oTemplateToRemove)
|
||||
editTemplate(oTemplateItem) {
|
||||
if (oTemplateItem)
|
||||
{
|
||||
this.templates.remove(fRemoveAccount);
|
||||
|
||||
Remote.templateDelete(function() {
|
||||
self.reloadTemplates();
|
||||
}, oTemplateToRemove.id);
|
||||
showScreenPopup(require('View/Popup/Template'), [oTemplateItem]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TemplatesUserSettings.prototype.reloadTemplates = function()
|
||||
{
|
||||
require('App/User').default.templates();
|
||||
};
|
||||
deleteTemplate(templateToRemove) {
|
||||
if (templateToRemove && templateToRemove.deleteAccess())
|
||||
{
|
||||
this.templateForDeletion(null);
|
||||
|
||||
TemplatesUserSettings.prototype.onBuild = function(oDom)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.templates-list .template-item .e-action', function() {
|
||||
var oTemplateItem = ko.dataFor(this);
|
||||
if (oTemplateItem)
|
||||
if (templateToRemove)
|
||||
{
|
||||
self.editTemplate(oTemplateItem);
|
||||
}
|
||||
});
|
||||
this.templates.remove((template) => templateToRemove === template);
|
||||
|
||||
this.reloadTemplates();
|
||||
};
|
||||
Remote.templateDelete(() => {
|
||||
this.reloadTemplates();
|
||||
}, templateToRemove.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reloadTemplates() {
|
||||
this.getApp().templates();
|
||||
}
|
||||
|
||||
getApp() {
|
||||
return require('App/User').default;
|
||||
}
|
||||
|
||||
onBuild(oDom) {
|
||||
var self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.templates-list .template-item .e-action', function() {
|
||||
const template = ko.dataFor(this);
|
||||
if (template)
|
||||
{
|
||||
self.editTemplate(template);
|
||||
}
|
||||
});
|
||||
|
||||
this.reloadTemplates();
|
||||
}
|
||||
}
|
||||
|
||||
export {TemplatesUserSettings, TemplatesUserSettings as default};
|
||||
|
|
|
|||
|
|
@ -1,177 +1,159 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
$ = require('$'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import $ from '$';
|
||||
import ko from 'ko';
|
||||
|
||||
Jua = require('Jua'),
|
||||
import Jua from 'Jua';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Links = require('Common/Links'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {SaveSettingsStep, UploadErrorCode, Capa, Magics} from 'Common/Enums';
|
||||
import {changeTheme, convertThemeName} from 'Common/Utils';
|
||||
import {userBackground, themePreviewLink, uploadBackground} from 'Common/Links';
|
||||
import {i18n} from 'Common/Translator';
|
||||
|
||||
ThemeStore = require('Stores/Theme'),
|
||||
import {capa} from 'Storage/Settings';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
import ThemeStore from 'Stores/Theme';
|
||||
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function ThemesUserSettings()
|
||||
class ThemesUserSettings
|
||||
{
|
||||
this.theme = ThemeStore.theme;
|
||||
this.themes = ThemeStore.themes;
|
||||
this.themesObjects = ko.observableArray([]);
|
||||
constructor() {
|
||||
this.theme = ThemeStore.theme;
|
||||
this.themes = ThemeStore.themes;
|
||||
this.themesObjects = ko.observableArray([]);
|
||||
|
||||
this.background = {};
|
||||
this.background.name = ThemeStore.themeBackgroundName;
|
||||
this.background.hash = ThemeStore.themeBackgroundHash;
|
||||
this.background.uploaderButton = ko.observable(null);
|
||||
this.background.loading = ko.observable(false);
|
||||
this.background.error = ko.observable('');
|
||||
this.background = {};
|
||||
this.background.name = ThemeStore.themeBackgroundName;
|
||||
this.background.hash = ThemeStore.themeBackgroundHash;
|
||||
this.background.uploaderButton = ko.observable(null);
|
||||
this.background.loading = ko.observable(false);
|
||||
this.background.error = ko.observable('');
|
||||
|
||||
this.capaUserBackground = ko.observable(Settings.capa(Enums.Capa.UserBackground));
|
||||
this.capaUserBackground = ko.observable(capa(Capa.UserBackground));
|
||||
|
||||
this.themeTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': 100});
|
||||
this.themeTrigger = ko.observable(SaveSettingsStep.Idle).extend({throttle: Magics.Time100ms});
|
||||
|
||||
this.iTimer = 0;
|
||||
this.oThemeAjaxRequest = null;
|
||||
this.iTimer = 0;
|
||||
this.oThemeAjaxRequest = null;
|
||||
|
||||
this.theme.subscribe(function(sValue) {
|
||||
|
||||
_.each(this.themesObjects(), function(oTheme) {
|
||||
oTheme.selected(sValue === oTheme.name);
|
||||
});
|
||||
|
||||
Utils.changeTheme(sValue, this.themeTrigger);
|
||||
|
||||
Remote.saveSettings(null, {
|
||||
'Theme': sValue
|
||||
});
|
||||
|
||||
}, this);
|
||||
|
||||
this.background.hash.subscribe(function(sValue) {
|
||||
|
||||
var $oBg = $('#rl-bg');
|
||||
if (!sValue)
|
||||
{
|
||||
if ($oBg.data('backstretch'))
|
||||
{
|
||||
$oBg.backstretch('destroy').attr('style', '');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#rl-bg').attr('style', 'background-image: none !important;').backstretch(
|
||||
Links.userBackground(sValue), {
|
||||
'fade': 1000, 'centeredX': true, 'centeredY': true
|
||||
}).removeAttr('style');
|
||||
}
|
||||
|
||||
}, this);
|
||||
}
|
||||
|
||||
ThemesUserSettings.prototype.onBuild = function()
|
||||
{
|
||||
var sCurrentTheme = this.theme();
|
||||
this.themesObjects(_.map(this.themes(), function(sTheme) {
|
||||
return {
|
||||
'name': sTheme,
|
||||
'nameDisplay': Utils.convertThemeName(sTheme),
|
||||
'selected': ko.observable(sTheme === sCurrentTheme),
|
||||
'themePreviewSrc': Links.themePreviewLink(sTheme)
|
||||
};
|
||||
}));
|
||||
|
||||
this.initUploader();
|
||||
};
|
||||
|
||||
ThemesUserSettings.prototype.onShow = function()
|
||||
{
|
||||
this.background.error('');
|
||||
};
|
||||
|
||||
ThemesUserSettings.prototype.clearBackground = function()
|
||||
{
|
||||
if (this.capaUserBackground())
|
||||
{
|
||||
var self = this;
|
||||
Remote.clearUserBackground(function() {
|
||||
self.background.name('');
|
||||
self.background.hash('');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
ThemesUserSettings.prototype.initUploader = function()
|
||||
{
|
||||
if (this.background.uploaderButton() && this.capaUserBackground())
|
||||
{
|
||||
var
|
||||
oJua = new Jua({
|
||||
'action': Links.uploadBackground(),
|
||||
'name': 'uploader',
|
||||
'queueSize': 1,
|
||||
'multipleSizeLimit': 1,
|
||||
'disableDragAndDrop': true,
|
||||
'disableMultiple': true,
|
||||
'clickElement': this.background.uploaderButton()
|
||||
this.theme.subscribe((value) => {
|
||||
_.each(this.themesObjects(), (theme) => {
|
||||
theme.selected(value === theme.name);
|
||||
});
|
||||
|
||||
oJua
|
||||
.on('onStart', _.bind(function() {
|
||||
changeTheme(value, this.themeTrigger);
|
||||
|
||||
this.background.loading(true);
|
||||
this.background.error('');
|
||||
Remote.saveSettings(null, {
|
||||
'Theme': value
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
}, this))
|
||||
.on('onComplete', _.bind(function(sId, bResult, oData) {
|
||||
|
||||
this.background.loading(false);
|
||||
|
||||
if (bResult && sId && oData && oData.Result && oData.Result.Name && oData.Result.Hash)
|
||||
this.background.hash.subscribe((value) => {
|
||||
const $bg = $('#rl-bg');
|
||||
if (!value)
|
||||
{
|
||||
if ($bg.data('backstretch'))
|
||||
{
|
||||
this.background.name(oData.Result.Name);
|
||||
this.background.hash(oData.Result.Hash);
|
||||
$bg.backstretch('destroy').attr('style', '');
|
||||
}
|
||||
else
|
||||
{
|
||||
this.background.name('');
|
||||
this.background.hash('');
|
||||
|
||||
var sError = '';
|
||||
if (oData.ErrorCode)
|
||||
{
|
||||
switch (oData.ErrorCode)
|
||||
{
|
||||
case Enums.UploadErrorCode.FileIsTooBig:
|
||||
sError = Translator.i18n('SETTINGS_THEMES/ERROR_FILE_IS_TOO_BIG');
|
||||
break;
|
||||
case Enums.UploadErrorCode.FileType:
|
||||
sError = Translator.i18n('SETTINGS_THEMES/ERROR_FILE_TYPE_ERROR');
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
}
|
||||
|
||||
if (!sError && oData.ErrorMessage)
|
||||
{
|
||||
sError = oData.ErrorMessage;
|
||||
}
|
||||
|
||||
this.background.error(sError || Translator.i18n('SETTINGS_THEMES/ERROR_UNKNOWN'));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
$bg.attr('style', 'background-image: none !important;').backstretch(userBackground(value), {
|
||||
fade: 1000, centeredX: true, centeredY: true
|
||||
}).removeAttr('style');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onBuild() {
|
||||
const currentTheme = this.theme();
|
||||
|
||||
this.themesObjects(_.map(this.themes(), (theme) => ({
|
||||
name: theme,
|
||||
nameDisplay: convertThemeName(theme),
|
||||
selected: ko.observable(theme === currentTheme),
|
||||
themePreviewSrc: themePreviewLink(theme)
|
||||
})));
|
||||
|
||||
this.initUploader();
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.background.error('');
|
||||
}
|
||||
|
||||
clearBackground() {
|
||||
if (this.capaUserBackground())
|
||||
{
|
||||
Remote.clearUserBackground(() => {
|
||||
this.background.name('');
|
||||
this.background.hash('');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
initUploader() {
|
||||
if (this.background.uploaderButton() && this.capaUserBackground())
|
||||
{
|
||||
const
|
||||
oJua = new Jua({
|
||||
'action': uploadBackground(),
|
||||
'name': 'uploader',
|
||||
'queueSize': 1,
|
||||
'multipleSizeLimit': 1,
|
||||
'disableDragAndDrop': true,
|
||||
'disableMultiple': true,
|
||||
'clickElement': this.background.uploaderButton()
|
||||
});
|
||||
|
||||
oJua
|
||||
.on('onStart', () => {
|
||||
this.background.loading(true);
|
||||
this.background.error('');
|
||||
return true;
|
||||
})
|
||||
.on('onComplete', (id, result, data) => {
|
||||
this.background.loading(false);
|
||||
|
||||
if (result && id && data && data.Result && data.Result.Name && data.Result.Hash)
|
||||
{
|
||||
this.background.name(data.Result.Name);
|
||||
this.background.hash(data.Result.Hash);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.background.name('');
|
||||
this.background.hash('');
|
||||
|
||||
let errorMsg = '';
|
||||
if (data.ErrorCode)
|
||||
{
|
||||
switch (data.ErrorCode)
|
||||
{
|
||||
case UploadErrorCode.FileIsTooBig:
|
||||
errorMsg = i18n('SETTINGS_THEMES/ERROR_FILE_IS_TOO_BIG');
|
||||
break;
|
||||
case UploadErrorCode.FileType:
|
||||
errorMsg = i18n('SETTINGS_THEMES/ERROR_FILE_TYPE_ERROR');
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
}
|
||||
|
||||
if (!errorMsg && data.ErrorMessage)
|
||||
{
|
||||
errorMsg = data.ErrorMessage;
|
||||
}
|
||||
|
||||
this.background.error(errorMsg || i18n('SETTINGS_THEMES/ERROR_UNKNOWN'));
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {ThemesUserSettings, ThemesUserSettings as default};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue