mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 13:39:22 +03:00
Code refactoring
Flow first look
This commit is contained in:
parent
2f841524cb
commit
e6e0b02849
71 changed files with 2092 additions and 1836 deletions
|
|
@ -4,13 +4,15 @@ import ko from 'ko';
|
|||
|
||||
import {
|
||||
settingsSaveHelperSimpleFunction,
|
||||
defautOptionsAfterRender, createCommand,
|
||||
defautOptionsAfterRender,
|
||||
inArray, trim, boolToAjax
|
||||
} from 'Common/Utils';
|
||||
|
||||
import {SaveSettingsStep, StorageResultType, Magics} from 'Common/Enums';
|
||||
import {i18n} from 'Common/Translator';
|
||||
import {settingsGet} from 'Storage/Settings';
|
||||
import Remote from 'Remote/Admin/Ajax';
|
||||
import {command} from 'Knoin/Knoin';
|
||||
|
||||
class ContactsAdminSettings
|
||||
{
|
||||
|
|
@ -21,7 +23,6 @@ class ContactsAdminSettings
|
|||
this.contactsSync = ko.observable(!!settingsGet('ContactsSync'));
|
||||
|
||||
const
|
||||
Remote = require('Remote/Admin/Ajax'),
|
||||
supportedTypes = [],
|
||||
types = ['sqlite', 'mysql', 'pgsql'],
|
||||
getTypeName = (name) => {
|
||||
|
|
@ -111,27 +112,26 @@ class ContactsAdminSettings
|
|||
this.testContactsError = ko.observable(false);
|
||||
this.testContactsErrorMessage = ko.observable('');
|
||||
|
||||
this.testContactsCommand = createCommand(() => {
|
||||
|
||||
this.testContactsSuccess(false);
|
||||
this.testContactsError(false);
|
||||
this.testContactsErrorMessage('');
|
||||
this.testing(true);
|
||||
|
||||
Remote.testContacts(this.onTestContactsResponse, {
|
||||
'ContactsPdoType': this.contactsType(),
|
||||
'ContactsPdoDsn': this.pdoDsn(),
|
||||
'ContactsPdoUser': this.pdoUser(),
|
||||
'ContactsPdoPassword': this.pdoPassword()
|
||||
});
|
||||
|
||||
}, () => '' !== this.pdoDsn() && '' !== this.pdoUser());
|
||||
|
||||
this.contactsType(settingsGet('ContactsPdoType'));
|
||||
|
||||
this.onTestContactsResponse = _.bind(this.onTestContactsResponse, this);
|
||||
}
|
||||
|
||||
@command((self) => '' !== self.pdoDsn() && '' !== self.pdoUser())
|
||||
testContactsCommand() {
|
||||
this.testContactsSuccess(false);
|
||||
this.testContactsError(false);
|
||||
this.testContactsErrorMessage('');
|
||||
this.testing(true);
|
||||
|
||||
Remote.testContacts(this.onTestContactsResponse, {
|
||||
'ContactsPdoType': this.contactsType(),
|
||||
'ContactsPdoDsn': this.pdoDsn(),
|
||||
'ContactsPdoUser': this.pdoUser(),
|
||||
'ContactsPdoPassword': this.pdoPassword()
|
||||
});
|
||||
}
|
||||
|
||||
onTestContactsResponse(result, data) {
|
||||
this.testContactsSuccess(false);
|
||||
this.testContactsError(false);
|
||||
|
|
@ -166,7 +166,6 @@ class ContactsAdminSettings
|
|||
onBuild() {
|
||||
_.delay(() => {
|
||||
const
|
||||
Remote = require('Remote/Admin/Ajax'),
|
||||
f1 = settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this),
|
||||
f3 = settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this),
|
||||
f4 = settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
import {createCommand, trim, boolToAjax} from 'Common/Utils';
|
||||
import {trim, boolToAjax} from 'Common/Utils';
|
||||
import {phpInfo} from 'Common/Links';
|
||||
import {StorageResultType, Magics} from 'Common/Enums';
|
||||
|
||||
|
|
@ -13,6 +13,8 @@ import CapaAdminStore from 'Stores/Admin/Capa';
|
|||
|
||||
import Remote from 'Remote/Admin/Ajax';
|
||||
|
||||
import {command} from 'Knoin/Knoin';
|
||||
|
||||
class SecurityAdminSettings
|
||||
{
|
||||
constructor() {
|
||||
|
|
@ -77,35 +79,36 @@ class SecurityAdminSettings
|
|||
this.adminPasswordNewError(false);
|
||||
});
|
||||
|
||||
this.saveNewAdminPasswordCommand = createCommand(() => {
|
||||
|
||||
if ('' === trim(this.adminLogin()))
|
||||
{
|
||||
this.adminLoginError(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.adminPasswordNew() !== this.adminPasswordNew2())
|
||||
{
|
||||
this.adminPasswordNewError(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.adminPasswordUpdateError(false);
|
||||
this.adminPasswordUpdateSuccess(false);
|
||||
|
||||
Remote.saveNewAdminPassword(this.onNewAdminPasswordResponse, {
|
||||
'Login': this.adminLogin(),
|
||||
'Password': this.adminPassword(),
|
||||
'NewPassword': this.adminPasswordNew()
|
||||
});
|
||||
|
||||
return true;
|
||||
}, () => '' !== trim(this.adminLogin()) && '' !== this.adminPassword());
|
||||
|
||||
this.onNewAdminPasswordResponse = _.bind(this.onNewAdminPasswordResponse, this);
|
||||
}
|
||||
|
||||
@command((self) => '' !== trim(self.adminLogin()) && '' !== self.adminPassword())
|
||||
saveNewAdminPasswordCommand() {
|
||||
|
||||
if ('' === trim(this.adminLogin()))
|
||||
{
|
||||
this.adminLoginError(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.adminPasswordNew() !== this.adminPasswordNew2())
|
||||
{
|
||||
this.adminPasswordNewError(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.adminPasswordUpdateError(false);
|
||||
this.adminPasswordUpdateSuccess(false);
|
||||
|
||||
Remote.saveNewAdminPassword(this.onNewAdminPasswordResponse, {
|
||||
'Login': this.adminLogin(),
|
||||
'Password': this.adminPassword(),
|
||||
'NewPassword': this.adminPasswordNew()
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
showTwoFactorDropper() {
|
||||
this.twoFactorDropperUser('');
|
||||
this.isTwoFactorDropperShown(true);
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ import _ from '_';
|
|||
import ko from 'ko';
|
||||
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {createCommand} from 'Common/Utils';
|
||||
import {getNotificationFromResponse, i18n} from 'Common/Translator';
|
||||
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
import {command} from 'Knoin/Knoin';
|
||||
|
||||
class ChangePasswordUserSettings
|
||||
{
|
||||
|
|
@ -43,30 +43,30 @@ class ChangePasswordUserSettings
|
|||
this.passwordMismatch(false);
|
||||
});
|
||||
|
||||
this.saveNewPasswordCommand = createCommand(() => {
|
||||
if (this.newPassword() !== this.newPassword2())
|
||||
{
|
||||
this.passwordMismatch(true);
|
||||
this.errorDescription(i18n('SETTINGS_CHANGE_PASSWORD/ERROR_PASSWORD_MISMATCH'));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.changeProcess(true);
|
||||
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
this.currentPassword.error(false);
|
||||
this.passwordMismatch(false);
|
||||
this.errorDescription('');
|
||||
|
||||
Remote.changePassword(this.onChangePasswordResponse, this.currentPassword(), this.newPassword());
|
||||
}
|
||||
|
||||
}, () => !this.changeProcess() && '' !== this.currentPassword() && '' !== this.newPassword() && '' !== this.newPassword2());
|
||||
|
||||
this.onChangePasswordResponse = _.bind(this.onChangePasswordResponse, this);
|
||||
}
|
||||
|
||||
@command((self) => !self.changeProcess() && '' !== self.currentPassword() && '' !== self.newPassword() && '' !== self.newPassword2())
|
||||
saveNewPasswordCommand() {
|
||||
if (this.newPassword() !== this.newPassword2())
|
||||
{
|
||||
this.passwordMismatch(true);
|
||||
this.errorDescription(i18n('SETTINGS_CHANGE_PASSWORD/ERROR_PASSWORD_MISMATCH'));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.changeProcess(true);
|
||||
|
||||
this.passwordUpdateError(false);
|
||||
this.passwordUpdateSuccess(false);
|
||||
this.currentPassword.error(false);
|
||||
this.passwordMismatch(false);
|
||||
this.errorDescription('');
|
||||
|
||||
Remote.changePassword(this.onChangePasswordResponse, this.currentPassword(), this.newPassword());
|
||||
}
|
||||
}
|
||||
|
||||
onHide() {
|
||||
this.changeProcess(false);
|
||||
this.currentPassword('');
|
||||
|
|
|
|||
|
|
@ -2,20 +2,17 @@
|
|||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
import {windowResizeCallback, isArray, trim, delegateRunOnDestroy} from 'Common/Utils';
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {getNotification} from 'Common/Translator';
|
||||
|
||||
import {
|
||||
windowResizeCallback, createCommand, isArray, trim, delegateRunOnDestroy
|
||||
} from 'Common/Utils';
|
||||
|
||||
import {showScreenPopup} from 'Knoin/Knoin';
|
||||
|
||||
import FilterStore from 'Stores/User/Filter';
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
import {FilterModel} from 'Model/Filter';
|
||||
|
||||
import {showScreenPopup, command} from 'Knoin/Knoin';
|
||||
|
||||
class FiltersUserSettings
|
||||
{
|
||||
constructor() {
|
||||
|
|
@ -46,41 +43,6 @@ class FiltersUserSettings
|
|||
|
||||
this.filterForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
|
||||
this.saveChanges = createCommand(() => {
|
||||
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());
|
||||
}
|
||||
|
||||
return true;
|
||||
}, () => this.haveChanges());
|
||||
|
||||
this.filters.subscribe(() => {
|
||||
this.haveChanges(true);
|
||||
});
|
||||
|
|
@ -100,6 +62,42 @@ class FiltersUserSettings
|
|||
});
|
||||
}
|
||||
|
||||
@command((self) => self.haveChanges())
|
||||
saveChangesCommand() {
|
||||
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());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
scrollableOptions(wrapper) {
|
||||
return {
|
||||
handle: '.drag-handle',
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
import {createCommand} from 'Common/Utils';
|
||||
|
||||
import SocialStore from 'Stores/Social';
|
||||
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
import {command} from 'Knoin/Knoin';
|
||||
|
||||
class SocialUserSettings
|
||||
{
|
||||
constructor() {
|
||||
|
|
@ -29,39 +29,45 @@ class SocialUserSettings
|
|||
this.twitterActions = SocialStore.twitter.loading;
|
||||
this.twitterLoggined = SocialStore.twitter.loggined;
|
||||
this.twitterUserName = SocialStore.twitter.userName;
|
||||
}
|
||||
|
||||
this.connectGoogle = createCommand(() => {
|
||||
if (!this.googleLoggined())
|
||||
{
|
||||
getApp().googleConnect();
|
||||
}
|
||||
}, () => !this.googleLoggined() && !this.googleActions());
|
||||
@command((self) => !self.googleLoggined() && !self.googleActions())
|
||||
connectGoogleCommand() {
|
||||
if (!this.googleLoggined())
|
||||
{
|
||||
getApp().googleConnect();
|
||||
}
|
||||
}
|
||||
|
||||
this.disconnectGoogle = createCommand(() => {
|
||||
getApp().googleDisconnect();
|
||||
});
|
||||
@command()
|
||||
disconnectGoogleCommand() {
|
||||
getApp().googleDisconnect();
|
||||
}
|
||||
|
||||
this.connectFacebook = createCommand(() => {
|
||||
if (!this.facebookLoggined())
|
||||
{
|
||||
getApp().facebookConnect();
|
||||
}
|
||||
}, () => !this.facebookLoggined() && !this.facebookActions());
|
||||
@command((self) => !self.facebookLoggined() && !self.facebookActions())
|
||||
connectFacebookCommand() {
|
||||
if (!this.facebookLoggined())
|
||||
{
|
||||
getApp().facebookConnect();
|
||||
}
|
||||
}
|
||||
|
||||
this.disconnectFacebook = createCommand(() => {
|
||||
getApp().facebookDisconnect();
|
||||
});
|
||||
@command()
|
||||
disconnectFacebookCommand() {
|
||||
getApp().facebookDisconnect();
|
||||
}
|
||||
|
||||
this.connectTwitter = createCommand(() => {
|
||||
if (!this.twitterLoggined())
|
||||
{
|
||||
getApp().twitterConnect();
|
||||
}
|
||||
}, () => !this.twitterLoggined() && !this.twitterActions());
|
||||
@command((self) => !self.twitterLoggined() && !self.twitterActions())
|
||||
connectTwitterCommand() {
|
||||
if (!this.twitterLoggined())
|
||||
{
|
||||
getApp().twitterConnect();
|
||||
}
|
||||
}
|
||||
|
||||
this.disconnectTwitter = createCommand(() => {
|
||||
getApp().twitterDisconnect();
|
||||
});
|
||||
@command()
|
||||
disconnectTwitterCommand() {
|
||||
getApp().twitterDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue