mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 21:49:21 +03:00
es5 -> es2015 (last stage)
Signature plugin fixes Add view decorator A large number of fixes
This commit is contained in:
parent
e88c193334
commit
17669b7be0
153 changed files with 21193 additions and 21115 deletions
|
|
@ -1,123 +0,0 @@
|
|||
|
||||
var
|
||||
ko = require('ko'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Globals = require('Common/Globals');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {string=} sPosition = ''
|
||||
* @param {string=} sTemplate = ''
|
||||
*/
|
||||
function AbstractView(sPosition, sTemplate)
|
||||
{
|
||||
this.bDisabeCloseOnEsc = false;
|
||||
this.sPosition = Utils.pString(sPosition);
|
||||
this.sTemplate = Utils.pString(sTemplate);
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.None;
|
||||
this.sCurrentKeyScope = this.sDefaultKeyScope;
|
||||
|
||||
this.viewModelVisibility = ko.observable(false);
|
||||
this.modalVisibility = ko.observable(false).extend({'rateLimit': 0});
|
||||
|
||||
this.viewModelName = '';
|
||||
this.viewModelNames = [];
|
||||
this.viewModelDom = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
AbstractView.prototype.bDisabeCloseOnEsc = false;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
AbstractView.prototype.sPosition = '';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
AbstractView.prototype.sTemplate = '';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
AbstractView.prototype.sDefaultKeyScope = Enums.KeyState.None;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
AbstractView.prototype.sCurrentKeyScope = Enums.KeyState.None;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
AbstractView.prototype.viewModelName = '';
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
*/
|
||||
AbstractView.prototype.viewModelNames = [];
|
||||
|
||||
/**
|
||||
* @type {?}
|
||||
*/
|
||||
AbstractView.prototype.viewModelDom = null;
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
AbstractView.prototype.viewModelTemplate = function()
|
||||
{
|
||||
return this.sTemplate;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
AbstractView.prototype.viewModelPosition = function()
|
||||
{
|
||||
return this.sPosition;
|
||||
};
|
||||
|
||||
AbstractView.prototype.cancelCommand = Utils.noop;
|
||||
AbstractView.prototype.closeCommand = Utils.noop;
|
||||
|
||||
AbstractView.prototype.storeAndSetKeyScope = function()
|
||||
{
|
||||
this.sCurrentKeyScope = Globals.keyScope();
|
||||
Globals.keyScope(this.sDefaultKeyScope);
|
||||
};
|
||||
|
||||
AbstractView.prototype.restoreKeyScope = function()
|
||||
{
|
||||
Globals.keyScope(this.sCurrentKeyScope);
|
||||
};
|
||||
|
||||
AbstractView.prototype.registerPopupKeyDown = function()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
Globals.$win.on('keydown', function(oEvent) {
|
||||
if (oEvent && self.modalVisibility && self.modalVisibility())
|
||||
{
|
||||
if (!this.bDisabeCloseOnEsc && Enums.EventKeyCode.Esc === oEvent.keyCode)
|
||||
{
|
||||
Utils.delegateRun(self, 'cancelCommand');
|
||||
return false;
|
||||
}
|
||||
else if (Enums.EventKeyCode.Backspace === oEvent.keyCode && !Utils.inFocus())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = AbstractView;
|
||||
64
dev/Knoin/AbstractViewNext.js
Normal file
64
dev/Knoin/AbstractViewNext.js
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
|
||||
import ko from 'ko';
|
||||
|
||||
import {delegateRun, inFocus} from 'Common/Utils';
|
||||
import {KeyState, EventKeyCode} from 'Common/Enums';
|
||||
import {$win, keyScope} from 'Common/Globals';
|
||||
|
||||
class AbstractViewNext
|
||||
{
|
||||
constructor() {
|
||||
this.bDisabeCloseOnEsc = false;
|
||||
this.sDefaultKeyScope = KeyState.None;
|
||||
this.sCurrentKeyScope = this.sDefaultKeyScope;
|
||||
|
||||
this.viewModelVisibility = ko.observable(false);
|
||||
this.modalVisibility = ko.observable(false).extend({rateLimit: 0});
|
||||
|
||||
this.viewModelName = '';
|
||||
this.viewModelNames = [];
|
||||
this.viewModelDom = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
storeAndSetKeyScope() {
|
||||
this.sCurrentKeyScope = keyScope();
|
||||
keyScope(this.sDefaultKeyScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
restoreKeyScope() {
|
||||
keyScope(this.sCurrentKeyScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
registerPopupKeyDown() {
|
||||
$win.on('keydown', (event) => {
|
||||
if (event && this.modalVisibility && this.modalVisibility())
|
||||
{
|
||||
if (!this.bDisabeCloseOnEsc && EventKeyCode.Esc === event.keyCode)
|
||||
{
|
||||
delegateRun(this, 'cancelCommand');
|
||||
return false;
|
||||
}
|
||||
else if (EventKeyCode.Backspace === event.keyCode && !inFocus())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
cancelCommand() {} // eslint-disable-line no-empty-function
|
||||
closeCommand() {} // eslint-disable-line no-empty-function
|
||||
}
|
||||
|
||||
export {AbstractViewNext, AbstractViewNext as default};
|
||||
|
|
@ -9,7 +9,7 @@ import {runHook} from 'Common/Plugins';
|
|||
import {$html, aViewModels as VIEW_MODELS, popupVisibilityNames} from 'Common/Globals';
|
||||
|
||||
import {
|
||||
isFunc, isArray, isUnd, pString, log,
|
||||
isArray, isUnd, pString, log,
|
||||
createCommand, delegateRun, isNonEmptyArray
|
||||
} from 'Common/Utils';
|
||||
|
||||
|
|
@ -19,6 +19,13 @@ let
|
|||
|
||||
const SCREENS = {};
|
||||
|
||||
export const ViewType = {
|
||||
Popup: 'Popups',
|
||||
Left: 'Left',
|
||||
Right: 'Right',
|
||||
Center: 'Center'
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
|
|
@ -28,40 +35,6 @@ export function hideLoading()
|
|||
$('#rl-loading').hide().remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} context
|
||||
* @returns {void}
|
||||
*/
|
||||
export function constructorEnd(context)
|
||||
{
|
||||
if (isFunc(context.__constructor_end))
|
||||
{
|
||||
context.__constructor_end();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|Array} name
|
||||
* @param {Function} ViewModelClass
|
||||
* @returns {void}
|
||||
*/
|
||||
export function extendAsViewModel(name, ViewModelClass)
|
||||
{
|
||||
if (ViewModelClass)
|
||||
{
|
||||
if (isArray(name))
|
||||
{
|
||||
ViewModelClass.__names = name;
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewModelClass.__names = [name];
|
||||
}
|
||||
|
||||
ViewModelClass.__name = ViewModelClass.__names[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} SettingsViewModelClass
|
||||
* @param {string} template
|
||||
|
|
@ -161,8 +134,8 @@ export function buildViewModel(ViewModelClass, vmScreen)
|
|||
let vmDom = null;
|
||||
const
|
||||
vm = new ViewModelClass(vmScreen),
|
||||
position = vm.viewModelPosition(),
|
||||
vmPlace = $('#rl-content #rl-' + position.toLowerCase());
|
||||
position = ViewModelClass.__type || '',
|
||||
vmPlace = position ? $('#rl-content #rl-' + position.toLowerCase()) : null;
|
||||
|
||||
ViewModelClass.__builded = true;
|
||||
ViewModelClass.__vm = vm;
|
||||
|
|
@ -172,18 +145,20 @@ export function buildViewModel(ViewModelClass, vmScreen)
|
|||
|
||||
vm.viewModelName = ViewModelClass.__name;
|
||||
vm.viewModelNames = ViewModelClass.__names;
|
||||
vm.viewModelTemplateID = ViewModelClass.__templateID;
|
||||
vm.viewModelPosition = ViewModelClass.__type;
|
||||
|
||||
if (vmPlace && 1 === vmPlace.length)
|
||||
{
|
||||
vmDom = $('<div></div>').addClass('rl-view-model').addClass('RL-' + vm.viewModelTemplate()).hide();
|
||||
vmDom = $('<div></div>').addClass('rl-view-model').addClass('RL-' + vm.viewModelTemplateID).hide();
|
||||
vmDom.appendTo(vmPlace);
|
||||
|
||||
vm.viewModelDom = vmDom;
|
||||
ViewModelClass.__dom = vmDom;
|
||||
|
||||
if ('Popups' === position)
|
||||
if (ViewType.Popup === position)
|
||||
{
|
||||
vm.cancelCommand = vm.closeCommand = createCommand(vm, () => {
|
||||
vm.cancelCommand = vm.closeCommand = createCommand(() => {
|
||||
hideScreenPopup(ViewModelClass);
|
||||
});
|
||||
|
||||
|
|
@ -229,11 +204,11 @@ export function buildViewModel(ViewModelClass, vmScreen)
|
|||
|
||||
ko.applyBindingAccessorsToNode(vmDom[0], {
|
||||
translatorInit: true,
|
||||
template: () => ({name: vm.viewModelTemplate()})
|
||||
template: () => ({name: vm.viewModelTemplateID})
|
||||
}, vm);
|
||||
|
||||
delegateRun(vm, 'onBuild', [vmDom]);
|
||||
if (vm && 'Popups' === position)
|
||||
if (vm && ViewType.Popup === position)
|
||||
{
|
||||
vm.registerPopupKeyDown();
|
||||
}
|
||||
|
|
@ -273,6 +248,23 @@ export function showScreenPopup(ViewModelClassToShow, params = [])
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToShow
|
||||
* @returns {void}
|
||||
*/
|
||||
export function warmUpScreenPopup(ViewModelClassToShow)
|
||||
{
|
||||
if (ViewModelClassToShow)
|
||||
{
|
||||
buildViewModel(ViewModelClassToShow);
|
||||
|
||||
if (ViewModelClassToShow.__vm && ViewModelClassToShow.__dom)
|
||||
{
|
||||
delegateRun(ViewModelClassToShow.__vm, 'onWarmUp');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToShow
|
||||
* @returns {boolean}
|
||||
|
|
@ -345,7 +337,7 @@ export function screenOnRoute(screenName, subPart)
|
|||
if (isNonEmptyArray(currentScreen.viewModels()))
|
||||
{
|
||||
_.each(currentScreen.viewModels(), (ViewModelClass) => {
|
||||
if (ViewModelClass.__vm && ViewModelClass.__dom && 'Popups' !== ViewModelClass.__vm.viewModelPosition())
|
||||
if (ViewModelClass.__vm && ViewModelClass.__dom && ViewType.Popup !== ViewModelClass.__vm.viewModelPosition)
|
||||
{
|
||||
ViewModelClass.__dom.hide();
|
||||
ViewModelClass.__vm.viewModelVisibility(false);
|
||||
|
|
@ -380,7 +372,7 @@ export function screenOnRoute(screenName, subPart)
|
|||
{
|
||||
_.each(currentScreen.viewModels(), (ViewModelClass) => {
|
||||
|
||||
if (ViewModelClass.__vm && ViewModelClass.__dom && 'Popups' !== ViewModelClass.__vm.viewModelPosition())
|
||||
if (ViewModelClass.__vm && ViewModelClass.__dom && ViewType.Popup !== ViewModelClass.__vm.viewModelPosition)
|
||||
{
|
||||
delegateRun(ViewModelClass.__vm, 'onBeforeShow');
|
||||
|
||||
|
|
@ -486,3 +478,41 @@ export function setHash(hash, silence = false, replace = false)
|
|||
hasher.setHash(hash);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @returns {void}
|
||||
*/
|
||||
function viewDecorator({name, type, templateID})
|
||||
{
|
||||
return (target) => {
|
||||
if (target)
|
||||
{
|
||||
if (name)
|
||||
{
|
||||
if (isArray(name))
|
||||
{
|
||||
target.__names = name;
|
||||
}
|
||||
else
|
||||
{
|
||||
target.__names = [name];
|
||||
}
|
||||
|
||||
target.__name = target.__names[0];
|
||||
}
|
||||
|
||||
if (type)
|
||||
{
|
||||
target.__type = type;
|
||||
}
|
||||
|
||||
if (templateID)
|
||||
{
|
||||
target.__templateID = templateID;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export {viewDecorator, viewDecorator as view, viewDecorator as viewModel};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue