Code refactoring

This commit is contained in:
RainLoop Team 2014-10-18 17:43:44 +04:00
parent 345e7c58af
commit 8cf8b94d39
103 changed files with 664 additions and 659 deletions

View file

@ -0,0 +1,99 @@
(function () {
'use strict';
var
window = require('window'),
_ = require('_'),
ko = require('ko'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Links = require('Common/Links'),
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
;
/**
* @constructor
*/
function AccountsUserSetting()
{
this.accounts = Data.accounts;
this.processText = ko.computed(function () {
return Data.accountsLoading() ? Utils.i18n('SETTINGS_ACCOUNTS/LOADING_PROCESS') : '';
}, this);
this.visibility = ko.computed(function () {
return '' === this.processText() ? 'hidden' : 'visible';
}, this);
this.accountForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this,
function (oPrev) {
if (oPrev)
{
oPrev.deleteAccess(false);
}
}, function (oNext) {
if (oNext)
{
oNext.deleteAccess(true);
}
}
]});
}
AccountsUserSetting.prototype.addNewAccount = function ()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/AddAccount'));
};
/**
* @param {AccountModel} oAccountToRemove
*/
AccountsUserSetting.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').accountsAndIdentities();
}
}, oAccountToRemove.email);
}
}
};
module.exports = AccountsUserSetting;
}());

View file

@ -0,0 +1,121 @@
(function () {
'use strict';
var
_ = require('_'),
ko = require('ko'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Remote = require('Storage/User/Remote')
;
/**
* @constructor
*/
function ChangePasswordUserSetting()
{
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.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(Utils.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());
}
}, function () {
return !this.changeProcess() && '' !== this.currentPassword() &&
'' !== this.newPassword() && '' !== this.newPassword2();
});
this.onChangePasswordResponse = _.bind(this.onChangePasswordResponse, this);
}
ChangePasswordUserSetting.prototype.onHide = function ()
{
this.changeProcess(false);
this.currentPassword('');
this.newPassword('');
this.newPassword2('');
this.errorDescription('');
this.passwordMismatch(false);
this.currentPassword.error(false);
};
ChangePasswordUserSetting.prototype.onChangePasswordResponse = function (sResult, oData)
{
this.changeProcess(false);
this.passwordMismatch(false);
this.errorDescription('');
this.currentPassword.error(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
this.currentPassword('');
this.newPassword('');
this.newPassword2('');
this.passwordUpdateSuccess(true);
this.currentPassword.error(false);
}
else
{
if (oData && Enums.Notification.CurrentPasswordIncorrect === oData.ErrorCode)
{
this.currentPassword.error(true);
}
this.passwordUpdateError(true);
this.errorDescription(oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) :
Utils.getNotification(Enums.Notification.CouldNotSaveNewPassword));
}
};
module.exports = ChangePasswordUserSetting;
}());

View file

@ -0,0 +1,56 @@
(function () {
'use strict';
var
ko = require('ko'),
Remote = require('Storage/User/Remote'),
Data = require('Storage/User/Data')
;
/**
* @constructor
*/
function ContactsUserSetting()
{
this.contactsAutosave = Data.contactsAutosave;
this.allowContactsSync = Data.allowContactsSync;
this.enableContactsSync = Data.enableContactsSync;
this.contactsSyncUrl = Data.contactsSyncUrl;
this.contactsSyncUser = Data.contactsSyncUser;
this.contactsSyncPass = Data.contactsSyncPass;
this.saveTrigger = ko.computed(function () {
return [
this.enableContactsSync() ? '1' : '0',
this.contactsSyncUrl(),
this.contactsSyncUser(),
this.contactsSyncPass()
].join('|');
}, this).extend({'throttle': 500});
this.saveTrigger.subscribe(function () {
Remote.saveContactsSyncData(null,
this.enableContactsSync(),
this.contactsSyncUrl(),
this.contactsSyncUser(),
this.contactsSyncPass()
);
}, this);
}
ContactsUserSetting.prototype.onBuild = function ()
{
Data.contactsAutosave.subscribe(function (bValue) {
Remote.saveSettings(null, {
'ContactsAutosave': bValue ? '1' : '0'
});
});
};
module.exports = ContactsUserSetting;
}());

