mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 05:29:20 +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
|
|
@ -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