From cec53b111f481d0ffd8b6d0e7519a0f8fb9834d0 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Sat, 16 Jul 2016 00:29:42 +0300 Subject: [PATCH] Code refactoring (5) (es5 -> es2015) --- .eslintrc.js | 22 +- dev/App/Admin.jsx | 3 +- dev/App/User.jsx | 3 +- dev/Common/Audio.jsx | 3 +- dev/Common/Base64.jsx | 2 +- dev/Common/Booter.jsx | 2 + .../ClientStorageDriver/LocalStorage.jsx | 3 +- dev/Common/Globals.jsx | 91 +++-- dev/Common/Translator.jsx | 12 +- dev/Common/Utils.jsx | 16 +- dev/External/ko.js | 5 + dev/Helper/Message.jsx | 16 +- dev/Model/Attachment.jsx | 3 +- dev/Model/Contact.jsx | 3 +- dev/Model/Filter.jsx | 3 +- dev/Model/FilterCondition.jsx | 3 +- dev/Model/Folder.jsx | 3 +- dev/Model/Message.jsx | 3 +- dev/Promises/AbstractAjax.js | 5 +- dev/Remote/AbstractAjax.js | 4 +- dev/Remote/Admin/Ajax.js | 69 ++-- dev/Remote/User/Ajax.js | 15 + dev/Screen/Admin/Login.jsx | 3 +- dev/Screen/Admin/Settings.jsx | 9 +- dev/Screen/User/About.jsx | 3 +- dev/Screen/User/Login.jsx | 3 +- dev/Screen/User/MailBox.jsx | 3 +- dev/Screen/User/Settings.jsx | 3 +- dev/Settings/Admin/About.jsx | 144 ++++--- dev/Settings/Admin/Branding.jsx | 31 +- dev/Settings/Admin/Contacts.jsx | 370 +++++++++-------- dev/Settings/Admin/Domains.jsx | 124 +++--- dev/Settings/Admin/General.jsx | 292 +++++++------- dev/Settings/Admin/Login.jsx | 99 ++--- dev/Settings/Admin/Packages.jsx | 150 +++---- dev/Settings/Admin/Plugins.jsx | 170 ++++---- dev/Settings/Admin/Security.jsx | 312 +++++++-------- dev/Settings/Admin/Social.jsx | 249 +++++------- dev/Settings/User/Accounts.jsx | 267 ++++++------- dev/Settings/User/ChangePassword.jsx | 167 ++++---- dev/Settings/User/Contacts.jsx | 71 ++-- dev/Settings/User/Filters.jsx | 375 ++++++++---------- dev/Settings/User/Folders.jsx | 291 +++++++------- dev/Settings/User/General.jsx | 368 ++++++++--------- dev/Settings/User/OpenPgp.jsx | 113 +++--- dev/Settings/User/Security.jsx | 99 ++--- dev/Settings/User/Social.jsx | 109 +++-- dev/Settings/User/Templates.jsx | 137 +++---- dev/Settings/User/Themes.jsx | 292 +++++++------- dev/Stores/AbstractApp.jsx | 3 +- dev/Stores/Admin/App.jsx | 3 +- dev/Stores/User/App.jsx | 3 +- dev/Stores/User/Identity.jsx | 3 +- dev/Stores/User/Pgp.js | 27 +- dev/Styles/_social.css | 7 + dev/View/Admin/Settings/Menu.js | 2 + dev/View/Popup/Compose.js | 6 +- dev/View/Popup/Contacts.js | 2 + dev/View/Popup/NewOpenPgpKey.js | 18 +- dev/View/Popup/Plugin.js | 5 +- dev/View/Popup/Template.js | 3 +- dev/View/User/Login.js | 23 +- dev/View/User/MailBox/FolderList.js | 6 +- dev/View/User/MailBox/MessageView.js | 16 +- dev/View/User/Settings/Menu.js | 1 + dev/bootstrap.jsx | 4 +- .../Views/Admin/AdminSettingsLogin.html | 2 +- .../Views/User/PopupsNewOpenPgpKey.html | 5 + 68 files changed, 2210 insertions(+), 2472 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 35d74d3f2..b83cb00d2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,4 @@ + module.exports = { 'extends': 'eslint:recommended', 'ecmaFeatures': { @@ -14,18 +15,7 @@ module.exports = { 'browser': true }, 'globals': { - 'RL_COMMUNITY': true, - 'ko': true, - 'ssm': true, - 'moment': true, - 'ifvisible': true, - 'crossroads': true, - 'hasher': true, - 'key': true, - 'Jua': true, - '_': true, - '$': true, - 'Dropbox': true + 'RL_COMMUNITY': true }, // http://eslint.org/docs/rules/ 'rules': { @@ -166,7 +156,7 @@ module.exports = { 'array-bracket-spacing': 2, 'block-spacing': [2, 'never'], // 'brace-style': [2, 'allman'], -// 'camelcase': 2, + 'camelcase': 2, 'comma-dangle': [2, 'never'], 'comma-spacing': 2, 'comma-style': 2, @@ -234,9 +224,9 @@ module.exports = { // 'one-var': [2, { // 'var': 'always', // 'let': 'always', -// 'const': 'never' +// 'const': 'always' // }], -// 'one-var-declaration-per-line': [2, 'always'], + 'one-var-declaration-per-line': [2, 'always'], 'operator-assignment': 2, 'operator-linebreak': [2, 'after'], // 'padded-blocks': [2, 'never'], @@ -284,7 +274,7 @@ module.exports = { // 'prefer-template': 2, 'require-yield': 2, 'rest-spread-spacing': 2, - 'sort-imports': 0, + 'sort-imports': 0, // off 'template-curly-spacing': 2, 'yield-star-spacing': 2 } diff --git a/dev/App/Admin.jsx b/dev/App/Admin.jsx index f83e29972..f4d57f85f 100644 --- a/dev/App/Admin.jsx +++ b/dev/App/Admin.jsx @@ -27,8 +27,7 @@ import {AbstractApp} from 'App/Abstract'; class AdminApp extends AbstractApp { - constructor() - { + constructor() { super(Remote); } diff --git a/dev/App/User.jsx b/dev/App/User.jsx index ce2467ae5..9a4df785e 100644 --- a/dev/App/User.jsx +++ b/dev/App/User.jsx @@ -66,8 +66,7 @@ import {AbstractApp} from 'App/Abstract'; class AppUser extends AbstractApp { - constructor() - { + constructor() { super(Remote); this.moveCache = {}; diff --git a/dev/Common/Audio.jsx b/dev/Common/Audio.jsx index e9b73cee4..e989478ce 100644 --- a/dev/Common/Audio.jsx +++ b/dev/Common/Audio.jsx @@ -8,8 +8,7 @@ import {trim} from 'Common/Utils'; class Audio { - constructor() - { + constructor() { this.notificator = null; this.supportedMp3 = false; diff --git a/dev/Common/Base64.jsx b/dev/Common/Base64.jsx index 2b70f4c6f..8d739a6fe 100644 --- a/dev/Common/Base64.jsx +++ b/dev/Common/Base64.jsx @@ -158,8 +158,8 @@ const Base64 = { return string; } }; -/* eslint-enable */ export const decode = Base64.decode; export const encode = Base64.encode; export const urlsafe_encode = Base64.urlsafe_encode; +/* eslint-enable */ diff --git a/dev/Common/Booter.jsx b/dev/Common/Booter.jsx index 246a4fcb2..dc66f2356 100644 --- a/dev/Common/Booter.jsx +++ b/dev/Common/Booter.jsx @@ -10,10 +10,12 @@ import {getHash, setHash, clearHash} from 'Storage/RainLoop'; let RL_APP_DATA_STORAGE = null; +/* eslint-disable */ window.__rlah = () => getHash(); window.__rlah_set = () => setHash(); window.__rlah_clear = () => clearHash(); window.__rlah_data = () => RL_APP_DATA_STORAGE; +/* eslint-enable */ /** * @param {string} id diff --git a/dev/Common/ClientStorageDriver/LocalStorage.jsx b/dev/Common/ClientStorageDriver/LocalStorage.jsx index c7f6401bc..03c415a41 100644 --- a/dev/Common/ClientStorageDriver/LocalStorage.jsx +++ b/dev/Common/ClientStorageDriver/LocalStorage.jsx @@ -7,8 +7,7 @@ import {CLIENT_SIDE_STORAGE_INDEX_NAME} from 'Common/Consts'; class LocalStorageDriver { - constructor() - { + constructor() { this.s = window.localStorage || null; } diff --git a/dev/Common/Globals.jsx b/dev/Common/Globals.jsx index 10b4edeb3..e4840b4ab 100644 --- a/dev/Common/Globals.jsx +++ b/dev/Common/Globals.jsx @@ -82,15 +82,20 @@ export const bAnimationSupported = !bMobileDevice && $html.hasClass('csstransiti */ export const bXMLHttpRequestSupported = !!window.XMLHttpRequest; +/** + * @type {boolean} + */ +export const bIsHttps = window.document && window.document.location ? 'https:' === window.document.location.protocol : false; + /** * @type {Object} */ export const oHtmlEditorDefaultConfig = { - title: false, - stylesSet: false, - customConfig: '', - contentsCss: '', - toolbarGroups: [ + 'title': false, + 'stylesSet': false, + 'customConfig': '', + 'contentsCss': '', + 'toolbarGroups': [ {name: 'spec'}, {name: 'styles'}, {name: 'basicstyles', groups: ['basicstyles', 'cleanup', 'bidi']}, @@ -102,54 +107,54 @@ export const oHtmlEditorDefaultConfig = { {name: 'others'} ], - removePlugins: 'liststyle', - removeButtons: 'Format,Undo,Redo,Cut,Copy,Paste,Anchor,Strike,Subscript,Superscript,Image,SelectAll,Source', - removeDialogTabs: 'link:advanced;link:target;image:advanced;images:advanced', + 'removePlugins': 'liststyle', + 'removeButtons': 'Format,Undo,Redo,Cut,Copy,Paste,Anchor,Strike,Subscript,Superscript,Image,SelectAll,Source', + 'removeDialogTabs': 'link:advanced;link:target;image:advanced;images:advanced', - extraPlugins: 'plain,signature', + 'extraPlugins': 'plain,signature', - allowedContent: true, - extraAllowedContent: true, + 'allowedContent': true, + 'extraAllowedContent': true, - fillEmptyBlocks: false, - ignoreEmptyParagraph: true, - disableNativeSpellChecker: false, + 'fillEmptyBlocks': false, + 'ignoreEmptyParagraph': true, + 'disableNativeSpellChecker': false, - font_defaultLabel: 'Arial', - fontSize_defaultLabel: '13', - fontSize_sizes: '10/10px;12/12px;13/13px;14/14px;16/16px;18/18px;20/20px;24/24px;28/28px;36/36px;48/48px' + 'font_defaultLabel': 'Arial', + 'fontSize_defaultLabel': '13', + 'fontSize_sizes': '10/10px;12/12px;13/13px;14/14px;16/16px;18/18px;20/20px;24/24px;28/28px;36/36px;48/48px' }; /** * @type {Object} */ export const oHtmlEditorLangsMap = { - bg_bg: 'bg', - de_de: 'de', - el_gr: 'el', - es_es: 'es', - fr_fr: 'fr', - hu_hu: 'hu', - is_is: 'is', - it_it: 'it', - ja_jp: 'ja', - ko_kr: 'ko', - lt_lt: 'lt', - lv_lv: 'lv', - nl_nl: 'nl', - bg_no: 'no', - pl_pl: 'pl', - pt_pt: 'pt', - pt_br: 'pt-br', - ro_ro: 'ro', - ru_ru: 'ru', - sk_sk: 'sk', - sl_si: 'sl', - sv_se: 'sv', - tr_tr: 'tr', - uk_ua: 'ru', - zh_tw: 'zh', - zh_cn: 'zh-cn' + 'bg_bg': 'bg', + 'de_de': 'de', + 'el_gr': 'el', + 'es_es': 'es', + 'fr_fr': 'fr', + 'hu_hu': 'hu', + 'is_is': 'is', + 'it_it': 'it', + 'ja_jp': 'ja', + 'ko_kr': 'ko', + 'lt_lt': 'lt', + 'lv_lv': 'lv', + 'nl_nl': 'nl', + 'bg_no': 'no', + 'pl_pl': 'pl', + 'pt_pt': 'pt', + 'pt_br': 'pt-br', + 'ro_ro': 'ro', + 'ru_ru': 'ru', + 'sk_sk': 'sk', + 'sl_si': 'sl', + 'sv_se': 'sv', + 'tr_tr': 'tr', + 'uk_ua': 'ru', + 'zh_tw': 'zh', + 'zh_cn': 'zh-cn' }; /** diff --git a/dev/Common/Translator.jsx b/dev/Common/Translator.jsx index af3c44331..3e6fce605 100644 --- a/dev/Common/Translator.jsx +++ b/dev/Common/Translator.jsx @@ -163,12 +163,12 @@ export function i18nToNodes(elements, animate = false) if (animate && bAnimationSupported) { $('.i18n-animation[data-i18n]', elements).letterfx({ - fx: 'fall fade', - backwards: false, - timing: 50, - fx_duration: '50ms', - letter_end: 'restore', - element_end: 'restore' + 'fx': 'fall fade', + 'backwards': false, + 'timing': 50, + 'fx_duration': '50ms', + 'letter_end': 'restore', + 'element_end': 'restore' }); } }); diff --git a/dev/Common/Utils.jsx b/dev/Common/Utils.jsx index 3a850ace7..29564cf35 100644 --- a/dev/Common/Utils.jsx +++ b/dev/Common/Utils.jsx @@ -145,7 +145,10 @@ export function encodeURI(url) */ export function simpleQueryParser(queryString) { - let index = 0, len = 0, temp = null; + let + index = 0, + len = 0, + temp = null; const queries = queryString.split('&'), @@ -498,7 +501,7 @@ export function delegateRun(object, methodName, params, delay = 0) /** * @param {?} event */ -export function kill_CtrlA_CtrlS(event) +export function killCtrlACtrlS(event) { event = event || window.event; if (event && event.ctrlKey && !event.shiftKey && !event.altKey) @@ -1055,8 +1058,8 @@ export function plainToHtml(plain, findEmailAndLinksInText = false) return findEmailAndLinksInText ? findEmailAndLinks(plain) : plain; } -window.rainloop_Utils_htmlToPlain = htmlToPlain; -window.rainloop_Utils_plainToHtml = plainToHtml; +window['rainloop_Utils_htmlToPlain'] = htmlToPlain; // eslint-disable-line dot-notation +window['rainloop_Utils_plainToHtml'] = plainToHtml; // eslint-disable-line dot-notation /** * @param {Array} aSystem @@ -1195,7 +1198,10 @@ export function folderListOptionsBuilder(aSystem, aList, aDisabled, aHeaderLines */ export function selectElement(element) { - let sel = null, range = null; + let + sel = null, + range = null; + if (window.getSelection) { sel = window.getSelection(); diff --git a/dev/External/ko.js b/dev/External/ko.js index 94829a082..6135f8dcc 100644 --- a/dev/External/ko.js +++ b/dev/External/ko.js @@ -1210,6 +1210,11 @@ ko.extenders.idleTrigger = function(oTarget) // functions +ko.observable.fn.idleTrigger = function() +{ + return this.extend({'idleTrigger': true}); +}; + ko.observable.fn.validateNone = function() { this.hasError = ko.observable(false); diff --git a/dev/Helper/Message.jsx b/dev/Helper/Message.jsx index ff7a7d116..375b75bf9 100644 --- a/dev/Helper/Message.jsx +++ b/dev/Helper/Message.jsx @@ -9,10 +9,11 @@ import {EmailModel} from 'Model/Email'; * @returns {string} */ export function emailArrayToString(emails, friendlyView = false, wrapWithLink = false) { + let + index = 0, + len = 0; - let index = 0, len = 0; const result = []; - if (isNonEmptyArray(emails)) { for (len = emails.length; index < len; index++) @@ -29,10 +30,11 @@ export function emailArrayToString(emails, friendlyView = false, wrapWithLink = * @returns {string} */ export function emailArrayToStringClear(emails) { + let + index = 0, + len = 0; - let index = 0, len = 0; const result = []; - if (isNonEmptyArray(emails)) { for (len = emails.length; index < len; index++) @@ -52,10 +54,12 @@ export function emailArrayToStringClear(emails) { * @returns {Array.} */ export function emailArrayFromJson(json) { + let + index = 0, + len = 0, + email = null; - let index = 0, len = 0, email = null; const result = []; - if (isNonEmptyArray(json)) { for (index = 0, len = json.length; index < len; index++) diff --git a/dev/Model/Attachment.jsx b/dev/Model/Attachment.jsx index 0b497b501..e3b3a7bf0 100644 --- a/dev/Model/Attachment.jsx +++ b/dev/Model/Attachment.jsx @@ -233,8 +233,7 @@ export const staticCombinedIconClass = (data) => { class AttachmentModel extends AbstractModel { - constructor() - { + constructor() { super('AttachmentModel'); this.checked = ko.observable(false); diff --git a/dev/Model/Contact.jsx b/dev/Model/Contact.jsx index 55c464bbf..c545f71e2 100644 --- a/dev/Model/Contact.jsx +++ b/dev/Model/Contact.jsx @@ -10,8 +10,7 @@ import {AbstractModel} from 'Knoin/AbstractModel'; class ContactModel extends AbstractModel { - constructor() - { + constructor() { super('ContactModel'); this.idContact = 0; diff --git a/dev/Model/Filter.jsx b/dev/Model/Filter.jsx index 53e391566..a81cdd4d8 100644 --- a/dev/Model/Filter.jsx +++ b/dev/Model/Filter.jsx @@ -12,8 +12,7 @@ import {AbstractModel} from 'Knoin/AbstractModel'; class FilterModel extends AbstractModel { - constructor() - { + constructor() { super('FilterModel'); this.enabled = ko.observable(true); diff --git a/dev/Model/FilterCondition.jsx b/dev/Model/FilterCondition.jsx index 43b0cf62c..a731c7ea5 100644 --- a/dev/Model/FilterCondition.jsx +++ b/dev/Model/FilterCondition.jsx @@ -8,8 +8,7 @@ import {AbstractModel} from 'Knoin/AbstractModel'; class FilterConditionModel extends AbstractModel { - constructor() - { + constructor() { super('FilterConditionModel'); this.field = ko.observable(FilterConditionField.From); diff --git a/dev/Model/Folder.jsx b/dev/Model/Folder.jsx index 2ed6747e0..136da729c 100644 --- a/dev/Model/Folder.jsx +++ b/dev/Model/Folder.jsx @@ -12,8 +12,7 @@ import {AbstractModel} from 'Knoin/AbstractModel'; class FolderModel extends AbstractModel { - constructor() - { + constructor() { super('FolderModel'); this.name = ko.observable(''); diff --git a/dev/Model/Message.jsx b/dev/Model/Message.jsx index 3ba37e992..3c9a2961c 100644 --- a/dev/Model/Message.jsx +++ b/dev/Model/Message.jsx @@ -20,8 +20,7 @@ import {AbstractModel} from 'Knoin/AbstractModel'; class MessageModel extends AbstractModel { - constructor() - { + constructor() { super('MessageModel'); this.folderFullNameRaw = ''; diff --git a/dev/Promises/AbstractAjax.js b/dev/Promises/AbstractAjax.js index 663e2f83b..d435285b8 100644 --- a/dev/Promises/AbstractAjax.js +++ b/dev/Promises/AbstractAjax.js @@ -81,8 +81,11 @@ AbstractAjaxPromises.prototype.ajaxRequest = function(sAction, bPost, iTimeOut, timeout: iTimeOut, global: true }).always(function(oData, sTextStatus) { + var + bCached = false, + oErrorData = null, + sType = Enums.StorageResultType.Error; - var bCached = false, oErrorData = null, sType = Enums.StorageResultType.Error; if (oData && oData.Time) { bCached = Utils.pInt(oData.Time) > Utils.microtime() - iStart; diff --git a/dev/Remote/AbstractAjax.js b/dev/Remote/AbstractAjax.js index c27476e50..7e434e18d 100644 --- a/dev/Remote/AbstractAjax.js +++ b/dev/Remote/AbstractAjax.js @@ -83,10 +83,10 @@ AbstractAjaxRemote.prototype.defaultResponse = function(fCallback, sRequestActio Globals.data.iTokenErrorCount = 0; } + Plugins.runHook('ajax-default-response', [sRequestAction, Enums.StorageResultType.Success === sType ? oData : null, sType, bCached, oRequestParameters]); + if (fCallback) { - Plugins.runHook('ajax-default-response', [sRequestAction, Enums.StorageResultType.Success === sType ? oData : null, sType, bCached, oRequestParameters]); - fCallback( sType, Enums.StorageResultType.Success === sType ? oData : null, diff --git a/dev/Remote/Admin/Ajax.js b/dev/Remote/Admin/Ajax.js index 538622da0..62d57b573 100644 --- a/dev/Remote/Admin/Ajax.js +++ b/dev/Remote/Admin/Ajax.js @@ -10,21 +10,21 @@ var * @constructor * @extends AbstractAjaxRemote */ -function RemoteAdminStorage() +function RemoteAdminAjax() { AbstractAjaxRemote.call(this); this.oRequests = {}; } -_.extend(RemoteAdminStorage.prototype, AbstractAjaxRemote.prototype); +_.extend(RemoteAdminAjax.prototype, AbstractAjaxRemote.prototype); /** * @param {?Function} fCallback * @param {string} sLogin * @param {string} sPassword */ -RemoteAdminStorage.prototype.adminLogin = function(fCallback, sLogin, sPassword) +RemoteAdminAjax.prototype.adminLogin = function(fCallback, sLogin, sPassword) { this.defaultRequest(fCallback, 'AdminLogin', { 'Login': sLogin, @@ -35,7 +35,7 @@ RemoteAdminStorage.prototype.adminLogin = function(fCallback, sLogin, sPassword) /** * @param {?Function} fCallback */ -RemoteAdminStorage.prototype.adminLogout = function(fCallback) +RemoteAdminAjax.prototype.adminLogout = function(fCallback) { this.defaultRequest(fCallback, 'AdminLogout'); }; @@ -44,16 +44,31 @@ RemoteAdminStorage.prototype.adminLogout = function(fCallback) * @param {?Function} fCallback * @param {?} oData */ -RemoteAdminStorage.prototype.saveAdminConfig = function(fCallback, oData) +RemoteAdminAjax.prototype.saveAdminConfig = function(fCallback, oData) { this.defaultRequest(fCallback, 'AdminSettingsUpdate', oData); }; +/** + * @param {string} key + * @param {?Function} valueFn + * @param {?Function} fn + */ +RemoteAdminAjax.prototype.saveAdminConfigHelper = function(key, valueFn, fn) +{ + var self = this; + return function(value) { + var data = {}; + data[key] = valueFn ? valueFn(value) : value; + self.saveAdminConfig(fn || null, data); + }; +}; + /** * @param {?Function} fCallback * @param {boolean=} bIncludeAliases = true */ -RemoteAdminStorage.prototype.domainList = function(fCallback, bIncludeAliases) +RemoteAdminAjax.prototype.domainList = function(fCallback, bIncludeAliases) { bIncludeAliases = Utils.isUnd(bIncludeAliases) ? true : bIncludeAliases; this.defaultRequest(fCallback, 'AdminDomainList', { @@ -64,7 +79,7 @@ RemoteAdminStorage.prototype.domainList = function(fCallback, bIncludeAliases) /** * @param {?Function} fCallback */ -RemoteAdminStorage.prototype.pluginList = function(fCallback) +RemoteAdminAjax.prototype.pluginList = function(fCallback) { this.defaultRequest(fCallback, 'AdminPluginList'); }; @@ -72,7 +87,7 @@ RemoteAdminStorage.prototype.pluginList = function(fCallback) /** * @param {?Function} fCallback */ -RemoteAdminStorage.prototype.packagesList = function(fCallback) +RemoteAdminAjax.prototype.packagesList = function(fCallback) { this.defaultRequest(fCallback, 'AdminPackagesList'); }; @@ -80,7 +95,7 @@ RemoteAdminStorage.prototype.packagesList = function(fCallback) /** * @param {?Function} fCallback */ -RemoteAdminStorage.prototype.coreData = function(fCallback) +RemoteAdminAjax.prototype.coreData = function(fCallback) { this.defaultRequest(fCallback, 'AdminCoreData'); }; @@ -88,7 +103,7 @@ RemoteAdminStorage.prototype.coreData = function(fCallback) /** * @param {?Function} fCallback */ -RemoteAdminStorage.prototype.updateCoreData = function(fCallback) +RemoteAdminAjax.prototype.updateCoreData = function(fCallback) { this.defaultRequest(fCallback, 'AdminUpdateCoreData', {}, 90000); }; @@ -97,7 +112,7 @@ RemoteAdminStorage.prototype.updateCoreData = function(fCallback) * @param {?Function} fCallback * @param {Object} oPackage */ -RemoteAdminStorage.prototype.packageInstall = function(fCallback, oPackage) +RemoteAdminAjax.prototype.packageInstall = function(fCallback, oPackage) { this.defaultRequest(fCallback, 'AdminPackageInstall', { 'Id': oPackage.id, @@ -110,7 +125,7 @@ RemoteAdminStorage.prototype.packageInstall = function(fCallback, oPackage) * @param {?Function} fCallback * @param {Object} oPackage */ -RemoteAdminStorage.prototype.packageDelete = function(fCallback, oPackage) +RemoteAdminAjax.prototype.packageDelete = function(fCallback, oPackage) { this.defaultRequest(fCallback, 'AdminPackageDelete', { 'Id': oPackage.id @@ -121,7 +136,7 @@ RemoteAdminStorage.prototype.packageDelete = function(fCallback, oPackage) * @param {?Function} fCallback * @param {string} sName */ -RemoteAdminStorage.prototype.domain = function(fCallback, sName) +RemoteAdminAjax.prototype.domain = function(fCallback, sName) { this.defaultRequest(fCallback, 'AdminDomainLoad', { 'Name': sName @@ -132,7 +147,7 @@ RemoteAdminStorage.prototype.domain = function(fCallback, sName) * @param {?Function} fCallback * @param {string} sName */ -RemoteAdminStorage.prototype.plugin = function(fCallback, sName) +RemoteAdminAjax.prototype.plugin = function(fCallback, sName) { this.defaultRequest(fCallback, 'AdminPluginLoad', { 'Name': sName @@ -143,7 +158,7 @@ RemoteAdminStorage.prototype.plugin = function(fCallback, sName) * @param {?Function} fCallback * @param {string} sName */ -RemoteAdminStorage.prototype.domainDelete = function(fCallback, sName) +RemoteAdminAjax.prototype.domainDelete = function(fCallback, sName) { this.defaultRequest(fCallback, 'AdminDomainDelete', { 'Name': sName @@ -155,7 +170,7 @@ RemoteAdminStorage.prototype.domainDelete = function(fCallback, sName) * @param {string} sName * @param {boolean} bDisabled */ -RemoteAdminStorage.prototype.domainDisable = function(fCallback, sName, bDisabled) +RemoteAdminAjax.prototype.domainDisable = function(fCallback, sName, bDisabled) { return this.defaultRequest(fCallback, 'AdminDomainDisable', { Name: sName, @@ -167,7 +182,7 @@ RemoteAdminStorage.prototype.domainDisable = function(fCallback, sName, bDisable * @param {?Function} fCallback * @param {Object} oConfig */ -RemoteAdminStorage.prototype.pluginSettingsUpdate = function(fCallback, oConfig) +RemoteAdminAjax.prototype.pluginSettingsUpdate = function(fCallback, oConfig) { return this.defaultRequest(fCallback, 'AdminPluginSettingsUpdate', oConfig); }; @@ -176,7 +191,7 @@ RemoteAdminStorage.prototype.pluginSettingsUpdate = function(fCallback, oConfig) * @param {?Function} fCallback * @param {boolean} bForce */ -RemoteAdminStorage.prototype.licensing = function(fCallback, bForce) +RemoteAdminAjax.prototype.licensing = function(fCallback, bForce) { return this.defaultRequest(fCallback, 'AdminLicensing', { Force: bForce ? '1' : '0' @@ -188,7 +203,7 @@ RemoteAdminStorage.prototype.licensing = function(fCallback, bForce) * @param {string} sDomain * @param {string} sKey */ -RemoteAdminStorage.prototype.licensingActivate = function(fCallback, sDomain, sKey) +RemoteAdminAjax.prototype.licensingActivate = function(fCallback, sDomain, sKey) { return this.defaultRequest(fCallback, 'AdminLicensingActivate', { Domain: sDomain, @@ -201,7 +216,7 @@ RemoteAdminStorage.prototype.licensingActivate = function(fCallback, sDomain, sK * @param {string} sName * @param {boolean} bDisabled */ -RemoteAdminStorage.prototype.pluginDisable = function(fCallback, sName, bDisabled) +RemoteAdminAjax.prototype.pluginDisable = function(fCallback, sName, bDisabled) { return this.defaultRequest(fCallback, 'AdminPluginDisable', { Name: sName, @@ -209,7 +224,7 @@ RemoteAdminStorage.prototype.pluginDisable = function(fCallback, sName, bDisable }); }; -RemoteAdminStorage.prototype.createDomainAlias = function(fCallback, sName, sAlias) +RemoteAdminAjax.prototype.createDomainAlias = function(fCallback, sName, sAlias) { this.defaultRequest(fCallback, 'AdminDomainAliasSave', { Name: sName, @@ -217,7 +232,7 @@ RemoteAdminStorage.prototype.createDomainAlias = function(fCallback, sName, sAli }); }; -RemoteAdminStorage.prototype.createOrUpdateDomain = function(fCallback, +RemoteAdminAjax.prototype.createOrUpdateDomain = function(fCallback, bCreate, sName, sIncHost, iIncPort, sIncSecure, bIncShortLogin, bUseSieve, sSieveAllowRaw, sSieveHost, iSievePort, sSieveSecure, @@ -250,7 +265,7 @@ RemoteAdminStorage.prototype.createOrUpdateDomain = function(fCallback, }); }; -RemoteAdminStorage.prototype.testConnectionForDomain = function(fCallback, sName, +RemoteAdminAjax.prototype.testConnectionForDomain = function(fCallback, sName, sIncHost, iIncPort, sIncSecure, bUseSieve, sSieveHost, iSievePort, sSieveSecure, sOutHost, iOutPort, sOutSecure, bOutAuth, bOutPhpMail) @@ -276,7 +291,7 @@ RemoteAdminStorage.prototype.testConnectionForDomain = function(fCallback, sName * @param {?Function} fCallback * @param {?} oData */ -RemoteAdminStorage.prototype.testContacts = function(fCallback, oData) +RemoteAdminAjax.prototype.testContacts = function(fCallback, oData) { this.defaultRequest(fCallback, 'AdminContactsTest', oData); }; @@ -285,7 +300,7 @@ RemoteAdminStorage.prototype.testContacts = function(fCallback, oData) * @param {?Function} fCallback * @param {?} oData */ -RemoteAdminStorage.prototype.saveNewAdminPassword = function(fCallback, oData) +RemoteAdminAjax.prototype.saveNewAdminPassword = function(fCallback, oData) { this.defaultRequest(fCallback, 'AdminPasswordUpdate', oData); }; @@ -293,9 +308,9 @@ RemoteAdminStorage.prototype.saveNewAdminPassword = function(fCallback, oData) /** * @param {?Function} fCallback */ -RemoteAdminStorage.prototype.adminPing = function(fCallback) +RemoteAdminAjax.prototype.adminPing = function(fCallback) { this.defaultRequest(fCallback, 'AdminPing'); }; -module.exports = new RemoteAdminStorage(); +module.exports = new RemoteAdminAjax(); diff --git a/dev/Remote/User/Ajax.js b/dev/Remote/User/Ajax.js index 61322c146..e84381041 100644 --- a/dev/Remote/User/Ajax.js +++ b/dev/Remote/User/Ajax.js @@ -669,6 +669,21 @@ RemoteUserAjax.prototype.saveSettings = function(fCallback, oData) this.defaultRequest(fCallback, 'SettingsUpdate', oData); }; +/** + * @param {string} key + * @param {?Function} valueFn + * @param {?Function} fn + */ +RemoteUserAjax.prototype.saveSettingsHelper = function(key, valueFn, fn) +{ + var self = this; + return function(value) { + var data = {}; + data[key] = valueFn ? valueFn(value) : value; + self.saveSettings(fn || null, data); + }; +}; + /** * @param {?Function} fCallback * @param {string} sPrevPassword diff --git a/dev/Screen/Admin/Login.jsx b/dev/Screen/Admin/Login.jsx index 9b2a6730d..11252825e 100644 --- a/dev/Screen/Admin/Login.jsx +++ b/dev/Screen/Admin/Login.jsx @@ -4,8 +4,7 @@ import App from 'App/Admin'; class LoginAdminScreen extends AbstractScreen { - constructor() - { + constructor() { super('login', [ require('View/Admin/Login') ]); diff --git a/dev/Screen/Admin/Settings.jsx b/dev/Screen/Admin/Settings.jsx index 25ca707d9..2f27056c0 100644 --- a/dev/Screen/Admin/Settings.jsx +++ b/dev/Screen/Admin/Settings.jsx @@ -13,12 +13,11 @@ import {SecurityAdminSettings} from 'Settings/Admin/Security'; import {SocialAdminSettings} from 'Settings/Admin/Social'; import {PluginsAdminSettings} from 'Settings/Admin/Plugins'; import {PackagesAdminSettings} from 'Settings/Admin/Packages'; -// import {AboutAdminSettings} from 'Settings/Admin/About'; +import {AboutAdminSettings} from 'Settings/Admin/About'; class SettingsAdminScreen extends AbstractSettingsScreen { - constructor() - { + constructor() { super([ require('View/Admin/Settings/Menu'), require('View/Admin/Settings/Pane') @@ -70,8 +69,8 @@ class SettingsAdminScreen extends AbstractSettingsScreen 'AdminSettingsLicensing', 'TABS_LABELS/LABEL_LICENSING_NAME', 'licensing'); } - // addSettingsViewModel(AboutAdminSettings, - // 'AdminSettingsAbout', 'TABS_LABELS/LABEL_ABOUT_NAME', 'about'); + addSettingsViewModel(AboutAdminSettings, + 'AdminSettingsAbout', 'TABS_LABELS/LABEL_ABOUT_NAME', 'about'); runSettingsViewModelHooks(true); diff --git a/dev/Screen/User/About.jsx b/dev/Screen/User/About.jsx index 20a6edf63..c4fc88ad7 100644 --- a/dev/Screen/User/About.jsx +++ b/dev/Screen/User/About.jsx @@ -4,8 +4,7 @@ import App from 'App/User'; class AboutUserScreen extends AbstractScreen { - constructor() - { + constructor() { super('about', [ require('View/User/About') ]); diff --git a/dev/Screen/User/Login.jsx b/dev/Screen/User/Login.jsx index f2de068d7..c17edbc4d 100644 --- a/dev/Screen/User/Login.jsx +++ b/dev/Screen/User/Login.jsx @@ -4,8 +4,7 @@ import App from 'App/User'; class LoginUserScreen extends AbstractScreen { - constructor() - { + constructor() { super('login', [ require('View/User/Login') ]); diff --git a/dev/Screen/User/MailBox.jsx b/dev/Screen/User/MailBox.jsx index 82a95062c..ba2ccd460 100644 --- a/dev/Screen/User/MailBox.jsx +++ b/dev/Screen/User/MailBox.jsx @@ -21,8 +21,7 @@ import App from 'App/User'; class MailBoxUserScreen extends AbstractScreen { - constructor() - { + constructor() { super('mailbox', [ require('View/User/MailBox/SystemDropDown'), require('View/User/MailBox/FolderList'), diff --git a/dev/Screen/User/Settings.jsx b/dev/Screen/User/Settings.jsx index d97c582c3..2b6809b68 100644 --- a/dev/Screen/User/Settings.jsx +++ b/dev/Screen/User/Settings.jsx @@ -27,8 +27,7 @@ import {OpenPgpUserSettings} from 'Settings/User/OpenPgp'; class SettingsUserScreen extends AbstractSettingsScreen { - constructor() - { + constructor() { super([ require('View/User/Settings/SystemDropDown'), require('View/User/Settings/Menu'), diff --git a/dev/Settings/Admin/About.jsx b/dev/Settings/Admin/About.jsx index 9b42bccbc..192f66d88 100644 --- a/dev/Settings/Admin/About.jsx +++ b/dev/Settings/Admin/About.jsx @@ -1,92 +1,86 @@ -var - ko = require('ko'), +import ko from 'ko'; - Translator = require('Common/Translator'), +import {i18n, trigger as translatorTrigger} from 'Common/Translator'; +import {appSettingsGet, settingsGet} from 'Storage/Settings'; - Settings = require('Storage/Settings'), - CoreStore = require('Stores/Admin/Core'), - AppStore = require('Stores/Admin/App'); +import CoreStore from 'Stores/Admin/Core'; +import AppStore from 'Stores/Admin/App'; -/** - * @constructor - */ -function AboutAdminSettings() +class AboutAdminSettings { - this.version = ko.observable(Settings.appSettingsGet('version')); - this.access = ko.observable(!!Settings.settingsGet('CoreAccess')); - this.errorDesc = ko.observable(''); + constructor() { + this.version = ko.observable(appSettingsGet('version')); + this.access = ko.observable(!!settingsGet('CoreAccess')); + this.errorDesc = ko.observable(''); - this.coreReal = CoreStore.coreReal; - this.coreChannel = CoreStore.coreChannel; - this.coreType = CoreStore.coreType; - this.coreUpdatable = CoreStore.coreUpdatable; - this.coreAccess = CoreStore.coreAccess; - this.coreChecking = CoreStore.coreChecking; - this.coreUpdating = CoreStore.coreUpdating; - this.coreWarning = CoreStore.coreWarning; - this.coreVersion = CoreStore.coreVersion; - this.coreRemoteVersion = CoreStore.coreRemoteVersion; - this.coreRemoteRelease = CoreStore.coreRemoteRelease; - this.coreVersionCompare = CoreStore.coreVersionCompare; + this.coreReal = CoreStore.coreReal; + this.coreChannel = CoreStore.coreChannel; + this.coreType = CoreStore.coreType; + this.coreUpdatable = CoreStore.coreUpdatable; + this.coreAccess = CoreStore.coreAccess; + this.coreChecking = CoreStore.coreChecking; + this.coreUpdating = CoreStore.coreUpdating; + this.coreWarning = CoreStore.coreWarning; + this.coreVersion = CoreStore.coreVersion; + this.coreRemoteVersion = CoreStore.coreRemoteVersion; + this.coreRemoteRelease = CoreStore.coreRemoteRelease; + this.coreVersionCompare = CoreStore.coreVersionCompare; - this.community = RL_COMMUNITY || AppStore.community(); + this.community = RL_COMMUNITY || AppStore.community(); - this.coreRemoteVersionHtmlDesc = ko.computed(function() { - Translator.trigger(); - return Translator.i18n('TAB_ABOUT/HTML_NEW_VERSION', {'VERSION': this.coreRemoteVersion()}); - }, this); + this.coreRemoteVersionHtmlDesc = ko.computed(() => { + translatorTrigger(); + return i18n('TAB_ABOUT/HTML_NEW_VERSION', {'VERSION': this.coreRemoteVersion()}); + }); - this.statusType = ko.computed(function() { + this.statusType = ko.computed(() => { + let type = ''; + const + versionToCompare = this.coreVersionCompare(), + isChecking = this.coreChecking(), + isUpdating = this.coreUpdating(), + isReal = this.coreReal(); - var - sType = '', - iVersionCompare = this.coreVersionCompare(), - bChecking = this.coreChecking(), - bUpdating = this.coreUpdating(), - bReal = this.coreReal(); + if (isChecking) + { + type = 'checking'; + } + else if (isUpdating) + { + type = 'updating'; + } + else if (isReal && 0 === versionToCompare) + { + type = 'up-to-date'; + } + else if (isReal && -1 === versionToCompare) + { + type = 'available'; + } + else if (!isReal) + { + type = 'error'; + this.errorDesc('Cannot access the repository at the moment.'); + } - if (bChecking) + return type; + }); + } + + onBuild() { + if (this.access() && !this.community) { - sType = 'checking'; - } - else if (bUpdating) - { - sType = 'updating'; - } - else if (bReal && 0 === iVersionCompare) - { - sType = 'up-to-date'; - } - else if (bReal && -1 === iVersionCompare) - { - sType = 'available'; - } - else if (!bReal) - { - sType = 'error'; - this.errorDesc('Cannot access the repository at the moment.'); + require('App/Admin').default.reloadCoreData(); } + } - return sType; - - }, this); + updateCoreData() { + if (!this.coreUpdating() && !this.community) + { + require('App/Admin').default.updateCoreData(); + } + } } -AboutAdminSettings.prototype.onBuild = function() -{ - if (this.access() && !this.community) - { - require('App/Admin').default.reloadCoreData(); - } -}; - -AboutAdminSettings.prototype.updateCoreData = function() -{ - if (!this.coreUpdating() && !this.community) - { - require('App/Admin').default.updateCoreData(); - } -}; - export {AboutAdminSettings, AboutAdminSettings as default}; diff --git a/dev/Settings/Admin/Branding.jsx b/dev/Settings/Admin/Branding.jsx index af194704b..d7b361442 100644 --- a/dev/Settings/Admin/Branding.jsx +++ b/dev/Settings/Admin/Branding.jsx @@ -9,26 +9,25 @@ import {settingsGet} from 'Storage/Settings'; class BrandingAdminSettings { - constructor() - { + constructor() { const AppStore = require('Stores/Admin/App'); this.capa = AppStore.prem; - this.title = ko.observable(settingsGet('Title')).extend({idleTrigger: true}); - this.loadingDesc = ko.observable(settingsGet('LoadingDescription')).extend({idleTrigger: true}); - this.faviconUrl = ko.observable(settingsGet('FaviconUrl')).extend({idleTrigger: true}); - this.loginLogo = ko.observable(settingsGet('LoginLogo') || '').extend({idleTrigger: true}); - this.loginBackground = ko.observable(settingsGet('LoginBackground') || '').extend({idleTrigger: true}); - this.userLogo = ko.observable(settingsGet('UserLogo') || '').extend({idleTrigger: true}); - this.userLogoMessage = ko.observable(settingsGet('UserLogoMessage') || '').extend({idleTrigger: true}); - this.userIframeMessage = ko.observable(settingsGet('UserIframeMessage') || '').extend({idleTrigger: true}); - this.userLogoTitle = ko.observable(settingsGet('UserLogoTitle') || '').extend({idleTrigger: true}); - this.loginDescription = ko.observable(settingsGet('LoginDescription')).extend({idleTrigger: true}); - this.loginCss = ko.observable(settingsGet('LoginCss')).extend({idleTrigger: true}); - this.userCss = ko.observable(settingsGet('UserCss')).extend({idleTrigger: true}); - this.welcomePageUrl = ko.observable(settingsGet('WelcomePageUrl')).extend({idleTrigger: true}); - this.welcomePageDisplay = ko.observable(settingsGet('WelcomePageDisplay')).extend({idleTrigger: true}); + this.title = ko.observable(settingsGet('Title')).idleTrigger(); + this.loadingDesc = ko.observable(settingsGet('LoadingDescription')).idleTrigger(); + this.faviconUrl = ko.observable(settingsGet('FaviconUrl')).idleTrigger(); + this.loginLogo = ko.observable(settingsGet('LoginLogo') || '').idleTrigger(); + this.loginBackground = ko.observable(settingsGet('LoginBackground') || '').idleTrigger(); + this.userLogo = ko.observable(settingsGet('UserLogo') || '').idleTrigger(); + this.userLogoMessage = ko.observable(settingsGet('UserLogoMessage') || '').idleTrigger(); + this.userIframeMessage = ko.observable(settingsGet('UserIframeMessage') || '').idleTrigger(); + this.userLogoTitle = ko.observable(settingsGet('UserLogoTitle') || '').idleTrigger(); + this.loginDescription = ko.observable(settingsGet('LoginDescription')).idleTrigger(); + this.loginCss = ko.observable(settingsGet('LoginCss')).idleTrigger(); + this.userCss = ko.observable(settingsGet('UserCss')).idleTrigger(); + this.welcomePageUrl = ko.observable(settingsGet('WelcomePageUrl')).idleTrigger(); + this.welcomePageDisplay = ko.observable(settingsGet('WelcomePageDisplay')).idleTrigger(); this.welcomePageDisplay.options = ko.computed(() => { translatorTrigger(); return [ diff --git a/dev/Settings/Admin/Contacts.jsx b/dev/Settings/Admin/Contacts.jsx index 21f653d68..fe43b8923 100644 --- a/dev/Settings/Admin/Contacts.jsx +++ b/dev/Settings/Admin/Contacts.jsx @@ -1,234 +1,222 @@ -var - _ = require('_'), - ko = require('ko'), +import _ from '_'; +import ko from 'ko'; - Enums = require('Common/Enums'), - Utils = require('Common/Utils'), +import { + settingsSaveHelperSimpleFunction, + defautOptionsAfterRender, createCommand, + inArray, trim, boolToAjax +} from 'Common/Utils'; - Translator = require('Common/Translator'), +import {SaveSettingsStep, StorageResultType, Magics} from 'Common/Enums'; +import {i18n} from 'Common/Translator'; +import {settingsGet} from 'Storage/Settings'; - Settings = require('Storage/Settings'); - -/** - * @constructor - */ -function ContactsAdminSettings() +class ContactsAdminSettings { - var - Remote = require('Remote/Admin/Ajax'); + constructor() { + this.defautOptionsAfterRender = defautOptionsAfterRender; + this.enableContacts = ko.observable(!!settingsGet('ContactsEnable')); + this.contactsSharing = ko.observable(!!settingsGet('ContactsSharing')); + this.contactsSync = ko.observable(!!settingsGet('ContactsSync')); - this.defautOptionsAfterRender = Utils.defautOptionsAfterRender; - this.enableContacts = ko.observable(!!Settings.settingsGet('ContactsEnable')); - this.contactsSharing = ko.observable(!!Settings.settingsGet('ContactsSharing')); - this.contactsSync = ko.observable(!!Settings.settingsGet('ContactsSync')); - - var - aTypes = ['sqlite', 'mysql', 'pgsql'], - aSupportedTypes = [], - getTypeName = function(sName) { - switch (sName) - { - case 'sqlite': - sName = 'SQLite'; - break; - case 'mysql': - sName = 'MySQL'; - break; - case 'pgsql': - sName = 'PostgreSQL'; - break; - // no default - } - - return sName; - }; - - if (Settings.settingsGet('SQLiteIsSupported')) - { - aSupportedTypes.push('sqlite'); - } - if (Settings.settingsGet('MySqlIsSupported')) - { - aSupportedTypes.push('mysql'); - } - if (Settings.settingsGet('PostgreSqlIsSupported')) - { - aSupportedTypes.push('pgsql'); - } - - this.contactsSupported = 0 < aSupportedTypes.length; - - this.contactsTypes = ko.observableArray([]); - this.contactsTypesOptions = this.contactsTypes.map(function(sValue) { - var bDisabled = -1 === Utils.inArray(sValue, aSupportedTypes); - return { - 'id': sValue, - 'name': getTypeName(sValue) + (bDisabled ? ' (' + Translator.i18n('HINTS/NOT_SUPPORTED') + ')' : ''), - 'disabled': bDisabled - }; - }); - - this.contactsTypes(aTypes); - this.contactsType = ko.observable(''); - - this.mainContactsType = ko.computed({ - 'owner': this, - 'read': this.contactsType, - 'write': function(sValue) { - if (sValue !== this.contactsType()) - { - if (-1 < Utils.inArray(sValue, aSupportedTypes)) + const + Remote = require('Remote/Admin/Ajax'), + supportedTypes = [], + types = ['sqlite', 'mysql', 'pgsql'], + getTypeName = (name) => { + switch (name) { - this.contactsType(sValue); + case 'sqlite': + name = 'SQLite'; + break; + case 'mysql': + name = 'MySQL'; + break; + case 'pgsql': + name = 'PostgreSQL'; + break; + // no default } - else if (0 < aSupportedTypes.length) - { - this.contactsType(''); - } - } - else - { - this.contactsType.valueHasMutated(); - } + + return name; + }; + + if (settingsGet('SQLiteIsSupported')) + { + supportedTypes.push('sqlite'); + } + if (settingsGet('MySqlIsSupported')) + { + supportedTypes.push('mysql'); + } + if (settingsGet('PostgreSqlIsSupported')) + { + supportedTypes.push('pgsql'); } - }).extend({'notify': 'always'}); - this.contactsType.subscribe(function() { - this.testContactsSuccess(false); - this.testContactsError(false); - this.testContactsErrorMessage(''); - }, this); + this.contactsSupported = 0 < supportedTypes.length; - this.pdoDsn = ko.observable(Settings.settingsGet('ContactsPdoDsn')); - this.pdoUser = ko.observable(Settings.settingsGet('ContactsPdoUser')); - this.pdoPassword = ko.observable(Settings.settingsGet('ContactsPdoPassword')); - - this.pdoDsnTrigger = ko.observable(Enums.SaveSettingsStep.Idle); - this.pdoUserTrigger = ko.observable(Enums.SaveSettingsStep.Idle); - this.pdoPasswordTrigger = ko.observable(Enums.SaveSettingsStep.Idle); - this.contactsTypeTrigger = ko.observable(Enums.SaveSettingsStep.Idle); - - this.testing = ko.observable(false); - this.testContactsSuccess = ko.observable(false); - this.testContactsError = ko.observable(false); - this.testContactsErrorMessage = ko.observable(''); - - this.testContactsCommand = Utils.createCommand(this, function() { - - 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.contactsTypes = ko.observableArray([]); + this.contactsTypesOptions = this.contactsTypes.map((value) => { + const disabled = -1 === inArray(value, supportedTypes); + return { + 'id': value, + 'name': getTypeName(value) + (disabled ? ' (' + i18n('HINTS/NOT_SUPPORTED') + ')' : ''), + 'disabled': disabled + }; }); - }, function() { - return '' !== this.pdoDsn() && '' !== this.pdoUser(); - }); + this.contactsTypes(types); + this.contactsType = ko.observable(''); - this.contactsType(Settings.settingsGet('ContactsPdoType')); + this.mainContactsType = ko.computed({ + 'read': this.contactsType, + 'write': (value) => { + if (value !== this.contactsType()) + { + if (-1 < inArray(value, supportedTypes)) + { + this.contactsType(value); + } + else if (0 < supportedTypes.length) + { + this.contactsType(''); + } + } + else + { + this.contactsType.valueHasMutated(); + } + } + }).extend({notify: 'always'}); - this.onTestContactsResponse = _.bind(this.onTestContactsResponse, this); -} + this.contactsType.subscribe(function() { + this.testContactsSuccess(false); + this.testContactsError(false); + this.testContactsErrorMessage(''); + }, this); -ContactsAdminSettings.prototype.onTestContactsResponse = function(sResult, oData) -{ - this.testContactsSuccess(false); - this.testContactsError(false); - this.testContactsErrorMessage(''); + this.pdoDsn = ko.observable(settingsGet('ContactsPdoDsn')); + this.pdoUser = ko.observable(settingsGet('ContactsPdoUser')); + this.pdoPassword = ko.observable(settingsGet('ContactsPdoPassword')); - if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.Result) - { - this.testContactsSuccess(true); + this.pdoDsnTrigger = ko.observable(SaveSettingsStep.Idle); + this.pdoUserTrigger = ko.observable(SaveSettingsStep.Idle); + this.pdoPasswordTrigger = ko.observable(SaveSettingsStep.Idle); + this.contactsTypeTrigger = ko.observable(SaveSettingsStep.Idle); + + this.testing = ko.observable(false); + this.testContactsSuccess = ko.observable(false); + this.testContactsError = ko.observable(false); + this.testContactsErrorMessage = ko.observable(''); + + this.testContactsCommand = createCommand(this, () => { + + 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); } - else - { - this.testContactsError(true); - if (oData && oData.Result) + + onTestContactsResponse(result, data) { + this.testContactsSuccess(false); + this.testContactsError(false); + this.testContactsErrorMessage(''); + + if (StorageResultType.Success === result && data && data.Result && data.Result.Result) { - this.testContactsErrorMessage(oData.Result.Message || ''); + this.testContactsSuccess(true); } else { - this.testContactsErrorMessage(''); + this.testContactsError(true); + if (data && data.Result) + { + this.testContactsErrorMessage(data.Result.Message || ''); + } + else + { + this.testContactsErrorMessage(''); + } } + + this.testing(false); } - this.testing(false); -}; + onShow() { + this.testContactsSuccess(false); + this.testContactsError(false); + this.testContactsErrorMessage(''); + } -ContactsAdminSettings.prototype.onShow = function() -{ - this.testContactsSuccess(false); - this.testContactsError(false); - this.testContactsErrorMessage(''); -}; + onBuild() { + _.delay(() => { + const + Remote = require('Remote/Admin/Ajax'), + f1 = settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this), + f3 = settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this), + f4 = settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this), + f5 = settingsSaveHelperSimpleFunction(this.contactsTypeTrigger, this); -ContactsAdminSettings.prototype.onBuild = function() -{ - var - self = this, - Remote = require('Remote/Admin/Ajax'); - - _.delay(function() { - - var - f1 = Utils.settingsSaveHelperSimpleFunction(self.pdoDsnTrigger, self), - f3 = Utils.settingsSaveHelperSimpleFunction(self.pdoUserTrigger, self), - f4 = Utils.settingsSaveHelperSimpleFunction(self.pdoPasswordTrigger, self), - f5 = Utils.settingsSaveHelperSimpleFunction(self.contactsTypeTrigger, self); - - self.enableContacts.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'ContactsEnable': bValue ? '1' : '0' + this.enableContacts.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'ContactsEnable': boolToAjax(value) + }); }); - }); - self.contactsSharing.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'ContactsSharing': bValue ? '1' : '0' + this.contactsSharing.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'ContactsSharing': boolToAjax(value) + }); }); - }); - self.contactsSync.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'ContactsSync': bValue ? '1' : '0' + this.contactsSync.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'ContactsSync': boolToAjax(value) + }); }); - }); - self.contactsType.subscribe(function(sValue) { - Remote.saveAdminConfig(f5, { - 'ContactsPdoType': sValue + this.contactsType.subscribe((value) => { + Remote.saveAdminConfig(f5, { + 'ContactsPdoType': trim(value) + }); }); - }); - self.pdoDsn.subscribe(function(sValue) { - Remote.saveAdminConfig(f1, { - 'ContactsPdoDsn': Utils.trim(sValue) + this.pdoDsn.subscribe((value) => { + Remote.saveAdminConfig(f1, { + 'ContactsPdoDsn': trim(value) + }); }); - }); - self.pdoUser.subscribe(function(sValue) { - Remote.saveAdminConfig(f3, { - 'ContactsPdoUser': Utils.trim(sValue) + this.pdoUser.subscribe((value) => { + Remote.saveAdminConfig(f3, { + 'ContactsPdoUser': trim(value) + }); }); - }); - self.pdoPassword.subscribe(function(sValue) { - Remote.saveAdminConfig(f4, { - 'ContactsPdoPassword': Utils.trim(sValue) + this.pdoPassword.subscribe((value) => { + Remote.saveAdminConfig(f4, { + 'ContactsPdoPassword': trim(value) + }); }); - }); - self.contactsType(Settings.settingsGet('ContactsPdoType')); - - }, 50); -}; + this.contactsType(settingsGet('ContactsPdoType')); + }, Magics.Time50ms); + } +} export {ContactsAdminSettings, ContactsAdminSettings as default}; diff --git a/dev/Settings/Admin/Domains.jsx b/dev/Settings/Admin/Domains.jsx index bba412f7b..359c52859 100644 --- a/dev/Settings/Admin/Domains.jsx +++ b/dev/Settings/Admin/Domains.jsx @@ -1,78 +1,68 @@ -var - _ = require('_'), - ko = require('ko'), +import _ from '_'; +import ko from 'ko'; - Enums = require('Common/Enums'), +import {StorageResultType} from 'Common/Enums'; +import {showScreenPopup} from 'Knoin/Knoin'; - DomainStore = require('Stores/Admin/Domain'), - Remote = require('Remote/Admin/Ajax'); +import DomainStore from 'Stores/Admin/Domain'; +import Remote from 'Remote/Admin/Ajax'; -/** - * @constructor - */ -function DomainsAdminSettings() +class DomainsAdminSettings { - this.domains = DomainStore.domains; + constructor() { + this.domains = DomainStore.domains; - this.visibility = ko.computed(function() { - return this.domains.loading() ? 'visible' : 'hidden'; - }, this); + this.visibility = ko.computed(() => (this.domains.loading() ? 'visible' : 'hidden')); - this.domainForDeletion = ko.observable(null).deleteAccessHelper(); + this.domainForDeletion = ko.observable(null).deleteAccessHelper(); - this.onDomainListChangeRequest = _.bind(this.onDomainListChangeRequest, this); - this.onDomainLoadRequest = _.bind(this.onDomainLoadRequest, this); + this.onDomainListChangeRequest = _.bind(this.onDomainListChangeRequest, this); + this.onDomainLoadRequest = _.bind(this.onDomainLoadRequest, this); + } + + createDomain() { + showScreenPopup(require('View/Popup/Domain')); + } + + createDomainAlias() { + showScreenPopup(require('View/Popup/DomainAlias')); + } + + deleteDomain(domain) { + this.domains.remove(domain); + Remote.domainDelete(this.onDomainListChangeRequest, domain.name); + } + + disableDomain(domain) { + domain.disabled(!domain.disabled()); + Remote.domainDisable(this.onDomainListChangeRequest, domain.name, domain.disabled()); + } + + onBuild(oDom) { + const self = this; + oDom + .on('click', '.b-admin-domains-list-table .e-item .e-action', function() { + const domainItem = ko.dataFor(this); + if (domainItem) + { + Remote.domain(self.onDomainLoadRequest, domainItem.name); + } + }); + + require('App/Admin').default.reloadDomainList(); + } + + onDomainLoadRequest(sResult, oData) { + if (StorageResultType.Success === sResult && oData && oData.Result) + { + showScreenPopup(require('View/Popup/Domain'), [oData.Result]); + } + } + + onDomainListChangeRequest() { + require('App/Admin').default.reloadDomainList(); + } } -DomainsAdminSettings.prototype.createDomain = function() -{ - require('Knoin/Knoin').showScreenPopup(require('View/Popup/Domain')); -}; - -DomainsAdminSettings.prototype.createDomainAlias = function() -{ - require('Knoin/Knoin').showScreenPopup(require('View/Popup/DomainAlias')); -}; - -DomainsAdminSettings.prototype.deleteDomain = function(oDomain) -{ - this.domains.remove(oDomain); - Remote.domainDelete(this.onDomainListChangeRequest, oDomain.name); -}; - -DomainsAdminSettings.prototype.disableDomain = function(oDomain) -{ - oDomain.disabled(!oDomain.disabled()); - Remote.domainDisable(this.onDomainListChangeRequest, oDomain.name, oDomain.disabled()); -}; - -DomainsAdminSettings.prototype.onBuild = function(oDom) -{ - var self = this; - oDom - .on('click', '.b-admin-domains-list-table .e-item .e-action', function() { - var oDomainItem = ko.dataFor(this); - if (oDomainItem) - { - Remote.domain(self.onDomainLoadRequest, oDomainItem.name); - } - }); - - require('App/Admin').default.reloadDomainList(); -}; - -DomainsAdminSettings.prototype.onDomainLoadRequest = function(sResult, oData) -{ - if (Enums.StorageResultType.Success === sResult && oData && oData.Result) - { - require('Knoin/Knoin').showScreenPopup(require('View/Popup/Domain'), [oData.Result]); - } -}; - -DomainsAdminSettings.prototype.onDomainListChangeRequest = function() -{ - require('App/Admin').default.reloadDomainList(); -}; - export {DomainsAdminSettings, DomainsAdminSettings as default}; diff --git a/dev/Settings/Admin/General.jsx b/dev/Settings/Admin/General.jsx index 8fe7c3c7b..f91307090 100644 --- a/dev/Settings/Admin/General.jsx +++ b/dev/Settings/Admin/General.jsx @@ -1,202 +1,176 @@ -var - _ = require('_'), - ko = require('ko'), +import _ from '_'; +import ko from 'ko'; - Enums = require('Common/Enums'), - Utils = require('Common/Utils'), - Links = require('Common/Links'), - Translator = require('Common/Translator'), +import { + trim, pInt, boolToAjax, settingsSaveHelperSimpleFunction, + changeTheme, convertThemeName, convertLangName +} from 'Common/Utils'; - ThemeStore = require('Stores/Theme'), - LanguageStore = require('Stores/Language'), - AppAdminStore = require('Stores/Admin/App'), - CapaAdminStore = require('Stores/Admin/Capa'), +import {SaveSettingsStep, Magics} from 'Common/Enums'; +import {reload as translatorReload} from 'Common/Translator'; +import {phpInfo} from 'Common/Links'; - Settings = require('Storage/Settings'); +import {settingsGet} from 'Storage/Settings'; +import {showScreenPopup} from 'Knoin/Knoin'; -/** - * @constructor - */ -function GeneralAdminSettings() +import ThemeStore from 'Stores/Theme'; +import LanguageStore from 'Stores/Language'; +import AppAdminStore from 'Stores/Admin/App'; +import CapaAdminStore from 'Stores/Admin/Capa'; + +class GeneralAdminSettings { - this.language = LanguageStore.language; - this.languages = LanguageStore.languages; - this.languageAdmin = LanguageStore.languageAdmin; - this.languagesAdmin = LanguageStore.languagesAdmin; + constructor() { + this.language = LanguageStore.language; + this.languages = LanguageStore.languages; + this.languageAdmin = LanguageStore.languageAdmin; + this.languagesAdmin = LanguageStore.languagesAdmin; - this.theme = ThemeStore.theme; - this.themes = ThemeStore.themes; + this.theme = ThemeStore.theme; + this.themes = ThemeStore.themes; - this.capaThemes = CapaAdminStore.themes; - this.capaUserBackground = CapaAdminStore.userBackground; - this.capaGravatar = CapaAdminStore.gravatar; - this.capaAdditionalAccounts = CapaAdminStore.additionalAccounts; - this.capaIdentities = CapaAdminStore.identities; - this.capaAttachmentThumbnails = CapaAdminStore.attachmentThumbnails; - this.capaTemplates = CapaAdminStore.templates; + this.capaThemes = CapaAdminStore.themes; + this.capaUserBackground = CapaAdminStore.userBackground; + this.capaGravatar = CapaAdminStore.gravatar; + this.capaAdditionalAccounts = CapaAdminStore.additionalAccounts; + this.capaIdentities = CapaAdminStore.identities; + this.capaAttachmentThumbnails = CapaAdminStore.attachmentThumbnails; + this.capaTemplates = CapaAdminStore.templates; - this.allowLanguagesOnSettings = AppAdminStore.allowLanguagesOnSettings; - this.weakPassword = AppAdminStore.weakPassword; + this.allowLanguagesOnSettings = AppAdminStore.allowLanguagesOnSettings; + this.weakPassword = AppAdminStore.weakPassword; - this.mainAttachmentLimit = ko.observable(Utils.pInt(Settings.settingsGet('AttachmentLimit')) / (1024 * 1024)).extend({'posInterer': 25}); - this.uploadData = Settings.settingsGet('PhpUploadSizes'); - this.uploadDataDesc = this.uploadData && (this.uploadData.upload_max_filesize || this.uploadData.post_max_size) ? [ - this.uploadData.upload_max_filesize ? 'upload_max_filesize = ' + this.uploadData.upload_max_filesize + '; ' : '', - this.uploadData.post_max_size ? 'post_max_size = ' + this.uploadData.post_max_size : '' - ].join('') : ''; + this.mainAttachmentLimit = ko.observable(pInt(settingsGet('AttachmentLimit')) / (Magics.BitLength1024 * Magics.BitLength1024)).extend({posInterer: 25}); - this.themesOptions = ko.computed(function() { - return _.map(this.themes(), function(sTheme) { - return { - optValue: sTheme, - optText: Utils.convertThemeName(sTheme) - }; - }); - }, this); + this.uploadData = settingsGet('PhpUploadSizes'); + this.uploadDataDesc = this.uploadData && (this.uploadData.upload_max_filesize || this.uploadData.post_max_size) ? [ + this.uploadData.upload_max_filesize ? 'upload_max_filesize = ' + this.uploadData.upload_max_filesize + '; ' : '', + this.uploadData.post_max_size ? 'post_max_size = ' + this.uploadData.post_max_size : '' + ].join('') : ''; - this.languageFullName = ko.computed(function() { - return Utils.convertLangName(this.language()); - }, this); + this.themesOptions = ko.computed(() => _.map(this.themes(), (theme) => ({optValue: theme, optText: convertThemeName(theme)}))); - this.languageAdminFullName = ko.computed(function() { - return Utils.convertLangName(this.languageAdmin()); - }, this); + this.languageFullName = ko.computed(() => convertLangName(this.language())); + this.languageAdminFullName = ko.computed(() => convertLangName(this.languageAdmin())); - this.attachmentLimitTrigger = ko.observable(Enums.SaveSettingsStep.Idle); - this.languageTrigger = ko.observable(Enums.SaveSettingsStep.Idle); - this.languageAdminTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': 100}); - this.themeTrigger = ko.observable(Enums.SaveSettingsStep.Idle); -} + this.attachmentLimitTrigger = ko.observable(SaveSettingsStep.Idle); + this.languageTrigger = ko.observable(SaveSettingsStep.Idle); + this.languageAdminTrigger = ko.observable(SaveSettingsStep.Idle).extend({throttle: Magics.Time100ms}); + this.themeTrigger = ko.observable(SaveSettingsStep.Idle); + } -GeneralAdminSettings.prototype.onBuild = function() -{ - var - self = this, - Remote = require('Remote/Admin/Ajax'); - - _.delay(function() { - - var - f1 = Utils.settingsSaveHelperSimpleFunction(self.attachmentLimitTrigger, self), - f2 = Utils.settingsSaveHelperSimpleFunction(self.languageTrigger, self), - f3 = Utils.settingsSaveHelperSimpleFunction(self.themeTrigger, self), - fReloadLanguageHelper = function(iSaveSettingsStep) { - return function() { - self.languageAdminTrigger(iSaveSettingsStep); - _.delay(function() { - self.languageAdminTrigger(Enums.SaveSettingsStep.Idle); - }, 1000); + onBuild() { + _.delay(() => { + const + Remote = require('Remote/Admin/Ajax'), + f1 = settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this), + f2 = settingsSaveHelperSimpleFunction(this.languageTrigger, this), + f3 = settingsSaveHelperSimpleFunction(this.themeTrigger, this), + fReloadLanguageHelper = (saveSettingsStep) => () => { + this.languageAdminTrigger(saveSettingsStep); + _.delay(() => this.languageAdminTrigger(SaveSettingsStep.Idle), Magics.Time1s); }; - }; - self.mainAttachmentLimit.subscribe(function(sValue) { - Remote.saveAdminConfig(f1, { - 'AttachmentLimit': Utils.pInt(sValue) - }); - }); - - self.language.subscribe(function(sValue) { - Remote.saveAdminConfig(f2, { - 'Language': Utils.trim(sValue) - }); - }); - - self.languageAdmin.subscribe(function(sValue) { - - self.languageAdminTrigger(Enums.SaveSettingsStep.Animate); - - Translator.reload(true, sValue).then( - fReloadLanguageHelper(Enums.SaveSettingsStep.TrueResult), - fReloadLanguageHelper(Enums.SaveSettingsStep.FalseResult) - ).then(function() { - Remote.saveAdminConfig(null, { - 'LanguageAdmin': Utils.trim(sValue) + this.mainAttachmentLimit.subscribe((value) => { + Remote.saveAdminConfig(f1, { + 'AttachmentLimit': pInt(value) }); }); - }); - - self.theme.subscribe(function(sValue) { - - Utils.changeTheme(sValue, self.themeTrigger); - - Remote.saveAdminConfig(f3, { - 'Theme': Utils.trim(sValue) + this.language.subscribe((value) => { + Remote.saveAdminConfig(f2, { + 'Language': trim(value) + }); }); - }); - self.capaAdditionalAccounts.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'CapaAdditionalAccounts': bValue ? '1' : '0' + this.languageAdmin.subscribe((value) => { + this.languageAdminTrigger(SaveSettingsStep.Animate); + translatorReload(true, value).then( + fReloadLanguageHelper(SaveSettingsStep.TrueResult), + fReloadLanguageHelper(SaveSettingsStep.FalseResult) + ).then(() => { + Remote.saveAdminConfig(null, { + 'LanguageAdmin': trim(value) + }); + }); }); - }); - self.capaIdentities.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'CapaIdentities': bValue ? '1' : '0' + this.theme.subscribe((value) => { + changeTheme(value, this.themeTrigger); + Remote.saveAdminConfig(f3, { + 'Theme': trim(value) + }); }); - }); - self.capaTemplates.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'CapaTemplates': bValue ? '1' : '0' + this.capaAdditionalAccounts.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaAdditionalAccounts': boolToAjax(value) + }); }); - }); - self.capaGravatar.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'CapaGravatar': bValue ? '1' : '0' + this.capaIdentities.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaIdentities': boolToAjax(value) + }); }); - }); - self.capaAttachmentThumbnails.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'CapaAttachmentThumbnails': bValue ? '1' : '0' + this.capaTemplates.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaTemplates': boolToAjax(value) + }); }); - }); - self.capaThemes.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'CapaThemes': bValue ? '1' : '0' + this.capaGravatar.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaGravatar': boolToAjax(value) + }); }); - }); - self.capaUserBackground.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'CapaUserBackground': bValue ? '1' : '0' + this.capaAttachmentThumbnails.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaAttachmentThumbnails': boolToAjax(value) + }); }); - }); - self.allowLanguagesOnSettings.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'AllowLanguagesOnSettings': bValue ? '1' : '0' + this.capaThemes.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaThemes': boolToAjax(value) + }); }); - }); - }, 50); -}; + this.capaUserBackground.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaUserBackground': boolToAjax(value) + }); + }); -GeneralAdminSettings.prototype.selectLanguage = function() -{ - require('Knoin/Knoin').showScreenPopup(require('View/Popup/Languages'), [ - this.language, this.languages(), LanguageStore.userLanguage() - ]); -}; + this.allowLanguagesOnSettings.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'AllowLanguagesOnSettings': boolToAjax(value) + }); + }); + }, Magics.Time50ms); + } -GeneralAdminSettings.prototype.selectLanguageAdmin = function() -{ - require('Knoin/Knoin').showScreenPopup(require('View/Popup/Languages'), [ - this.languageAdmin, this.languagesAdmin(), LanguageStore.userLanguageAdmin() - ]); -}; + selectLanguage() { + showScreenPopup(require('View/Popup/Languages'), [ + this.language, this.languages(), LanguageStore.userLanguage() + ]); + } -/** - * @returns {string} - */ -GeneralAdminSettings.prototype.phpInfoLink = function() -{ - return Links.phpInfo(); -}; + selectLanguageAdmin() { + showScreenPopup(require('View/Popup/Languages'), [ + this.languageAdmin, this.languagesAdmin(), LanguageStore.userLanguageAdmin() + ]); + } + + /** + * @returns {string} + */ + phpInfoLink() { + return phpInfo(); + } +} export {GeneralAdminSettings, GeneralAdminSettings as default}; diff --git a/dev/Settings/Admin/Login.jsx b/dev/Settings/Admin/Login.jsx index 621ac93a4..6a4028828 100644 --- a/dev/Settings/Admin/Login.jsx +++ b/dev/Settings/Admin/Login.jsx @@ -1,66 +1,55 @@ -var - _ = require('_'), - ko = require('ko'), +import _ from '_'; +import ko from 'ko'; - Enums = require('Common/Enums'), - Utils = require('Common/Utils'), +import {settingsSaveHelperSimpleFunction, boolToAjax, trim} from 'Common/Utils'; +import {settingsGet} from 'Storage/Settings'; - AppAdminStore = require('Stores/Admin/App'), +import AppAdminStore from 'Stores/Admin/App'; - Settings = require('Storage/Settings'); - -/** - * @constructor - */ -function LoginAdminSettings() +class LoginAdminSettings { - this.determineUserLanguage = AppAdminStore.determineUserLanguage; - this.determineUserDomain = AppAdminStore.determineUserDomain; + constructor() { + this.determineUserLanguage = AppAdminStore.determineUserLanguage; + this.determineUserDomain = AppAdminStore.determineUserDomain; - this.defaultDomain = ko.observable(Settings.settingsGet('LoginDefaultDomain')); + this.defaultDomain = ko.observable(settingsGet('LoginDefaultDomain')).idleTrigger(); + this.allowLanguagesOnLogin = AppAdminStore.allowLanguagesOnLogin; - this.allowLanguagesOnLogin = AppAdminStore.allowLanguagesOnLogin; - this.defaultDomainTrigger = ko.observable(Enums.SaveSettingsStep.Idle); + this.dummy = ko.observable(false); + } - this.dummy = ko.observable(false); + onBuild() { + _.delay(() => { + const + Remote = require('Remote/Admin/Ajax'), + f1 = settingsSaveHelperSimpleFunction(this.defaultDomain.trigger, this); + + this.determineUserLanguage.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'DetermineUserLanguage': boolToAjax(value) + }); + }); + + this.determineUserDomain.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'DetermineUserDomain': boolToAjax(value) + }); + }); + + this.allowLanguagesOnLogin.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'AllowLanguagesOnLogin': boolToAjax(value) + }); + }); + + this.defaultDomain.subscribe((value) => { + Remote.saveAdminConfig(f1, { + 'LoginDefaultDomain': trim(value) + }); + }); + }, 50); + } } -LoginAdminSettings.prototype.onBuild = function() -{ - var - self = this, - Remote = require('Remote/Admin/Ajax'); - - _.delay(function() { - - var f1 = Utils.settingsSaveHelperSimpleFunction(self.defaultDomainTrigger, self); - - self.determineUserLanguage.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'DetermineUserLanguage': bValue ? '1' : '0' - }); - }); - - self.determineUserDomain.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'DetermineUserDomain': bValue ? '1' : '0' - }); - }); - - self.allowLanguagesOnLogin.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'AllowLanguagesOnLogin': bValue ? '1' : '0' - }); - }); - - self.defaultDomain.subscribe(function(sValue) { - Remote.saveAdminConfig(f1, { - 'LoginDefaultDomain': Utils.trim(sValue) - }); - }); - - }, 50); -}; - export {LoginAdminSettings, LoginAdminSettings as default}; diff --git a/dev/Settings/Admin/Packages.jsx b/dev/Settings/Admin/Packages.jsx index f3dcef448..09f04c819 100644 --- a/dev/Settings/Admin/Packages.jsx +++ b/dev/Settings/Admin/Packages.jsx @@ -1,106 +1,88 @@ -var - window = require('window'), - _ = require('_'), - ko = require('ko'), +import window from 'window'; +import _ from '_'; +import ko from 'ko'; - Enums = require('Common/Enums'), - Translator = require('Common/Translator'), +import {StorageResultType, Notification} from 'Common/Enums'; +import {getNotification} from 'Common/Translator'; - PackageStore = require('Stores/Admin/Package'), - Remote = require('Remote/Admin/Ajax'); +import PackageStore from 'Stores/Admin/Package'; +import Remote from 'Remote/Admin/Ajax'; -/** - * @constructor - */ -function PackagesAdminSettings() +class PackagesAdminSettings { - this.packagesError = ko.observable(''); + constructor() { + this.packagesError = ko.observable(''); - this.packages = PackageStore.packages; - this.packagesReal = PackageStore.packagesReal; - this.packagesMainUpdatable = PackageStore.packagesMainUpdatable; + this.packages = PackageStore.packages; + this.packagesReal = PackageStore.packagesReal; + this.packagesMainUpdatable = PackageStore.packagesMainUpdatable; - this.packagesCurrent = this.packages.filter(function(item) { - return item && '' !== item.installed && !item.compare; - }); + this.packagesCurrent = this.packages.filter((item) => item && '' !== item.installed && !item.compare); + this.packagesAvailableForUpdate = this.packages.filter((item) => item && '' !== item.installed && !!item.compare); + this.packagesAvailableForInstallation = this.packages.filter((item) => item && '' === item.installed); - this.packagesAvailableForUpdate = this.packages.filter(function(item) { - return item && '' !== item.installed && !!item.compare; - }); + this.visibility = ko.computed(() => (PackageStore.packages.loading() ? 'visible' : 'hidden')); + } - this.packagesAvailableForInstallation = this.packages.filter(function(item) { - return item && '' === item.installed; - }); + onShow() { + this.packagesError(''); + } - this.visibility = ko.computed(function() { - return PackageStore.packages.loading() ? 'visible' : 'hidden'; - }, this); -} + onBuild() { + require('App/Admin').default.reloadPackagesList(); + } -PackagesAdminSettings.prototype.onShow = function() -{ - this.packagesError(''); -}; + requestHelper(packageToRequest, install) { + return (result, data) => { -PackagesAdminSettings.prototype.onBuild = function() -{ - require('App/Admin').default.reloadPackagesList(); -}; - -PackagesAdminSettings.prototype.requestHelper = function(oPackage, bInstall) -{ - var self = this; - return function(sResult, oData) { - - if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result) - { - if (oData && oData.ErrorCode) + if (StorageResultType.Success !== result || !data || !data.Result) { - self.packagesError(Translator.getNotification(oData.ErrorCode)); + if (data && data.ErrorCode) + { + this.packagesError(getNotification(data.ErrorCode)); + } + else + { + this.packagesError(getNotification( + install ? Notification.CantInstallPackage : Notification.CantDeletePackage)); + } + } + + _.each(this.packages(), (item) => { + if (item && packageToRequest && item.loading && item.loading() && packageToRequest.file === item.file) + { + packageToRequest.loading(false); + item.loading(false); + } + }); + + if (StorageResultType.Success === result && data && data.Result && data.Result.Reload) + { + window.location.reload(); } else { - self.packagesError(Translator.getNotification( - bInstall ? Enums.Notification.CantInstallPackage : Enums.Notification.CantDeletePackage)); + require('App/Admin').default.reloadPackagesList(); } - } - - _.each(self.packages(), function(item) { - if (item && oPackage && item.loading && item.loading() && oPackage.file === item.file) - { - oPackage.loading(false); - item.loading(false); - } - }); - - if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.Reload) - { - window.location.reload(); - } - else - { - require('App/Admin').default.reloadPackagesList(); - } - }; -}; - -PackagesAdminSettings.prototype.deletePackage = function(oPackage) -{ - if (oPackage) - { - oPackage.loading(true); - Remote.packageDelete(this.requestHelper(oPackage, false), oPackage); + }; } -}; -PackagesAdminSettings.prototype.installPackage = function(oPackage) -{ - if (oPackage) - { - oPackage.loading(true); - Remote.packageInstall(this.requestHelper(oPackage, true), oPackage); + deletePackage(packageToDelete) { + if (packageToDelete) + { + packageToDelete.loading(true); + Remote.packageDelete(this.requestHelper(packageToDelete, false), packageToDelete); + } } -}; + + installPackage(packageToInstall) { + if (packageToInstall) + { + packageToInstall.loading(true); + Remote.packageInstall(this.requestHelper(packageToInstall, true), packageToInstall); + } + } +} export {PackagesAdminSettings, PackagesAdminSettings as default}; diff --git a/dev/Settings/Admin/Plugins.jsx b/dev/Settings/Admin/Plugins.jsx index f9e81dbd1..5ea055526 100644 --- a/dev/Settings/Admin/Plugins.jsx +++ b/dev/Settings/Admin/Plugins.jsx @@ -1,109 +1,99 @@ -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 {getNotification} from 'Common/Translator'; +import {boolToAjax} from 'Common/Utils'; - Settings = require('Storage/Settings'), +import {settingsGet} from 'Storage/Settings'; +import {showScreenPopup} from 'Knoin/Knoin'; - AppStore = require('Stores/Admin/App'), - PluginStore = require('Stores/Admin/Plugin'), +import AppStore from 'Stores/Admin/App'; +import PluginStore from 'Stores/Admin/Plugin'; - Remote = require('Remote/Admin/Ajax'); +import Remote from 'Remote/Admin/Ajax'; -/** - * @constructor - */ -function PluginsAdminSettings() +class PluginsAdminSettings { - this.enabledPlugins = ko.observable(!!Settings.settingsGet('EnabledPlugins')); + constructor() { + this.enabledPlugins = ko.observable(!!settingsGet('EnabledPlugins')); - this.plugins = PluginStore.plugins; - this.pluginsError = PluginStore.plugins.error; + this.plugins = PluginStore.plugins; + this.pluginsError = PluginStore.plugins.error; - this.community = RL_COMMUNITY || AppStore.community(); + this.community = RL_COMMUNITY || AppStore.community(); - this.visibility = ko.computed(function() { - return PluginStore.plugins.loading() ? 'visible' : 'hidden'; - }, this); + this.visibility = ko.computed(() => (PluginStore.plugins.loading() ? 'visible' : 'hidden')); - this.onPluginLoadRequest = _.bind(this.onPluginLoadRequest, this); - this.onPluginDisableRequest = _.bind(this.onPluginDisableRequest, this); -} - -PluginsAdminSettings.prototype.disablePlugin = function(oPlugin) -{ - oPlugin.disabled(!oPlugin.disabled()); - Remote.pluginDisable(this.onPluginDisableRequest, oPlugin.name, oPlugin.disabled()); -}; - -PluginsAdminSettings.prototype.configurePlugin = function(oPlugin) -{ - Remote.plugin(this.onPluginLoadRequest, oPlugin.name); -}; - -PluginsAdminSettings.prototype.onBuild = function(oDom) -{ - var self = this; - - oDom - .on('click', '.e-item .configure-plugin-action', function() { - var oPlugin = ko.dataFor(this); - if (oPlugin) - { - self.configurePlugin(oPlugin); - } - }) - .on('click', '.e-item .disabled-plugin', function() { - var oPlugin = ko.dataFor(this); - if (oPlugin) - { - self.disablePlugin(oPlugin); - } - }); - - this.enabledPlugins.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'EnabledPlugins': bValue ? '1' : '0' - }); - }); -}; - -PluginsAdminSettings.prototype.onShow = function() -{ - PluginStore.plugins.error(''); - require('App/Admin').default.reloadPluginList(); -}; - -PluginsAdminSettings.prototype.onPluginLoadRequest = function(sResult, oData) -{ - if (Enums.StorageResultType.Success === sResult && oData && oData.Result) - { - require('Knoin/Knoin').showScreenPopup(require('View/Popup/Plugin'), [oData.Result]); + this.onPluginLoadRequest = _.bind(this.onPluginLoadRequest, this); + this.onPluginDisableRequest = _.bind(this.onPluginDisableRequest, this); } -}; -PluginsAdminSettings.prototype.onPluginDisableRequest = function(sResult, oData) -{ - if (Enums.StorageResultType.Success === sResult && oData) - { - if (!oData.Result && oData.ErrorCode) + disablePlugin(plugin) { + plugin.disabled(!plugin.disabled()); + Remote.pluginDisable(this.onPluginDisableRequest, plugin.name, plugin.disabled()); + } + + configurePlugin(plugin) { + Remote.plugin(this.onPluginLoadRequest, plugin.name); + } + + onBuild(oDom) { + const self = this; + oDom + .on('click', '.e-item .configure-plugin-action', function() { + const plugin = ko.dataFor(this); + if (plugin) + { + self.configurePlugin(plugin); + } + }) + .on('click', '.e-item .disabled-plugin', function() { + const plugin = ko.dataFor(this); + if (plugin) + { + self.disablePlugin(plugin); + } + }); + + this.enabledPlugins.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'EnabledPlugins': boolToAjax(value) + }); + }); + } + + onShow() { + PluginStore.plugins.error(''); + require('App/Admin').default.reloadPluginList(); + } + + onPluginLoadRequest(result, data) { + if (StorageResultType.Success === result && data && data.Result) { - if (Enums.Notification.UnsupportedPluginPackage === oData.ErrorCode && oData.ErrorMessage && '' !== oData.ErrorMessage) - { - PluginStore.plugins.error(oData.ErrorMessage); - } - else - { - PluginStore.plugins.error(Translator.getNotification(oData.ErrorCode)); - } + showScreenPopup(require('View/Popup/Plugin'), [data.Result]); } } - require('App/Admin').default.reloadPluginList(); -}; + onPluginDisableRequest(result, data) { + if (StorageResultType.Success === result && data) + { + if (!data.Result && data.ErrorCode) + { + if (Notification.UnsupportedPluginPackage === data.ErrorCode && data.ErrorMessage && '' !== data.ErrorMessage) + { + PluginStore.plugins.error(data.ErrorMessage); + } + else + { + PluginStore.plugins.error(getNotification(data.ErrorCode)); + } + } + } + + require('App/Admin').default.reloadPluginList(); + } +} export {PluginsAdminSettings, PluginsAdminSettings as default}; diff --git a/dev/Settings/Admin/Security.jsx b/dev/Settings/Admin/Security.jsx index bed0fb663..bd8df55c6 100644 --- a/dev/Settings/Admin/Security.jsx +++ b/dev/Settings/Admin/Security.jsx @@ -1,182 +1,174 @@ -var - _ = require('_'), - ko = require('ko'), +import _ from '_'; +import ko from 'ko'; - Enums = require('Common/Enums'), - Utils = require('Common/Utils'), - Links = require('Common/Links'), +import {createCommand, trim, boolToAjax} from 'Common/Utils'; +import {phpInfo} from 'Common/Links'; +import {StorageResultType} from 'Common/Enums'; - AppAdminStore = require('Stores/Admin/App'), - CapaAdminStore = require('Stores/Admin/Capa'), +import {settingsGet} from 'Storage/Settings'; - Settings = require('Storage/Settings'), - Remote = require('Remote/Admin/Ajax'); +import AppAdminStore from 'Stores/Admin/App'; +import CapaAdminStore from 'Stores/Admin/Capa'; -/** - * @constructor - */ -function SecurityAdminSettings() +import Remote from 'Remote/Admin/Ajax'; + +class SecurityAdminSettings { - this.useLocalProxyForExternalImages = AppAdminStore.useLocalProxyForExternalImages; + constructor() { + this.useLocalProxyForExternalImages = AppAdminStore.useLocalProxyForExternalImages; - this.weakPassword = AppAdminStore.weakPassword; + this.weakPassword = AppAdminStore.weakPassword; - this.capaOpenPGP = CapaAdminStore.openPGP; + this.capaOpenPGP = CapaAdminStore.openPGP; - this.capaTwoFactorAuth = CapaAdminStore.twoFactorAuth; - this.capaTwoFactorAuthForce = CapaAdminStore.twoFactorAuthForce; + this.capaTwoFactorAuth = CapaAdminStore.twoFactorAuth; + this.capaTwoFactorAuthForce = CapaAdminStore.twoFactorAuthForce; - this.capaTwoFactorAuth.subscribe(function(bValue) { - if (!bValue) - { - this.capaTwoFactorAuthForce(false); - } - }, this); - - this.verifySslCertificate = ko.observable(!!Settings.settingsGet('VerifySslCertificate')); - this.allowSelfSigned = ko.observable(!!Settings.settingsGet('AllowSelfSigned')); - - this.verifySslCertificate.subscribe(function(bValue) { - if (!bValue) - { - this.allowSelfSigned(true); - } - }, this); - - this.adminLogin = ko.observable(Settings.settingsGet('AdminLogin')); - this.adminLoginError = ko.observable(false); - this.adminPassword = ko.observable(''); - this.adminPasswordNew = ko.observable(''); - this.adminPasswordNew2 = ko.observable(''); - this.adminPasswordNewError = ko.observable(false); - - this.adminPasswordUpdateError = ko.observable(false); - this.adminPasswordUpdateSuccess = ko.observable(false); - - this.adminPassword.subscribe(function() { - this.adminPasswordUpdateError(false); - this.adminPasswordUpdateSuccess(false); - }, this); - - this.adminLogin.subscribe(function() { - this.adminLoginError(false); - }, this); - - this.adminPasswordNew.subscribe(function() { - this.adminPasswordUpdateError(false); - this.adminPasswordUpdateSuccess(false); - this.adminPasswordNewError(false); - }, this); - - this.adminPasswordNew2.subscribe(function() { - this.adminPasswordUpdateError(false); - this.adminPasswordUpdateSuccess(false); - this.adminPasswordNewError(false); - }, this); - - this.saveNewAdminPasswordCommand = Utils.createCommand(this, function() { - - if ('' === Utils.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() + this.capaTwoFactorAuth.subscribe((value) => { + if (!value) + { + this.capaTwoFactorAuthForce(false); + } }); - return true; + this.verifySslCertificate = ko.observable(!!settingsGet('VerifySslCertificate')); + this.allowSelfSigned = ko.observable(!!settingsGet('AllowSelfSigned')); - }, function() { - return '' !== Utils.trim(this.adminLogin()) && '' !== this.adminPassword(); - }); + this.verifySslCertificate.subscribe((value) => { + if (!value) + { + this.allowSelfSigned(true); + } + }); - this.onNewAdminPasswordResponse = _.bind(this.onNewAdminPasswordResponse, this); -} + this.adminLogin = ko.observable(settingsGet('AdminLogin')); + this.adminLoginError = ko.observable(false); + this.adminPassword = ko.observable(''); + this.adminPasswordNew = ko.observable(''); + this.adminPasswordNew2 = ko.observable(''); + this.adminPasswordNewError = ko.observable(false); -SecurityAdminSettings.prototype.onNewAdminPasswordResponse = function(sResult, oData) -{ - if (Enums.StorageResultType.Success === sResult && oData && oData.Result) - { + this.adminPasswordUpdateError = ko.observable(false); + this.adminPasswordUpdateSuccess = ko.observable(false); + + this.adminPassword.subscribe(() => { + this.adminPasswordUpdateError(false); + this.adminPasswordUpdateSuccess(false); + }); + + this.adminLogin.subscribe(() => { + this.adminLoginError(false); + }); + + this.adminPasswordNew.subscribe(() => { + this.adminPasswordUpdateError(false); + this.adminPasswordUpdateSuccess(false); + this.adminPasswordNewError(false); + }); + + this.adminPasswordNew2.subscribe(() => { + this.adminPasswordUpdateError(false); + this.adminPasswordUpdateSuccess(false); + this.adminPasswordNewError(false); + }); + + this.saveNewAdminPasswordCommand = createCommand(this, () => { + + 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); + } + + onNewAdminPasswordResponse(result, data) { + if (StorageResultType.Success === result && data && data.Result) + { + this.adminPassword(''); + this.adminPasswordNew(''); + this.adminPasswordNew2(''); + + this.adminPasswordUpdateSuccess(true); + + this.weakPassword(!!data.Result.Weak); + } + else + { + this.adminPasswordUpdateError(true); + } + } + + onBuild() { + this.capaOpenPGP.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaOpenPGP': boolToAjax(value) + }); + }); + + this.capaTwoFactorAuth.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaTwoFactorAuth': boolToAjax(value) + }); + }); + + this.capaTwoFactorAuthForce.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'CapaTwoFactorAuthForce': boolToAjax(value) + }); + }); + + this.useLocalProxyForExternalImages.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'UseLocalProxyForExternalImages': boolToAjax(value) + }); + }); + + this.verifySslCertificate.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'VerifySslCertificate': boolToAjax(value) + }); + }); + + this.allowSelfSigned.subscribe((value) => { + Remote.saveAdminConfig(null, { + 'AllowSelfSigned': boolToAjax(value) + }); + }); + } + + onHide() { this.adminPassword(''); this.adminPasswordNew(''); this.adminPasswordNew2(''); - - this.adminPasswordUpdateSuccess(true); - - this.weakPassword(!!oData.Result.Weak); } - else - { - this.adminPasswordUpdateError(true); + + /** + * @returns {string} + */ + phpInfoLink() { + return phpInfo(); } -}; - -SecurityAdminSettings.prototype.onBuild = function() -{ - this.capaOpenPGP.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'CapaOpenPGP': bValue ? '1' : '0' - }); - }); - - this.capaTwoFactorAuth.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'CapaTwoFactorAuth': bValue ? '1' : '0' - }); - }); - - this.capaTwoFactorAuthForce.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'CapaTwoFactorAuthForce': bValue ? '1' : '0' - }); - }); - - this.useLocalProxyForExternalImages.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'UseLocalProxyForExternalImages': bValue ? '1' : '0' - }); - }); - - this.verifySslCertificate.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'VerifySslCertificate': bValue ? '1' : '0' - }); - }); - - this.allowSelfSigned.subscribe(function(bValue) { - Remote.saveAdminConfig(null, { - 'AllowSelfSigned': bValue ? '1' : '0' - }); - }); -}; - -SecurityAdminSettings.prototype.onHide = function() -{ - this.adminPassword(''); - this.adminPasswordNew(''); - this.adminPasswordNew2(''); -}; - -/** - * @returns {string} - */ -SecurityAdminSettings.prototype.phpInfoLink = function() -{ - return Links.phpInfo(); -}; +} export {SecurityAdminSettings, SecurityAdminSettings as default}; diff --git a/dev/Settings/Admin/Social.jsx b/dev/Settings/Admin/Social.jsx index dc6793cb8..7c9826050 100644 --- a/dev/Settings/Admin/Social.jsx +++ b/dev/Settings/Admin/Social.jsx @@ -1,174 +1,109 @@ -var - _ = require('_'), - ko = require('ko'), +import _ from '_'; +import ko from 'ko'; - Enums = require('Common/Enums'), - Utils = require('Common/Utils'); +import {SaveSettingsStep, Magics} from 'Common/Enums'; +import {settingsSaveHelperSimpleFunction, trim, boolToAjax} from 'Common/Utils'; -/** - * @constructor - */ -function SocialAdminSettings() +import SocialStore from 'Stores/Social'; + +class SocialAdminSettings { - var 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.googleEnableRequireClientSettings = SocialStore.google.require.clientSettings; + this.googleEnableRequireApiKey = SocialStore.google.require.apiKeySettings; - this.googleEnableRequireClientSettings = SocialStore.google.require.clientSettings; - this.googleEnableRequireApiKey = SocialStore.google.require.apiKeySettings; + this.googleClientID = SocialStore.google.clientID; + this.googleClientSecret = SocialStore.google.clientSecret; + this.googleApiKey = SocialStore.google.apiKey; - this.googleClientID = SocialStore.google.clientID; - this.googleClientSecret = SocialStore.google.clientSecret; - this.googleApiKey = SocialStore.google.apiKey; + this.googleTrigger1 = ko.observable(SaveSettingsStep.Idle); + this.googleTrigger2 = ko.observable(SaveSettingsStep.Idle); + this.googleTrigger3 = ko.observable(SaveSettingsStep.Idle); - this.googleTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle); - this.googleTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle); - this.googleTrigger3 = ko.observable(Enums.SaveSettingsStep.Idle); + this.facebookSupported = SocialStore.facebook.supported; + this.facebookEnable = SocialStore.facebook.enabled; + this.facebookAppID = SocialStore.facebook.appID; + this.facebookAppSecret = SocialStore.facebook.appSecret; - this.facebookSupported = SocialStore.facebook.supported; - this.facebookEnable = SocialStore.facebook.enabled; - this.facebookAppID = SocialStore.facebook.appID; - this.facebookAppSecret = SocialStore.facebook.appSecret; + this.facebookTrigger1 = ko.observable(SaveSettingsStep.Idle); + this.facebookTrigger2 = ko.observable(SaveSettingsStep.Idle); - this.facebookTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle); - this.facebookTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle); + this.twitterEnable = SocialStore.twitter.enabled; + this.twitterConsumerKey = SocialStore.twitter.consumerKey; + this.twitterConsumerSecret = SocialStore.twitter.consumerSecret; - this.twitterEnable = SocialStore.twitter.enabled; - this.twitterConsumerKey = SocialStore.twitter.consumerKey; - this.twitterConsumerSecret = SocialStore.twitter.consumerSecret; + this.twitterTrigger1 = ko.observable(SaveSettingsStep.Idle); + this.twitterTrigger2 = ko.observable(SaveSettingsStep.Idle); - this.twitterTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle); - this.twitterTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle); + this.dropboxEnable = SocialStore.dropbox.enabled; + this.dropboxApiKey = SocialStore.dropbox.apiKey; - this.dropboxEnable = SocialStore.dropbox.enabled; - this.dropboxApiKey = SocialStore.dropbox.apiKey; + this.dropboxTrigger1 = ko.observable(SaveSettingsStep.Idle); + } - this.dropboxTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle); + onBuild() { + _.delay(() => { + const + Remote = require('Remote/Admin/Ajax'), + f1 = settingsSaveHelperSimpleFunction(this.facebookTrigger1, this), + f2 = settingsSaveHelperSimpleFunction(this.facebookTrigger2, this), + f3 = settingsSaveHelperSimpleFunction(this.twitterTrigger1, this), + f4 = settingsSaveHelperSimpleFunction(this.twitterTrigger2, this), + f5 = settingsSaveHelperSimpleFunction(this.googleTrigger1, this), + f6 = settingsSaveHelperSimpleFunction(this.googleTrigger2, this), + f7 = settingsSaveHelperSimpleFunction(this.googleTrigger3, this), + f8 = settingsSaveHelperSimpleFunction(this.dropboxTrigger1, this); + + this.facebookEnable.subscribe((value) => { + if (this.facebookSupported()) + { + Remote.saveAdminConfig(null, { + 'FacebookEnable': boolToAjax(value) + }); + } + }); + + this.facebookAppID.subscribe((value) => { + if (this.facebookSupported()) + { + Remote.saveAdminConfig(f1, { + 'FacebookAppID': trim(value) + }); + } + }); + + this.facebookAppSecret.subscribe((value) => { + if (this.facebookSupported()) + { + Remote.saveAdminConfig(f2, { + 'FacebookAppSecret': trim(value) + }); + } + }); + + this.twitterEnable.subscribe(Remote.saveAdminConfigHelper('TwitterEnable', boolToAjax)); + this.twitterConsumerKey.subscribe(Remote.saveAdminConfigHelper('TwitterConsumerKey', trim, f3)); + this.twitterConsumerSecret.subscribe(Remote.saveAdminConfigHelper('TwitterConsumerSecret', trim, f4)); + + this.googleEnable.subscribe(Remote.saveAdminConfigHelper('GoogleEnable', boolToAjax)); + this.googleEnableAuth.subscribe(Remote.saveAdminConfigHelper('GoogleEnableAuth', boolToAjax)); + this.googleEnableDrive.subscribe(Remote.saveAdminConfigHelper('GoogleEnableDrive', boolToAjax)); + this.googleEnablePreview.subscribe(Remote.saveAdminConfigHelper('GoogleEnablePreview', boolToAjax)); + this.googleClientID.subscribe(Remote.saveAdminConfigHelper('GoogleClientID', trim, f5)); + this.googleClientSecret.subscribe(Remote.saveAdminConfigHelper('GoogleClientSecret', trim, f6)); + this.googleApiKey.subscribe(Remote.saveAdminConfigHelper('GoogleApiKey', trim, f7)); + + this.dropboxEnable.subscribe(Remote.saveAdminConfigHelper('DropboxEnable', boolToAjax)); + this.dropboxApiKey.subscribe(Remote.saveAdminConfigHelper('DropboxApiKey', trim, f8)); + }, Magics.Time50ms); + } } -SocialAdminSettings.prototype.onBuild = function() -{ - var - self = this, - Remote = require('Remote/Admin/Ajax'); - - _.delay(function() { - - var - f1 = Utils.settingsSaveHelperSimpleFunction(self.facebookTrigger1, self), - f2 = Utils.settingsSaveHelperSimpleFunction(self.facebookTrigger2, self), - f3 = Utils.settingsSaveHelperSimpleFunction(self.twitterTrigger1, self), - f4 = Utils.settingsSaveHelperSimpleFunction(self.twitterTrigger2, self), - f5 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger1, self), - f6 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger2, self), - f7 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger3, self), - f8 = Utils.settingsSaveHelperSimpleFunction(self.dropboxTrigger1, self); - - self.facebookEnable.subscribe(function(bValue) { - if (self.facebookSupported()) - { - Remote.saveAdminConfig(Utils.noop, { - 'FacebookEnable': bValue ? '1' : '0' - }); - } - }); - - self.facebookAppID.subscribe(function(sValue) { - if (self.facebookSupported()) - { - Remote.saveAdminConfig(f1, { - 'FacebookAppID': Utils.trim(sValue) - }); - } - }); - - self.facebookAppSecret.subscribe(function(sValue) { - if (self.facebookSupported()) - { - Remote.saveAdminConfig(f2, { - 'FacebookAppSecret': Utils.trim(sValue) - }); - } - }); - - self.twitterEnable.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'TwitterEnable': bValue ? '1' : '0' - }); - }); - - self.twitterConsumerKey.subscribe(function(sValue) { - Remote.saveAdminConfig(f3, { - 'TwitterConsumerKey': Utils.trim(sValue) - }); - }); - - self.twitterConsumerSecret.subscribe(function(sValue) { - Remote.saveAdminConfig(f4, { - 'TwitterConsumerSecret': Utils.trim(sValue) - }); - }); - - self.googleEnable.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'GoogleEnable': bValue ? '1' : '0' - }); - }); - - self.googleEnableAuth.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'GoogleEnableAuth': bValue ? '1' : '0' - }); - }); - - self.googleEnableDrive.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'GoogleEnableDrive': bValue ? '1' : '0' - }); - }); - - self.googleEnablePreview.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'GoogleEnablePreview': bValue ? '1' : '0' - }); - }); - - self.googleClientID.subscribe(function(sValue) { - Remote.saveAdminConfig(f5, { - 'GoogleClientID': Utils.trim(sValue) - }); - }); - - self.googleClientSecret.subscribe(function(sValue) { - Remote.saveAdminConfig(f6, { - 'GoogleClientSecret': Utils.trim(sValue) - }); - }); - - self.googleApiKey.subscribe(function(sValue) { - Remote.saveAdminConfig(f7, { - 'GoogleApiKey': Utils.trim(sValue) - }); - }); - - self.dropboxEnable.subscribe(function(bValue) { - Remote.saveAdminConfig(Utils.noop, { - 'DropboxEnable': bValue ? '1' : '0' - }); - }); - - self.dropboxApiKey.subscribe(function(sValue) { - Remote.saveAdminConfig(f8, { - 'DropboxApiKey': Utils.trim(sValue) - }); - }); - - }, 50); -}; - export {SocialAdminSettings, SocialAdminSettings as default}; diff --git a/dev/Settings/User/Accounts.jsx b/dev/Settings/User/Accounts.jsx index b6545fbbb..1eefbb25c 100644 --- a/dev/Settings/User/Accounts.jsx +++ b/dev/Settings/User/Accounts.jsx @@ -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}; diff --git a/dev/Settings/User/ChangePassword.jsx b/dev/Settings/User/ChangePassword.jsx index 04d4a4dc5..74c02d912 100644 --- a/dev/Settings/User/ChangePassword.jsx +++ b/dev/Settings/User/ChangePassword.jsx @@ -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}; diff --git a/dev/Settings/User/Contacts.jsx b/dev/Settings/User/Contacts.jsx index 50443e092..5cce76aab 100644 --- a/dev/Settings/User/Contacts.jsx +++ b/dev/Settings/User/Contacts.jsx @@ -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}; diff --git a/dev/Settings/User/Filters.jsx b/dev/Settings/User/Filters.jsx index ddcf86db9..bab1babff 100644 --- a/dev/Settings/User/Filters.jsx +++ b/dev/Settings/User/Filters.jsx @@ -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}; diff --git a/dev/Settings/User/Folders.jsx b/dev/Settings/User/Folders.jsx index 8a95a7481..edb9e3da6 100644 --- a/dev/Settings/User/Folders.jsx +++ b/dev/Settings/User/Folders.jsx @@ -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}; diff --git a/dev/Settings/User/General.jsx b/dev/Settings/User/General.jsx index fa4977833..8451ed7ea 100644 --- a/dev/Settings/User/General.jsx +++ b/dev/Settings/User/General.jsx @@ -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}; diff --git a/dev/Settings/User/OpenPgp.jsx b/dev/Settings/User/OpenPgp.jsx index b5eee15a7..c3387af9f 100644 --- a/dev/Settings/User/OpenPgp.jsx +++ b/dev/Settings/User/OpenPgp.jsx @@ -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}; diff --git a/dev/Settings/User/Security.jsx b/dev/Settings/User/Security.jsx index 90c619a9e..9d8c95e93 100644 --- a/dev/Settings/User/Security.jsx +++ b/dev/Settings/User/Security.jsx @@ -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}; diff --git a/dev/Settings/User/Social.jsx b/dev/Settings/User/Social.jsx index 8b4252f48..38b1487fc 100644 --- a/dev/Settings/User/Social.jsx +++ b/dev/Settings/User/Social.jsx @@ -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}; diff --git a/dev/Settings/User/Templates.jsx b/dev/Settings/User/Templates.jsx index 15763e925..6f3306d22 100644 --- a/dev/Settings/User/Templates.jsx +++ b/dev/Settings/User/Templates.jsx @@ -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}; diff --git a/dev/Settings/User/Themes.jsx b/dev/Settings/User/Themes.jsx index ddb513ca6..0b65c2c54 100644 --- a/dev/Settings/User/Themes.jsx +++ b/dev/Settings/User/Themes.jsx @@ -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}; diff --git a/dev/Stores/AbstractApp.jsx b/dev/Stores/AbstractApp.jsx index 753355b08..65c43d7f2 100644 --- a/dev/Stores/AbstractApp.jsx +++ b/dev/Stores/AbstractApp.jsx @@ -5,8 +5,7 @@ import * as Settings from 'Storage/Settings'; class AbstractAppStore { - constructor() - { + constructor() { this.allowLanguagesOnSettings = ko.observable(true); this.allowLanguagesOnLogin = ko.observable(true); diff --git a/dev/Stores/Admin/App.jsx b/dev/Stores/Admin/App.jsx index aa94cdc34..02f11cfdd 100644 --- a/dev/Stores/Admin/App.jsx +++ b/dev/Stores/Admin/App.jsx @@ -5,8 +5,7 @@ import {AbstractAppStore} from 'Stores/AbstractApp'; class AppAdminStore extends AbstractAppStore { - constructor() - { + constructor() { super(); this.determineUserLanguage = ko.observable(false); diff --git a/dev/Stores/User/App.jsx b/dev/Stores/User/App.jsx index 291c48045..e0e268b57 100644 --- a/dev/Stores/User/App.jsx +++ b/dev/Stores/User/App.jsx @@ -9,8 +9,7 @@ import {AbstractAppStore} from 'Stores/AbstractApp'; class AppUserStore extends AbstractAppStore { - constructor() - { + constructor() { super(); this.currentAudio = ko.observable(''); diff --git a/dev/Stores/User/Identity.jsx b/dev/Stores/User/Identity.jsx index b0d6cf4de..9afae5936 100644 --- a/dev/Stores/User/Identity.jsx +++ b/dev/Stores/User/Identity.jsx @@ -4,8 +4,7 @@ import ko from 'ko'; class IdentityUserStore { - constructor() - { + constructor() { this.identities = ko.observableArray([]); this.identities.loading = ko.observable(false).extend({throttle: 100}); diff --git a/dev/Stores/User/Pgp.js b/dev/Stores/User/Pgp.js index 6058f4af3..e74f2471b 100644 --- a/dev/Stores/User/Pgp.js +++ b/dev/Stores/User/Pgp.js @@ -75,7 +75,10 @@ PgpUserStore.prototype.findPublicKeysBySigningKeyIds = function(aSigningKeyIds) PgpUserStore.prototype.findPrivateKeysByEncryptionKeyIds = function(aEncryptionKeyIds, aRecipients, bReturnWrapKeys) { - var self = this, aResult = []; + var + self = this, + aResult = []; + aResult = Utils.isArray(aEncryptionKeyIds) ? _.compact(_.flatten(_.map(aEncryptionKeyIds, function(oId) { var oKey = oId && oId.toHex ? self.findPrivateKeyByHex(oId.toHex()) : null; return oKey ? (bReturnWrapKeys ? [oKey] : oKey.getNativeKeys()) : [null]; @@ -184,7 +187,10 @@ PgpUserStore.prototype.findSelfPrivateKey = function(sPassword) PgpUserStore.prototype.decryptMessage = function(oMessage, aRecipients, fCallback) { - var self = this, aPrivateKeys = []; + var + self = this, + aPrivateKeys = []; + if (oMessage && oMessage.getEncryptionKeyIds) { aPrivateKeys = this.findPrivateKeysByEncryptionKeyIds(oMessage.getEncryptionKeyIds(), aRecipients, true); @@ -254,7 +260,12 @@ PgpUserStore.prototype.findKeyExternal = function(sEmail, fCallback) PgpUserStore.prototype.verifyMessage = function(oMessage, fCallback) { - var oValid = null, aResult = [], aPublicKeys = [], aSigningKeyIds = []; + var + oValid = null, + aResult = [], + aPublicKeys = [], + aSigningKeyIds = []; + if (oMessage && oMessage.getSigningKeyIds) { aSigningKeyIds = oMessage.getSigningKeyIds(); @@ -323,8 +334,9 @@ PgpUserStore.prototype.controlsHelper = function(mDom, oVerControl, bSuccess, sT PgpUserStore.domControlEncryptedClickHelper = function(store, mDom, sArmoredMessage, aRecipients) { return function() { - - var oMessage = null, $this = $(this); + var + oMessage = null, + $this = $(this); if ($this.hasClass('success')) { @@ -393,7 +405,10 @@ PgpUserStore.domControlSignedClickHelper = function(store, mDom, sArmoredMessage { return function() { - var oMessage = null, $this = $(this); + var + oMessage = null, + $this = $(this); + if ($this.hasClass('success') || $this.hasClass('error')) { return false; diff --git a/dev/Styles/_social.css b/dev/Styles/_social.css index ab6361549..1dce84e33 100644 --- a/dev/Styles/_social.css +++ b/dev/Styles/_social.css @@ -3,6 +3,13 @@ transform: rotate(1turn); } } + +html, body { + padding: 0; + margin: 0; + overflow: hidden; +} + .social-icon-wrp { position: absolute; top: 0; diff --git a/dev/View/Admin/Settings/Menu.js b/dev/View/Admin/Settings/Menu.js index f78eb5995..1b3d3a160 100644 --- a/dev/View/Admin/Settings/Menu.js +++ b/dev/View/Admin/Settings/Menu.js @@ -1,6 +1,8 @@ var _ = require('_'), + $ = require('$'), + key = require('key'), Globals = require('Common/Globals'), Enums = require('Common/Enums'), diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 491174b7d..12474eb8a 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -4,6 +4,7 @@ var _ = require('_'), $ = require('$'), ko = require('ko'), + key = require('key'), JSON = require('JSON'), Jua = require('Jua'), @@ -928,7 +929,10 @@ ComposePopupView.prototype.setSignatureFromIdentity = function(oIdentity) { var self = this; this.editor(function(oEditor) { - var bHtml = false, sSignature = oIdentity.signature(); + var + bHtml = false, + sSignature = oIdentity.signature(); + if ('' !== sSignature) { if (':HTML:' === sSignature.substr(0, 6)) diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 020013542..be6e77ed5 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -6,6 +6,8 @@ var ko = require('ko'), key = require('key'), + Jua = require('Jua'), + Enums = require('Common/Enums'), Consts = require('Common/Consts'), Globals = require('Common/Globals'), diff --git a/dev/View/Popup/NewOpenPgpKey.js b/dev/View/Popup/NewOpenPgpKey.js index bb8bc9257..46ab1c875 100644 --- a/dev/View/Popup/NewOpenPgpKey.js +++ b/dev/View/Popup/NewOpenPgpKey.js @@ -28,6 +28,7 @@ function NewOpenPgpKeyPopupView() this.keyBitLength = ko.observable(Enums.Magics.BitLength2048); this.submitRequest = ko.observable(false); + this.submitError = ko.observable(''); this.email.subscribe(function() { this.email.error(false); @@ -53,6 +54,7 @@ function NewOpenPgpKeyPopupView() } this.submitRequest(true); + this.submitError(''); _.delay(function() { @@ -81,14 +83,15 @@ function NewOpenPgpKeyPopupView() Utils.delegateRun(self, 'cancelCommand'); } - }).then(null, function() { + }).then(null, function(e) { self.submitRequest(false); + self.showError(e); }); } catch (e) { - Utils.log(e); self.submitRequest(false); + self.showError(e); } }, Enums.Magics.Time100ms); @@ -102,6 +105,15 @@ function NewOpenPgpKeyPopupView() kn.extendAsViewModel(['View/Popup/NewOpenPgpKey', 'PopupsNewOpenPgpKeyViewModel'], NewOpenPgpKeyPopupView); _.extend(NewOpenPgpKeyPopupView.prototype, AbstractView.prototype); +NewOpenPgpKeyPopupView.prototype.showError = function(e) +{ + Utils.log(e); + if (e && e.message) + { + this.submitError(e.message); + } +}; + NewOpenPgpKeyPopupView.prototype.clearPopup = function() { this.name(''); @@ -110,6 +122,8 @@ NewOpenPgpKeyPopupView.prototype.clearPopup = function() this.email(''); this.email.error(false); this.keyBitLength(Enums.Magics.BitLength2048); + + this.submitError(''); }; NewOpenPgpKeyPopupView.prototype.onShow = function() diff --git a/dev/View/Popup/Plugin.js b/dev/View/Popup/Plugin.js index d031c0f64..8764c7dc3 100644 --- a/dev/View/Popup/Plugin.js +++ b/dev/View/Popup/Plugin.js @@ -60,15 +60,14 @@ function PluginPopupView() list.Name = this.name(); _.each(this.configures(), function(oItem) { - var value = oItem.value(); + if (false === value || true === value) { value = value ? '1' : '0'; } list['_' + oItem.Name] = value; - }, this); this.saveError(''); @@ -119,6 +118,7 @@ PluginPopupView.prototype.onShow = function(oPlugin) this.readme(oPlugin.Readme); var aConfig = oPlugin.Config; + if (Utils.isNonEmptyArray(aConfig)) { this.configures(_.map(aConfig, function(aItem) { @@ -160,6 +160,7 @@ PluginPopupView.prototype.onBuild = function() { this.tryToClosePopup(); } + return false; }, this)); }; diff --git a/dev/View/Popup/Template.js b/dev/View/Popup/Template.js index 796aa338a..90f66b95b 100644 --- a/dev/View/Popup/Template.js +++ b/dev/View/Popup/Template.js @@ -124,9 +124,10 @@ TemplatePopupView.prototype.populateBodyFromEditor = function() TemplatePopupView.prototype.editorSetBody = function(sBody) { + var self = this; + if (!this.editor && this.signatureDom()) { - var self = this; this.editor = new HtmlEditor(self.signatureDom(), function() { self.populateBodyFromEditor(); }, function() { diff --git a/dev/View/User/Login.js b/dev/View/User/Login.js index af60e8e42..e187b7c52 100644 --- a/dev/View/User/Login.js +++ b/dev/View/User/Login.js @@ -135,7 +135,6 @@ function LoginUserView() }, this); this.submitCommand = Utils.createCommand(this, function() { - Utils.triggerAutocompleteInputChange(); this.emailError(false); @@ -276,7 +275,6 @@ function LoginUserView() } return true; - }, function() { return !this.submitRequest(); }); @@ -284,12 +282,9 @@ function LoginUserView() this.facebookLoginEnabled = ko.observable(false); this.facebookCommand = Utils.createCommand(this, function() { - window.open(Links.socialFacebook(), 'Facebook', - 'left=200,top=100,width=650,height=450,menubar=no,status=no,resizable=yes,scrollbars=yes'); - + 'left=200,top=100,width=500,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes'); return true; - }, function() { return !this.submitRequest() && this.facebookLoginEnabled(); }); @@ -298,23 +293,17 @@ function LoginUserView() this.googleFastLoginEnabled = ko.observable(false); this.googleCommand = Utils.createCommand(this, function() { - window.open(Links.socialGoogle(), 'Google', - 'left=200,top=100,width=650,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes'); - + 'left=200,top=100,width=550,height=550,menubar=no,status=no,resizable=yes,scrollbars=yes'); return true; - }, function() { return !this.submitRequest() && this.googleLoginEnabled(); }); this.googleFastCommand = Utils.createCommand(this, function() { - window.open(Links.socialGoogle(true), 'Google', - 'left=200,top=100,width=650,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes'); - + 'left=200,top=100,width=550,height=550,menubar=no,status=no,resizable=yes,scrollbars=yes'); return true; - }, function() { return !this.submitRequest() && this.googleFastLoginEnabled(); }); @@ -322,18 +311,14 @@ function LoginUserView() this.twitterLoginEnabled = ko.observable(false); this.twitterCommand = Utils.createCommand(this, function() { - window.open(Links.socialTwitter(), 'Twitter', - 'left=200,top=100,width=650,height=450,menubar=no,status=no,resizable=yes,scrollbars=yes'); - + 'left=200,top=100,width=500,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes'); return true; - }, function() { return !this.submitRequest() && this.twitterLoginEnabled(); }); this.socialLoginEnabled = ko.computed(function() { - var bF = this.facebookLoginEnabled(), bG = this.googleLoginEnabled(), diff --git a/dev/View/User/MailBox/FolderList.js b/dev/View/User/MailBox/FolderList.js index 851c355d3..26668db2b 100644 --- a/dev/View/User/MailBox/FolderList.js +++ b/dev/View/User/MailBox/FolderList.js @@ -182,7 +182,11 @@ FolderListMailBoxUserView.prototype.onBuild = function(oDom) }); key('space', Enums.KeyState.FolderList, function() { - var bCollapsed = true, oFolder = null, $items = $('.b-folders .e-item .e-link:not(.hidden).focused', oDom); + var + bCollapsed = true, + oFolder = null, + $items = $('.b-folders .e-item .e-link:not(.hidden).focused', oDom); + if ($items.length && $items[0]) { oFolder = ko.dataFor($items[0]); diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index 2b909b0c1..87ee7fa20 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -1068,7 +1068,10 @@ MessageViewMailBoxUserView.prototype.getAttachmentsHashes = function() MessageViewMailBoxUserView.prototype.downloadAsZip = function() { - var self = this, aHashes = this.getAttachmentsHashes(); + var + self = this, + aHashes = this.getAttachmentsHashes(); + if (0 < aHashes.length) { Promises.attachmentsActions('Zip', aHashes, this.downloadAsZipLoading).then(function(oResult) { @@ -1094,7 +1097,10 @@ MessageViewMailBoxUserView.prototype.downloadAsZip = function() MessageViewMailBoxUserView.prototype.saveToOwnCloud = function() { - var self = this, aHashes = this.getAttachmentsHashes(); + var + self = this, + aHashes = this.getAttachmentsHashes(); + if (0 < aHashes.length) { Promises.attachmentsActions('OwnCloud', aHashes, this.saveToOwnCloudLoading).then(function(oResult) { @@ -1118,7 +1124,11 @@ MessageViewMailBoxUserView.prototype.saveToOwnCloud = function() MessageViewMailBoxUserView.prototype.saveToDropbox = function() { - var self = this, aFiles = [], aHashes = this.getAttachmentsHashes(); + var + self = this, + aFiles = [], + aHashes = this.getAttachmentsHashes(); + if (0 < aHashes.length) { if (window.Dropbox) diff --git a/dev/View/User/Settings/Menu.js b/dev/View/User/Settings/Menu.js index 6b437f2ab..39f20f9ae 100644 --- a/dev/View/User/Settings/Menu.js +++ b/dev/View/User/Settings/Menu.js @@ -1,6 +1,7 @@ var _ = require('_'), + $ = require('$'), key = require('key'), Enums = require('Common/Enums'), diff --git a/dev/bootstrap.jsx b/dev/bootstrap.jsx index 6a598d17d..074c755de 100644 --- a/dev/bootstrap.jsx +++ b/dev/bootstrap.jsx @@ -1,7 +1,7 @@ import window from 'window'; import $ from '$'; -import {kill_CtrlA_CtrlS, detectDropdownVisibility, createCommand} from 'Common/Utils'; +import {killCtrlACtrlS, detectDropdownVisibility, createCommand} from 'Common/Utils'; import {$win, $html, data as GlobalsData, bMobileDevice} from 'Common/Globals'; import * as Enums from 'Common/Enums'; import * as Plugins from 'Common/Plugins'; @@ -13,7 +13,7 @@ export default (App) => { GlobalsData.__APP__ = App; $win - .on('keydown', kill_CtrlA_CtrlS) + .on('keydown', killCtrlACtrlS) .on('unload', () => { GlobalsData.bUnload = true; }); diff --git a/rainloop/v/0.0.0/app/templates/Views/Admin/AdminSettingsLogin.html b/rainloop/v/0.0.0/app/templates/Views/Admin/AdminSettingsLogin.html index 918b5e996..4d0efc51a 100644 --- a/rainloop/v/0.0.0/app/templates/Views/Admin/AdminSettingsLogin.html +++ b/rainloop/v/0.0.0/app/templates/Views/Admin/AdminSettingsLogin.html @@ -8,7 +8,7 @@ name: 'Input', params: { value: defaultDomain, - trigger: defaultDomainTrigger, + trigger: defaultDomain.trigger, size: 3 } }"> diff --git a/rainloop/v/0.0.0/app/templates/Views/User/PopupsNewOpenPgpKey.html b/rainloop/v/0.0.0/app/templates/Views/User/PopupsNewOpenPgpKey.html index 916de9fa1..f377f1282 100644 --- a/rainloop/v/0.0.0/app/templates/Views/User/PopupsNewOpenPgpKey.html +++ b/rainloop/v/0.0.0/app/templates/Views/User/PopupsNewOpenPgpKey.html @@ -9,6 +9,11 @@