View file

@ -0,0 +1,43 @@
(function () {
'use strict';
var
ko = require('ko'),
Utils = require('Common/Utils')
;
/**
* @constructor
*/
function FiltersUserSetting()
{
this.filters = ko.observableArray([]);
this.filters.loading = ko.observable(false);
this.filters.subscribe(function () {
Utils.windowResize();
});
}
FiltersUserSetting.prototype.deleteFilter = function (oFilter)
{
this.filters.remove(oFilter);
Utils.delegateRunOnDestroy(oFilter);
};
FiltersUserSetting.prototype.addFilter = function ()
{
var
FilterModel = require('Model/Filter')
;
require('Knoin/Knoin').showScreenPopup(
require('View/Popup/Filter'), [new FilterModel()]);
};
module.exports = FiltersUserSetting;
}());

View file

@ -0,0 +1,214 @@
(function () {
'use strict';
var
ko = require('ko'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Settings = require('Storage/Settings'),
Data = require('Storage/User/Data'),
Cache = require('Storage/User/Cache'),
Remote = require('Storage/User/Remote'),
Local = require('Storage/Local')
;
/**
* @constructor
*/
function FoldersUserSetting()
{
this.foldersListError = Data.foldersListError;
this.folderList = Data.folderList;
this.processText = ko.computed(function () {
var
bLoading = Data.foldersLoading(),
bCreating = Data.foldersCreating(),
bDeleting = Data.foldersDeleting(),
bRenaming = Data.foldersRenaming()
;
if (bCreating)
{
return Utils.i18n('SETTINGS_FOLDERS/CREATING_PROCESS');
}
else if (bDeleting)
{
return Utils.i18n('SETTINGS_FOLDERS/DELETING_PROCESS');
}
else if (bRenaming)
{
return Utils.i18n('SETTINGS_FOLDERS/RENAMING_PROCESS');
}
else if (bLoading)
{
return Utils.i18n('SETTINGS_FOLDERS/LOADING_PROCESS');
}
return '';
}, this);
this.visibility = ko.computed(function () {
return '' === this.processText() ? 'hidden' : 'visible';
}, this);
this.folderForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this,
function (oPrev) {
if (oPrev)
{
oPrev.deleteAccess(false);
}
}, function (oNext) {
if (oNext)
{
oNext.deleteAccess(true);
}
}
]});
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.settingsGet('UseImapSubscribe');
}
FoldersUserSetting.prototype.folderEditOnEnter = function (oFolder)
{
var
sEditName = oFolder ? Utils.trim(oFolder.nameForEdit()) : ''
;
if ('' !== sEditName && oFolder.name() !== sEditName)
{
Local.set(Enums.ClientSideKeyName.FoldersLashHash, '');
Data.foldersRenaming(true);
Remote.folderRename(function (sResult, oData) {
Data.foldersRenaming(false);
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
Data.foldersListError(
oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) : Utils.i18n('NOTIFICATIONS/CANT_RENAME_FOLDER'));
}
require('App/User').folders();
}, oFolder.fullNameRaw, sEditName);
Cache.removeFolderFromCacheList(oFolder.fullNameRaw);
oFolder.name(sEditName);
}
oFolder.edited(false);
};
FoldersUserSetting.prototype.folderEditOnEsc = function (oFolder)
{
if (oFolder)
{
oFolder.edited(false);
}
};
FoldersUserSetting.prototype.onShow = function ()
{
Data.foldersListError('');
};
FoldersUserSetting.prototype.createFolder = function ()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/FolderCreate'));
};
FoldersUserSetting.prototype.systemFolder = function ()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/FolderSystem'));
};
FoldersUserSetting.prototype.deleteFolder = function (oFolderToRemove)
{
if (oFolderToRemove && oFolderToRemove.canBeDeleted() && oFolderToRemove.deleteAccess() &&
0 === oFolderToRemove.privateMessageCountAll())
{
this.folderForDeletion(null);
var
fRemoveFolder = function (oFolder) {
if (oFolderToRemove === oFolder)
{
return true;
}
oFolder.subFolders.remove(fRemoveFolder);
return false;
}
;
if (oFolderToRemove)
{
Local.set(Enums.ClientSideKeyName.FoldersLashHash, '');
Data.folderList.remove(fRemoveFolder);
Data.foldersDeleting(true);
Remote.folderDelete(function (sResult, oData) {
Data.foldersDeleting(false);
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
Data.foldersListError(
oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) : Utils.i18n('NOTIFICATIONS/CANT_DELETE_FOLDER'));
}
require('App/User').folders();
}, oFolderToRemove.fullNameRaw);
Cache.removeFolderFromCacheList(oFolderToRemove.fullNameRaw);
}
}
else if (0 < oFolderToRemove.privateMessageCountAll())
{
Data.foldersListError(Utils.getNotification(Enums.Notification.CantDeleteNonEmptyFolder));
}
};
FoldersUserSetting.prototype.subscribeFolder = function (oFolder)
{
Local.set(Enums.ClientSideKeyName.FoldersLashHash, '');
Remote.folderSetSubscribe(Utils.emptyFunction, oFolder.fullNameRaw, true);
oFolder.subScribed(true);
};
FoldersUserSetting.prototype.unSubscribeFolder = function (oFolder)
{
Local.set(Enums.ClientSideKeyName.FoldersLashHash, '');
Remote.folderSetSubscribe(Utils.emptyFunction, oFolder.fullNameRaw, false);
oFolder.subScribed(false);
};
module.exports = FoldersUserSetting;
}());

View file

@ -0,0 +1,173 @@
(function () {
'use strict';
var
_ = require('_'),
ko = require('ko'),
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
;
/**
* @constructor
*/
function GeneralUserSetting()
{
this.mainLanguage = Data.mainLanguage;
this.mainMessagesPerPage = Data.mainMessagesPerPage;
this.mainMessagesPerPageArray = Consts.Defaults.MessagesPerPageArray;
this.editorDefaultType = Data.editorDefaultType;
this.showImages = Data.showImages;
this.interfaceAnimation = Data.interfaceAnimation;
this.useDesktopNotifications = Data.useDesktopNotifications;
this.threading = Data.threading;
this.useThreads = Data.useThreads;
this.replySameFolder = Data.replySameFolder;
this.layout = Data.layout;
this.usePreviewPane = Data.usePreviewPane;
this.useCheckboxesInList = Data.useCheckboxesInList;
this.allowLanguagesOnSettings = Data.allowLanguagesOnSettings;
this.isDesktopNotificationsSupported = ko.computed(function () {
return Enums.DesktopNotifications.NotSupported !== Data.desktopNotificationsPermisions();
});
this.isDesktopNotificationsDenied = ko.computed(function () {
return Enums.DesktopNotifications.NotSupported === Data.desktopNotificationsPermisions() ||
Enums.DesktopNotifications.Denied === Data.desktopNotificationsPermisions();
});
this.mainLanguageFullName = ko.computed(function () {
return Utils.convertLangName(this.mainLanguage());
}, this);
this.languageTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': 100});
this.mppTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.isAnimationSupported = Globals.bAnimationSupported;
}
GeneralUserSetting.prototype.toggleLayout = function ()
{
this.layout(Enums.Layout.NoPreview === this.layout() ? Enums.Layout.SidePreview : Enums.Layout.NoPreview);
};
GeneralUserSetting.prototype.onBuild = function ()
{
var self = this;
_.delay(function () {
var
f1 = Utils.settingsSaveHelperSimpleFunction(self.mppTrigger, self),
fReloadLanguageHelper = function (iSaveSettingsStep) {
return function() {
self.languageTrigger(iSaveSettingsStep);
_.delay(function () {
self.languageTrigger(Enums.SaveSettingsStep.Idle);
}, 1000);
};
}
;
Data.language.subscribe(function (sValue) {
self.languageTrigger(Enums.SaveSettingsStep.Animate);
Utils.reloadLanguage(sValue,
fReloadLanguageHelper(Enums.SaveSettingsStep.TrueResult),
fReloadLanguageHelper(Enums.SaveSettingsStep.FalseResult));
Remote.saveSettings(null, {
'Language': sValue
});
});
Data.editorDefaultType.subscribe(function (sValue) {
Remote.saveSettings(null, {
'EditorDefaultType': sValue
});
});
Data.messagesPerPage.subscribe(function (iValue) {
Remote.saveSettings(f1, {
'MPP': iValue
});
});
Data.showImages.subscribe(function (bValue) {
Remote.saveSettings(null, {
'ShowImages': bValue ? '1' : '0'
});
});
Data.interfaceAnimation.subscribe(function (sValue) {
Remote.saveSettings(null, {
'InterfaceAnimation': sValue
});
});
Data.useDesktopNotifications.subscribe(function (bValue) {
Utils.timeOutAction('SaveDesktopNotifications', function () {
Remote.saveSettings(null, {
'DesktopNotifications': bValue ? '1' : '0'
});
}, 3000);
});
Data.replySameFolder.subscribe(function (bValue) {
Utils.timeOutAction('SaveReplySameFolder', function () {
Remote.saveSettings(null, {
'ReplySameFolder': bValue ? '1' : '0'
});
}, 3000);
});
Data.useThreads.subscribe(function (bValue) {
Data.messageList([]);
Remote.saveSettings(null, {
'UseThreads': bValue ? '1' : '0'
});
});
Data.layout.subscribe(function (nValue) {
Data.messageList([]);
Remote.saveSettings(null, {
'Layout': nValue
});
});
Data.useCheckboxesInList.subscribe(function (bValue) {
Remote.saveSettings(null, {
'UseCheckboxesInList': bValue ? '1' : '0'
});
});
}, 50);
};
GeneralUserSetting.prototype.onShow = function ()
{
Data.desktopNotifications.valueHasMutated();
};
GeneralUserSetting.prototype.selectLanguage = function ()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Languages'));
};
module.exports = GeneralUserSetting;
}());

View file

@ -0,0 +1,233 @@
(function () {
'use strict';
var
_ = require('_'),
ko = require('ko'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
HtmlEditor = require('Common/HtmlEditor'),
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
;
/**
* @constructor
*/
function IdentitiesUserSetting()
{
this.editor = null;
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
this.accountEmail = Data.accountEmail;
this.displayName = Data.displayName;
this.signature = Data.signature;
this.signatureToAll = Data.signatureToAll;
this.replyTo = Data.replyTo;
this.signatureDom = ko.observable(null);
this.defaultIdentityIDTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.displayNameTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.replyTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.signatureTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.identities = Data.identities;
this.defaultIdentityID = Data.defaultIdentityID;
this.identitiesOptions = ko.computed(function () {
var
aList = this.identities(),
aResult = []
;
if (0 < aList.length)
{
aResult.push({
'id': this.accountEmail.peek(),
'name': this.formattedAccountIdentity(),
'seporator': false
});
aResult.push({
'id': '---',
'name': '---',
'seporator': true,
'disabled': true
});
_.each(aList, function (oItem) {
aResult.push({
'id': oItem.id,
'name': oItem.formattedNameForEmail(),
'seporator': false
});
});
}
return aResult;
}, this);
this.processText = ko.computed(function () {
return Data.identitiesLoading() ? Utils.i18n('SETTINGS_IDENTITIES/LOADING_PROCESS') : '';
}, this);
this.visibility = ko.computed(function () {
return '' === this.processText() ? 'hidden' : 'visible';
}, this);
this.identityForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this,
function (oPrev) {
if (oPrev)
{
oPrev.deleteAccess(false);
}
}, function (oNext) {
if (oNext)
{
oNext.deleteAccess(true);
}
}
]});
}
/**
*
* @return {string}
*/
IdentitiesUserSetting.prototype.formattedAccountIdentity = function ()
{
var
sDisplayName = this.displayName.peek(),
sEmail = this.accountEmail.peek()
;
return '' === sDisplayName ? sEmail : '"' + Utils.quoteName(sDisplayName) + '" <' + sEmail + '>';
};
IdentitiesUserSetting.prototype.addNewIdentity = function ()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Identity'));
};
IdentitiesUserSetting.prototype.editIdentity = function (oIdentity)
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Identity'), [oIdentity]);
};
/**
* @param {IdentityModel} oIdentityToRemove
*/
IdentitiesUserSetting.prototype.deleteIdentity = function (oIdentityToRemove)
{
if (oIdentityToRemove && oIdentityToRemove.deleteAccess())
{
this.identityForDeletion(null);
var
fRemoveFolder = function (oIdentity) {
return oIdentityToRemove === oIdentity;
}
;
if (oIdentityToRemove)
{
this.identities.remove(fRemoveFolder);
Remote.identityDelete(function () {
require('App/User').accountsAndIdentities();
}, oIdentityToRemove.id);
}
}
};
IdentitiesUserSetting.prototype.onFocus = function ()
{
if (!this.editor && this.signatureDom())
{
var
self = this,
sSignature = Data.signature()
;
this.editor = new HtmlEditor(self.signatureDom(), function () {
Data.signature(
(self.editor.isHtml() ? ':HTML:' : '') + self.editor.getData()
);
}, function () {
if (':HTML:' === sSignature.substr(0, 6))
{
self.editor.setHtml(sSignature.substr(6), false);
}
else
{
self.editor.setPlain(sSignature, false);
}
});
}
};
IdentitiesUserSetting.prototype.onBuild = function (oDom)
{
var self = this;
oDom
.on('click', '.identity-item .e-action', function () {
var oIdentityItem = ko.dataFor(this);
if (oIdentityItem)
{
self.editIdentity(oIdentityItem);
}
})
;
_.delay(function () {
var
f1 = Utils.settingsSaveHelperSimpleFunction(self.displayNameTrigger, self),
f2 = Utils.settingsSaveHelperSimpleFunction(self.replyTrigger, self),
f3 = Utils.settingsSaveHelperSimpleFunction(self.signatureTrigger, self),
f4 = Utils.settingsSaveHelperSimpleFunction(self.defaultIdentityIDTrigger, self)
;
Data.defaultIdentityID.subscribe(function (sValue) {
Remote.saveSettings(f4, {
'DefaultIdentityID': sValue
});
});
Data.displayName.subscribe(function (sValue) {
Remote.saveSettings(f1, {
'DisplayName': sValue
});
});
Data.replyTo.subscribe(function (sValue) {
Remote.saveSettings(f2, {
'ReplyTo': sValue
});
});
Data.signature.subscribe(function (sValue) {
Remote.saveSettings(f3, {
'Signature': sValue
});
});
Data.signatureToAll.subscribe(function (bValue) {
Remote.saveSettings(null, {
'SignatureToAll': bValue ? '1' : '0'
});
});
}, 50);
};
module.exports = IdentitiesUserSetting;
}());

View file

@ -0,0 +1,103 @@
(function () {
'use strict';
var
_ = require('_'),
ko = require('ko'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
HtmlEditor = require('Common/HtmlEditor'),
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
;
/**
* @constructor
*/
function IdentityUserSetting()
{
this.editor = null;
this.displayName = Data.displayName;
this.signature = Data.signature;
this.signatureToAll = Data.signatureToAll;
this.replyTo = Data.replyTo;
this.signatureDom = ko.observable(null);
this.displayNameTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.replyTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.signatureTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
}
IdentityUserSetting.prototype.onFocus = function ()
{
if (!this.editor && this.signatureDom())
{
var
self = this,
sSignature = Data.signature()
;
this.editor = new HtmlEditor(self.signatureDom(), function () {
Data.signature(
(self.editor.isHtml() ? ':HTML:' : '') + self.editor.getData()
);
}, function () {
if (':HTML:' === sSignature.substr(0, 6))
{
self.editor.setHtml(sSignature.substr(6), false);
}
else
{
self.editor.setPlain(sSignature, false);
}
});
}
};
IdentityUserSetting.prototype.onBuild = function ()
{
var self = this;
_.delay(function () {
var
f1 = Utils.settingsSaveHelperSimpleFunction(self.displayNameTrigger, self),
f2 = Utils.settingsSaveHelperSimpleFunction(self.replyTrigger, self),
f3 = Utils.settingsSaveHelperSimpleFunction(self.signatureTrigger, self)
;
Data.displayName.subscribe(function (sValue) {
Remote.saveSettings(f1, {
'DisplayName': sValue
});
});
Data.replyTo.subscribe(function (sValue) {
Remote.saveSettings(f2, {
'ReplyTo': sValue
});
});
Data.signature.subscribe(function (sValue) {
Remote.saveSettings(f3, {
'Signature': sValue
});
});
Data.signatureToAll.subscribe(function (bValue) {
Remote.saveSettings(null, {
'SignatureToAll': bValue ? '1' : '0'
});
});
}, 50);
};
module.exports = IdentityUserSetting;
}());

View file

@ -0,0 +1,92 @@
(function () {
'use strict';
var
_ = require('_'),
ko = require('ko'),
Utils = require('Common/Utils'),
kn = require('Knoin/Knoin'),
Data = require('Storage/User/Data')
;
/**
* @constructor
*/
function OpenPgpUserSetting()
{
this.openpgpkeys = Data.openpgpkeys;
this.openpgpkeysPublic = Data.openpgpkeysPublic;
this.openpgpkeysPrivate = Data.openpgpkeysPrivate;
this.openPgpKeyForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this,
function (oPrev) {
if (oPrev)
{
oPrev.deleteAccess(false);
}
}, function (oNext) {
if (oNext)
{
oNext.deleteAccess(true);
}
}
]});
}
OpenPgpUserSetting.prototype.addOpenPgpKey = function ()
{
kn.showScreenPopup(require('View/Popup/AddOpenPgpKey'));
};
OpenPgpUserSetting.prototype.generateOpenPgpKey = function ()
{
kn.showScreenPopup(require('View/Popup/NewOpenPgpKey'));
};
OpenPgpUserSetting.prototype.viewOpenPgpKey = function (oOpenPgpKey)
{
if (oOpenPgpKey)
{
kn.showScreenPopup(require('View/Popup/ViewOpenPgpKey'), [oOpenPgpKey]);
}
};
/**
* @param {OpenPgpKeyModel} oOpenPgpKeyToRemove
*/
OpenPgpUserSetting.prototype.deleteOpenPgpKey = function (oOpenPgpKeyToRemove)
{
if (oOpenPgpKeyToRemove && oOpenPgpKeyToRemove.deleteAccess())
{
this.openPgpKeyForDeletion(null);
if (oOpenPgpKeyToRemove && Data.openpgpKeyring)
{
var oFindedItem = _.find(this.openpgpkeys(), function (oOpenPgpKey) {
return oOpenPgpKeyToRemove === oOpenPgpKey;
});
if (oFindedItem)
{
this.openpgpkeys.remove(oFindedItem);
Utils.delegateRunOnDestroy(oFindedItem);
Data.openpgpKeyring[oFindedItem.isPrivate ? 'privateKeys' : 'publicKeys']
.removeForId(oFindedItem.guid);
Data.openpgpKeyring.store();
}
require('App/User').reloadOpenPgpKeys();
}
}
};
module.exports = OpenPgpUserSetting;
}());

View file

@ -0,0 +1,166 @@
(function () {
'use strict';
var
ko = require('ko'),
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Remote = require('Storage/User/Remote')
;
/**
* @constructor
*/
function SecurityUserSetting()
{
this.processing = ko.observable(false);
this.clearing = ko.observable(false);
this.secreting = ko.observable(false);
this.viewUser = ko.observable('');
this.viewEnable = ko.observable(false);
this.viewEnable.subs = true;
this.twoFactorStatus = ko.observable(false);
this.viewSecret = ko.observable('');
this.viewBackupCodes = ko.observable('');
this.viewUrl = ko.observable('');
this.bFirst = true;
this.viewTwoFactorStatus = ko.computed(function () {
Globals.langChangeTrigger();
return Utils.i18n(
this.twoFactorStatus() ?
'SETTINGS_SECURITY/TWO_FACTOR_SECRET_CONFIGURED_DESC' :
'SETTINGS_SECURITY/TWO_FACTOR_SECRET_NOT_CONFIGURED_DESC'
);
}, this);
this.onResult = _.bind(this.onResult, this);
this.onSecretResult = _.bind(this.onSecretResult, this);
}
SecurityUserSetting.prototype.showSecret = function ()
{
this.secreting(true);
Remote.showTwoFactorSecret(this.onSecretResult);
};
SecurityUserSetting.prototype.hideSecret = function ()
{
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrl('');
};
SecurityUserSetting.prototype.createTwoFactor = function ()
{
this.processing(true);
Remote.createTwoFactor(this.onResult);
};
SecurityUserSetting.prototype.enableTwoFactor = function ()
{
this.processing(true);
Remote.enableTwoFactor(this.onResult, this.viewEnable());
};
SecurityUserSetting.prototype.testTwoFactor = function ()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/TwoFactorTest'));
};
SecurityUserSetting.prototype.clearTwoFactor = function ()
{
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrl('');
this.clearing(true);
Remote.clearTwoFactor(this.onResult);
};
SecurityUserSetting.prototype.onShow = function ()
{
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrl('');
};
SecurityUserSetting.prototype.onResult = function (sResult, oData)
{
this.processing(false);
this.clearing(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
this.viewUser(Utils.pString(oData.Result.User));
this.viewEnable(!!oData.Result.Enable);
this.twoFactorStatus(!!oData.Result.IsSet);
this.viewSecret(Utils.pString(oData.Result.Secret));
this.viewBackupCodes(Utils.pString(oData.Result.BackupCodes).replace(/[\s]+/g, ' '));
this.viewUrl(Utils.pString(oData.Result.Url));
}
else
{
this.viewUser('');
this.viewEnable(false);
this.twoFactorStatus(false);
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrl('');
}
if (this.bFirst)
{
this.bFirst = false;
var self = this;
this.viewEnable.subscribe(function (bValue) {
if (this.viewEnable.subs)
{
Remote.enableTwoFactor(function (sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
self.viewEnable.subs = false;
self.viewEnable(false);
self.viewEnable.subs = true;
}
}, bValue);
}
}, this);
}
};
SecurityUserSetting.prototype.onSecretResult = function (sResult, oData)
{
this.secreting(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
this.viewSecret(Utils.pString(oData.Result.Secret));
this.viewUrl(Utils.pString(oData.Result.Url));
}
else
{
this.viewSecret('');
this.viewUrl('');
}
};
SecurityUserSetting.prototype.onBuild = function ()
{
this.processing(true);
Remote.getTwoFactor(this.onResult);
};
module.exports = SecurityUserSetting;
}());

View file

@ -0,0 +1,76 @@
(function () {
'use strict';
/**
* @constructor
*/
function SocialUserSetting()
{
var
Utils = require('Common/Utils'),
Data = require('Storage/User/Data')
;
this.googleEnable = Data.googleEnable;
this.googleActions = Data.googleActions;
this.googleLoggined = Data.googleLoggined;
this.googleUserName = Data.googleUserName;
this.facebookEnable = Data.facebookEnable;
this.facebookActions = Data.facebookActions;
this.facebookLoggined = Data.facebookLoggined;
this.facebookUserName = Data.facebookUserName;
this.twitterEnable = Data.twitterEnable;
this.twitterActions = Data.twitterActions;
this.twitterLoggined = Data.twitterLoggined;
this.twitterUserName = Data.twitterUserName;
this.connectGoogle = Utils.createCommand(this, function () {
if (!this.googleLoggined())
{
require('App/User').googleConnect();
}
}, function () {
return !this.googleLoggined() && !this.googleActions();
});
this.disconnectGoogle = Utils.createCommand(this, function () {
require('App/User').googleDisconnect();
});
this.connectFacebook = Utils.createCommand(this, function () {
if (!this.facebookLoggined())
{
require('App/User').facebookConnect();
}
}, function () {
return !this.facebookLoggined() && !this.facebookActions();
});
this.disconnectFacebook = Utils.createCommand(this, function () {
require('App/User').facebookDisconnect();
});
this.connectTwitter = Utils.createCommand(this, function () {
if (!this.twitterLoggined())
{
require('App/User').twitterConnect();
}
}, function () {
return !this.twitterLoggined() && !this.twitterActions();
});
this.disconnectTwitter = Utils.createCommand(this, function () {
require('App/User').twitterDisconnect();
});
}
module.exports = SocialUserSetting;
}());

132
dev/Settings/User/Themes.js Normal file
View file

@ -0,0 +1,132 @@
(function () {
'use strict';
var
window = require('window'),
_ = require('_'),
$ = require('$'),
ko = require('ko'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Links = require('Common/Links'),
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
;
/**
* @constructor
*/
function ThemesUserSetting()
{
var self = this;
this.mainTheme = Data.mainTheme;
this.themesObjects = ko.observableArray([]);
this.themeTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': 100});
this.iTimer = 0;
this.oThemeAjaxRequest = null;
Data.theme.subscribe(function (sValue) {
_.each(this.themesObjects(), function (oTheme) {
oTheme.selected(sValue === oTheme.name);
});
var
oThemeLink = $('#rlThemeLink'),
oThemeStyle = $('#rlThemeStyle'),
sUrl = oThemeLink.attr('href')
;
if (!sUrl)
{
sUrl = oThemeStyle.attr('data-href');
}
if (sUrl)
{
sUrl = sUrl.toString().replace(/\/-\/[^\/]+\/\-\//, '/-/' + sValue + '/-/');
sUrl = sUrl.toString().replace(/\/Css\/[^\/]+\/User\//, '/Css/0/User/');
if ('Json/' !== sUrl.substring(sUrl.length - 5, sUrl.length))
{
sUrl += 'Json/';
}
window.clearTimeout(self.iTimer);
self.themeTrigger(Enums.SaveSettingsStep.Animate);
if (this.oThemeAjaxRequest && this.oThemeAjaxRequest.abort)
{
this.oThemeAjaxRequest.abort();
}
this.oThemeAjaxRequest = $.ajax({
'url': sUrl,
'dataType': 'json'
}).done(function(aData) {
if (aData && Utils.isArray(aData) && 2 === aData.length)
{
if (oThemeLink && oThemeLink[0] && (!oThemeStyle || !oThemeStyle[0]))
{
oThemeStyle = $('<style id="rlThemeStyle"></style>');
oThemeLink.after(oThemeStyle);
oThemeLink.remove();
}
if (oThemeStyle && oThemeStyle[0])
{
oThemeStyle.attr('data-href', sUrl).attr('data-theme', aData[0]);
if (oThemeStyle && oThemeStyle[0] && oThemeStyle[0].styleSheet && !Utils.isUnd(oThemeStyle[0].styleSheet.cssText))
{
oThemeStyle[0].styleSheet.cssText = aData[1];
}
else
{
oThemeStyle.text(aData[1]);
}
}
self.themeTrigger(Enums.SaveSettingsStep.TrueResult);
}
}).always(function() {
self.iTimer = window.setTimeout(function () {
self.themeTrigger(Enums.SaveSettingsStep.Idle);
}, 1000);
self.oThemeAjaxRequest = null;
});
}
Remote.saveSettings(null, {
'Theme': sValue
});
}, this);
}
ThemesUserSetting.prototype.onBuild = function ()
{
var sCurrentTheme = Data.theme();
this.themesObjects(_.map(Data.themes(), function (sTheme) {
return {
'name': sTheme,
'nameDisplay': Utils.convertThemeName(sTheme),
'selected': ko.observable(sTheme === sCurrentTheme),
'themePreviewSrc': Links.themePreviewLink(sTheme)
};
}));
};
module.exports = ThemesUserSetting;
}());