mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 23:17:02 +03:00
CommonJS (research)
This commit is contained in:
parent
2fa2cd191e
commit
56607de87c
91 changed files with 20220 additions and 12933 deletions
|
|
@ -1,14 +0,0 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function KnoinAbstractBoot()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
KnoinAbstractBoot.prototype.bootstart = function ()
|
||||
{
|
||||
|
||||
};
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @param {string} sScreenName
|
||||
* @param {?=} aViewModels = []
|
||||
* @constructor
|
||||
*/
|
||||
function KnoinAbstractScreen(sScreenName, aViewModels)
|
||||
{
|
||||
this.sScreenName = sScreenName;
|
||||
this.aViewModels = Utils.isArray(aViewModels) ? aViewModels : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.oCross = null;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.sScreenName = '';
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.aViewModels = [];
|
||||
|
||||
/**
|
||||
* @return {Array}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.viewModels = function ()
|
||||
{
|
||||
return this.aViewModels;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.screenName = function ()
|
||||
{
|
||||
return this.sScreenName;
|
||||
};
|
||||
|
||||
KnoinAbstractScreen.prototype.routes = function ()
|
||||
{
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {?Object}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.__cross = function ()
|
||||
{
|
||||
return this.oCross;
|
||||
};
|
||||
|
||||
KnoinAbstractScreen.prototype.__start = function ()
|
||||
{
|
||||
var
|
||||
aRoutes = this.routes(),
|
||||
oRoute = null,
|
||||
fMatcher = null
|
||||
;
|
||||
|
||||
if (Utils.isNonEmptyArray(aRoutes))
|
||||
{
|
||||
fMatcher = _.bind(this.onRoute || Utils.emptyFunction, this);
|
||||
oRoute = crossroads.create();
|
||||
|
||||
_.each(aRoutes, function (aItem) {
|
||||
oRoute.addRoute(aItem[0], fMatcher).rules = aItem[1];
|
||||
});
|
||||
|
||||
this.oCross = oRoute;
|
||||
}
|
||||
};
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @param {string=} sPosition = ''
|
||||
* @param {string=} sTemplate = ''
|
||||
* @constructor
|
||||
*/
|
||||
function KnoinAbstractViewModel(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.viewModelName = '';
|
||||
this.viewModelVisibility = ko.observable(false);
|
||||
this.modalVisibility = ko.observable(false).extend({'rateLimit': 0});
|
||||
|
||||
this.viewModelDom = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.sPosition = '';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.sTemplate = '';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.viewModelName = '';
|
||||
|
||||
/**
|
||||
* @type {?}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.viewModelDom = null;
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.viewModelTemplate = function ()
|
||||
{
|
||||
return this.sTemplate;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.viewModelPosition = function ()
|
||||
{
|
||||
return this.sPosition;
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.cancelCommand = KnoinAbstractViewModel.prototype.closeCommand = function ()
|
||||
{
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.storeAndSetKeyScope = function ()
|
||||
{
|
||||
this.sCurrentKeyScope = RL.data().keyScope();
|
||||
RL.data().keyScope(this.sDefaultKeyScope);
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.restoreKeyScope = function ()
|
||||
{
|
||||
RL.data().keyScope(this.sCurrentKeyScope);
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.registerPopupKeyDown = function ()
|
||||
{
|
||||
var self = this;
|
||||
$window.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;
|
||||
});
|
||||
};
|
||||
|
|
@ -1,415 +1,486 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function Knoin()
|
||||
{
|
||||
this.sDefaultScreenName = '';
|
||||
this.oScreens = {};
|
||||
this.oBoot = null;
|
||||
this.oCurrentScreen = null;
|
||||
}
|
||||
(function (module) {
|
||||
|
||||
/**
|
||||
* @param {Object} thisObject
|
||||
*/
|
||||
Knoin.constructorEnd = function (thisObject)
|
||||
{
|
||||
if (Utils.isFunc(thisObject['__constructor_end']))
|
||||
'use strict';
|
||||
|
||||
var
|
||||
$ = require('../External/jquery.js'),
|
||||
_ = require('../External/underscore.js'),
|
||||
ko = require('../External/ko.js'),
|
||||
hasher = require('../External/hasher.js'),
|
||||
crossroads = require('../External/crossroads.js'),
|
||||
$html = require('../External/$html.js'),
|
||||
Utils = require('../Common/Utils.js'),
|
||||
Globals = require('../Common/Globals.js'),
|
||||
Enums = require('../Common/Enums.js')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function Knoin()
|
||||
{
|
||||
thisObject['__constructor_end'].call(thisObject);
|
||||
}
|
||||
};
|
||||
|
||||
Knoin.prototype.sDefaultScreenName = '';
|
||||
Knoin.prototype.oScreens = {};
|
||||
Knoin.prototype.oBoot = null;
|
||||
Knoin.prototype.oCurrentScreen = null;
|
||||
|
||||
Knoin.prototype.hideLoading = function ()
|
||||
{
|
||||
$('#rl-loading').hide();
|
||||
};
|
||||
|
||||
Knoin.prototype.routeOff = function ()
|
||||
{
|
||||
hasher.changed.active = false;
|
||||
};
|
||||
|
||||
Knoin.prototype.routeOn = function ()
|
||||
{
|
||||
hasher.changed.active = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} oBoot
|
||||
* @return {Knoin}
|
||||
*/
|
||||
Knoin.prototype.setBoot = function (oBoot)
|
||||
{
|
||||
if (Utils.isNormal(oBoot))
|
||||
{
|
||||
this.oBoot = oBoot;
|
||||
this.sDefaultScreenName = '';
|
||||
this.oScreens = {};
|
||||
this.oBoot = null;
|
||||
this.oCurrentScreen = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @param {Object} thisObject
|
||||
*/
|
||||
Knoin.constructorEnd = function (thisObject)
|
||||
{
|
||||
if (Utils.isFunc(thisObject['__constructor_end']))
|
||||
{
|
||||
thisObject['__constructor_end'].call(thisObject);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sScreenName
|
||||
* @return {?Object}
|
||||
*/
|
||||
Knoin.prototype.screen = function (sScreenName)
|
||||
{
|
||||
return ('' !== sScreenName && !Utils.isUnd(this.oScreens[sScreenName])) ? this.oScreens[sScreenName] : null;
|
||||
};
|
||||
Knoin.prototype.sDefaultScreenName = '';
|
||||
Knoin.prototype.oScreens = {};
|
||||
Knoin.prototype.oBoot = null;
|
||||
Knoin.prototype.oCurrentScreen = null;
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClass
|
||||
* @param {Object=} oScreen
|
||||
*/
|
||||
Knoin.prototype.buildViewModel = function (ViewModelClass, oScreen)
|
||||
{
|
||||
if (ViewModelClass && !ViewModelClass.__builded)
|
||||
Knoin.prototype.hideLoading = function ()
|
||||
{
|
||||
$('#rl-loading').hide();
|
||||
};
|
||||
|
||||
Knoin.prototype.rl = function ()
|
||||
{
|
||||
return this.oBoot;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} thisObject
|
||||
*/
|
||||
Knoin.prototype.constructorEnd = function (thisObject)
|
||||
{
|
||||
if (Utils.isFunc(thisObject['__constructor_end']))
|
||||
{
|
||||
thisObject['__constructor_end'].call(thisObject);
|
||||
}
|
||||
};
|
||||
|
||||
Knoin.prototype.routeOff = function ()
|
||||
{
|
||||
hasher.changed.active = false;
|
||||
};
|
||||
|
||||
Knoin.prototype.routeOn = function ()
|
||||
{
|
||||
hasher.changed.active = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sScreenName
|
||||
* @return {?Object}
|
||||
*/
|
||||
Knoin.prototype.screen = function (sScreenName)
|
||||
{
|
||||
return ('' !== sScreenName && !Utils.isUnd(this.oScreens[sScreenName])) ? this.oScreens[sScreenName] : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClass
|
||||
* @param {Object=} oScreen
|
||||
*/
|
||||
Knoin.prototype.buildViewModel = function (ViewModelClass, oScreen)
|
||||
{
|
||||
if (ViewModelClass && !ViewModelClass.__builded)
|
||||
{
|
||||
var
|
||||
oViewModel = new ViewModelClass(oScreen),
|
||||
sPosition = oViewModel.viewModelPosition(),
|
||||
oViewModelPlace = $('#rl-content #rl-' + sPosition.toLowerCase()),
|
||||
oViewModelDom = null
|
||||
;
|
||||
|
||||
ViewModelClass.__builded = true;
|
||||
ViewModelClass.__vm = oViewModel;
|
||||
oViewModel.data = RL.data(); // TODO cjs
|
||||
|
||||
oViewModel.viewModelName = ViewModelClass.__name;
|
||||
|
||||
if (oViewModelPlace && 1 === oViewModelPlace.length)
|
||||
{
|
||||
oViewModelDom = $('<div></div>').addClass('rl-view-model').addClass('RL-' + oViewModel.viewModelTemplate()).hide();
|
||||
oViewModelDom.appendTo(oViewModelPlace);
|
||||
|
||||
oViewModel.viewModelDom = oViewModelDom;
|
||||
ViewModelClass.__dom = oViewModelDom;
|
||||
|
||||
if ('Popups' === sPosition)
|
||||
{
|
||||
oViewModel.cancelCommand = oViewModel.closeCommand = Utils.createCommand(oViewModel, function () {
|
||||
kn.hideScreenPopup(ViewModelClass); // TODO cjs
|
||||
});
|
||||
|
||||
oViewModel.modalVisibility.subscribe(function (bValue) {
|
||||
|
||||
var self = this;
|
||||
if (bValue)
|
||||
{
|
||||
this.viewModelDom.show();
|
||||
this.storeAndSetKeyScope();
|
||||
|
||||
RL.popupVisibilityNames.push(this.viewModelName); // TODO cjs
|
||||
oViewModel.viewModelDom.css('z-index', 3000 + RL.popupVisibilityNames().length + 10); // TODO cjs
|
||||
|
||||
Utils.delegateRun(this, 'onFocus', [], 500);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.delegateRun(this, 'onHide');
|
||||
this.restoreKeyScope();
|
||||
|
||||
RL.popupVisibilityNames.remove(this.viewModelName); // TODO cjs
|
||||
oViewModel.viewModelDom.css('z-index', 2000);
|
||||
|
||||
Globals.tooltipTrigger(!Globals.tooltipTrigger());
|
||||
|
||||
_.delay(function () {
|
||||
self.viewModelDom.hide();
|
||||
}, 300);
|
||||
}
|
||||
|
||||
}, oViewModel);
|
||||
}
|
||||
|
||||
Plugins.runHook('view-model-pre-build', [ViewModelClass.__name, oViewModel, oViewModelDom]); // TODO cjs
|
||||
|
||||
ko.applyBindingAccessorsToNode(oViewModelDom[0], {
|
||||
'i18nInit': true,
|
||||
'template': function () { return {'name': oViewModel.viewModelTemplate()};}
|
||||
}, oViewModel);
|
||||
|
||||
Utils.delegateRun(oViewModel, 'onBuild', [oViewModelDom]);
|
||||
if (oViewModel && 'Popups' === sPosition)
|
||||
{
|
||||
oViewModel.registerPopupKeyDown();
|
||||
}
|
||||
|
||||
Plugins.runHook('view-model-post-build', [ViewModelClass.__name, oViewModel, oViewModelDom]); // TODO cjs
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.log('Cannot find view model position: ' + sPosition);
|
||||
}
|
||||
}
|
||||
|
||||
return ViewModelClass ? ViewModelClass.__vm : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} oViewModel
|
||||
* @param {Object} oViewModelDom
|
||||
*/
|
||||
Knoin.prototype.applyExternal = function (oViewModel, oViewModelDom)
|
||||
{
|
||||
if (oViewModel && oViewModelDom)
|
||||
{
|
||||
ko.applyBindings(oViewModel, oViewModelDom);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToHide
|
||||
*/
|
||||
Knoin.prototype.hideScreenPopup = function (ViewModelClassToHide)
|
||||
{
|
||||
if (ViewModelClassToHide && ViewModelClassToHide.__vm && ViewModelClassToHide.__dom)
|
||||
{
|
||||
ViewModelClassToHide.__vm.modalVisibility(false);
|
||||
Plugins.runHook('view-model-on-hide', [ViewModelClassToHide.__name, ViewModelClassToHide.__vm]); // TODO cjs
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToShow
|
||||
* @param {Array=} aParameters
|
||||
*/
|
||||
Knoin.prototype.showScreenPopup = function (ViewModelClassToShow, aParameters)
|
||||
{
|
||||
if (ViewModelClassToShow)
|
||||
{
|
||||
this.buildViewModel(ViewModelClassToShow);
|
||||
|
||||
if (ViewModelClassToShow.__vm && ViewModelClassToShow.__dom)
|
||||
{
|
||||
ViewModelClassToShow.__vm.modalVisibility(true);
|
||||
Utils.delegateRun(ViewModelClassToShow.__vm, 'onShow', aParameters || []);
|
||||
Plugins.runHook('view-model-on-show', [ViewModelClassToShow.__name, ViewModelClassToShow.__vm, aParameters || []]); // TODO cjs
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToShow
|
||||
* @return {boolean}
|
||||
*/
|
||||
Knoin.prototype.isPopupVisible = function (ViewModelClassToShow)
|
||||
{
|
||||
return ViewModelClassToShow && ViewModelClassToShow.__vm ? ViewModelClassToShow.__vm.modalVisibility() : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sScreenName
|
||||
* @param {string} sSubPart
|
||||
*/
|
||||
Knoin.prototype.screenOnRoute = function (sScreenName, sSubPart)
|
||||
{
|
||||
var
|
||||
oViewModel = new ViewModelClass(oScreen),
|
||||
sPosition = oViewModel.viewModelPosition(),
|
||||
oViewModelPlace = $('#rl-content #rl-' + sPosition.toLowerCase()),
|
||||
oViewModelDom = null
|
||||
self = this,
|
||||
oScreen = null,
|
||||
oCross = null
|
||||
;
|
||||
|
||||
ViewModelClass.__builded = true;
|
||||
ViewModelClass.__vm = oViewModel;
|
||||
oViewModel.data = RL.data();
|
||||
|
||||
oViewModel.viewModelName = ViewModelClass.__name;
|
||||
|
||||
if (oViewModelPlace && 1 === oViewModelPlace.length)
|
||||
if ('' === Utils.pString(sScreenName))
|
||||
{
|
||||
oViewModelDom = $('<div></div>').addClass('rl-view-model').addClass('RL-' + oViewModel.viewModelTemplate()).hide();
|
||||
oViewModelDom.appendTo(oViewModelPlace);
|
||||
sScreenName = this.sDefaultScreenName;
|
||||
}
|
||||
|
||||
oViewModel.viewModelDom = oViewModelDom;
|
||||
ViewModelClass.__dom = oViewModelDom;
|
||||
|
||||
if ('Popups' === sPosition)
|
||||
if ('' !== sScreenName)
|
||||
{
|
||||
oScreen = this.screen(sScreenName);
|
||||
if (!oScreen)
|
||||
{
|
||||
oViewModel.cancelCommand = oViewModel.closeCommand = Utils.createCommand(oViewModel, function () {
|
||||
kn.hideScreenPopup(ViewModelClass);
|
||||
oScreen = this.screen(this.sDefaultScreenName);
|
||||
if (oScreen)
|
||||
{
|
||||
sSubPart = sScreenName + '/' + sSubPart;
|
||||
sScreenName = this.sDefaultScreenName;
|
||||
}
|
||||
}
|
||||
|
||||
if (oScreen && oScreen.__started)
|
||||
{
|
||||
if (!oScreen.__builded)
|
||||
{
|
||||
oScreen.__builded = true;
|
||||
|
||||
if (Utils.isNonEmptyArray(oScreen.viewModels()))
|
||||
{
|
||||
_.each(oScreen.viewModels(), function (ViewModelClass) {
|
||||
this.buildViewModel(ViewModelClass, oScreen);
|
||||
}, this);
|
||||
}
|
||||
|
||||
Utils.delegateRun(oScreen, 'onBuild');
|
||||
}
|
||||
|
||||
_.defer(function () {
|
||||
|
||||
// hide screen
|
||||
if (self.oCurrentScreen)
|
||||
{
|
||||
Utils.delegateRun(self.oCurrentScreen, 'onHide');
|
||||
|
||||
if (Utils.isNonEmptyArray(self.oCurrentScreen.viewModels()))
|
||||
{
|
||||
_.each(self.oCurrentScreen.viewModels(), function (ViewModelClass) {
|
||||
|
||||
if (ViewModelClass.__vm && ViewModelClass.__dom &&
|
||||
'Popups' !== ViewModelClass.__vm.viewModelPosition())
|
||||
{
|
||||
ViewModelClass.__dom.hide();
|
||||
ViewModelClass.__vm.viewModelVisibility(false);
|
||||
Utils.delegateRun(ViewModelClass.__vm, 'onHide');
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
// --
|
||||
|
||||
self.oCurrentScreen = oScreen;
|
||||
|
||||
// show screen
|
||||
if (self.oCurrentScreen)
|
||||
{
|
||||
Utils.delegateRun(self.oCurrentScreen, 'onShow');
|
||||
|
||||
Plugins.runHook('screen-on-show', [self.oCurrentScreen.screenName(), self.oCurrentScreen]); // TODO cjs
|
||||
|
||||
if (Utils.isNonEmptyArray(self.oCurrentScreen.viewModels()))
|
||||
{
|
||||
_.each(self.oCurrentScreen.viewModels(), function (ViewModelClass) {
|
||||
|
||||
if (ViewModelClass.__vm && ViewModelClass.__dom &&
|
||||
'Popups' !== ViewModelClass.__vm.viewModelPosition())
|
||||
{
|
||||
ViewModelClass.__dom.show();
|
||||
ViewModelClass.__vm.viewModelVisibility(true);
|
||||
Utils.delegateRun(ViewModelClass.__vm, 'onShow');
|
||||
Utils.delegateRun(ViewModelClass.__vm, 'onFocus', [], 200);
|
||||
|
||||
Plugins.runHook('view-model-on-show', [ViewModelClass.__name, ViewModelClass.__vm]); // TODO cjs
|
||||
}
|
||||
|
||||
}, self);
|
||||
}
|
||||
}
|
||||
// --
|
||||
|
||||
oCross = oScreen.__cross();
|
||||
if (oCross)
|
||||
{
|
||||
oCross.parse(sSubPart);
|
||||
}
|
||||
});
|
||||
|
||||
oViewModel.modalVisibility.subscribe(function (bValue) {
|
||||
|
||||
var self = this;
|
||||
if (bValue)
|
||||
{
|
||||
this.viewModelDom.show();
|
||||
this.storeAndSetKeyScope();
|
||||
|
||||
RL.popupVisibilityNames.push(this.viewModelName);
|
||||
oViewModel.viewModelDom.css('z-index', 3000 + RL.popupVisibilityNames().length + 10);
|
||||
|
||||
Utils.delegateRun(this, 'onFocus', [], 500);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.delegateRun(this, 'onHide');
|
||||
this.restoreKeyScope();
|
||||
|
||||
RL.popupVisibilityNames.remove(this.viewModelName);
|
||||
oViewModel.viewModelDom.css('z-index', 2000);
|
||||
|
||||
Globals.tooltipTrigger(!Globals.tooltipTrigger());
|
||||
|
||||
_.delay(function () {
|
||||
self.viewModelDom.hide();
|
||||
}, 300);
|
||||
}
|
||||
|
||||
}, oViewModel);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Plugins.runHook('view-model-pre-build', [ViewModelClass.__name, oViewModel, oViewModelDom]);
|
||||
/**
|
||||
* @param {Array} aScreensClasses
|
||||
*/
|
||||
Knoin.prototype.startScreens = function (aScreensClasses)
|
||||
{
|
||||
$('#rl-content').css({
|
||||
'visibility': 'hidden'
|
||||
});
|
||||
|
||||
ko.applyBindingAccessorsToNode(oViewModelDom[0], {
|
||||
'i18nInit': true,
|
||||
'template': function () { return {'name': oViewModel.viewModelTemplate()};}
|
||||
}, oViewModel);
|
||||
_.each(aScreensClasses, function (CScreen) {
|
||||
|
||||
Utils.delegateRun(oViewModel, 'onBuild', [oViewModelDom]);
|
||||
if (oViewModel && 'Popups' === sPosition)
|
||||
var
|
||||
oScreen = new CScreen(),
|
||||
sScreenName = oScreen ? oScreen.screenName() : ''
|
||||
;
|
||||
|
||||
if (oScreen && '' !== sScreenName)
|
||||
{
|
||||
if ('' === this.sDefaultScreenName)
|
||||
{
|
||||
this.sDefaultScreenName = sScreenName;
|
||||
}
|
||||
|
||||
this.oScreens[sScreenName] = oScreen;
|
||||
}
|
||||
|
||||
}, this);
|
||||
|
||||
|
||||
_.each(this.oScreens, function (oScreen) {
|
||||
if (oScreen && !oScreen.__started && oScreen.__start)
|
||||
{
|
||||
oViewModel.registerPopupKeyDown();
|
||||
}
|
||||
oScreen.__started = true;
|
||||
oScreen.__start();
|
||||
|
||||
Plugins.runHook('view-model-post-build', [ViewModelClass.__name, oViewModel, oViewModelDom]);
|
||||
Plugins.runHook('screen-pre-start', [oScreen.screenName(), oScreen]); // TODO cjs
|
||||
Utils.delegateRun(oScreen, 'onStart');
|
||||
Plugins.runHook('screen-post-start', [oScreen.screenName(), oScreen]); // TODO cjs
|
||||
}
|
||||
}, this);
|
||||
|
||||
var oCross = crossroads.create();
|
||||
oCross.addRoute(/^([a-zA-Z0-9\-]*)\/?(.*)$/, _.bind(this.screenOnRoute, this));
|
||||
|
||||
hasher.initialized.add(oCross.parse, oCross);
|
||||
hasher.changed.add(oCross.parse, oCross);
|
||||
hasher.init();
|
||||
|
||||
$('#rl-content').css({
|
||||
'visibility': 'visible'
|
||||
});
|
||||
|
||||
_.delay(function () {
|
||||
$html.removeClass('rl-started-trigger').addClass('rl-started');
|
||||
}, 50);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sHash
|
||||
* @param {boolean=} bSilence = false
|
||||
* @param {boolean=} bReplace = false
|
||||
*/
|
||||
Knoin.prototype.setHash = function (sHash, bSilence, bReplace)
|
||||
{
|
||||
sHash = '#' === sHash.substr(0, 1) ? sHash.substr(1) : sHash;
|
||||
sHash = '/' === sHash.substr(0, 1) ? sHash.substr(1) : sHash;
|
||||
|
||||
bReplace = Utils.isUnd(bReplace) ? false : !!bReplace;
|
||||
|
||||
if (Utils.isUnd(bSilence) ? false : !!bSilence)
|
||||
{
|
||||
hasher.changed.active = false;
|
||||
hasher[bReplace ? 'replaceHash' : 'setHash'](sHash);
|
||||
hasher.changed.active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.log('Cannot find view model position: ' + sPosition);
|
||||
hasher.changed.active = true;
|
||||
hasher[bReplace ? 'replaceHash' : 'setHash'](sHash);
|
||||
hasher.setHash(sHash);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return ViewModelClass ? ViewModelClass.__vm : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} oViewModel
|
||||
* @param {Object} oViewModelDom
|
||||
*/
|
||||
Knoin.prototype.applyExternal = function (oViewModel, oViewModelDom)
|
||||
{
|
||||
if (oViewModel && oViewModelDom)
|
||||
/**
|
||||
* @return {Knoin}
|
||||
*/
|
||||
Knoin.prototype.bootstart = function (RL)
|
||||
{
|
||||
ko.applyBindings(oViewModel, oViewModelDom);
|
||||
}
|
||||
};
|
||||
this.oBoot = RL;
|
||||
|
||||
var
|
||||
window = require('../External/window.js'),
|
||||
$window = require('../External/$window.js'),
|
||||
$html = require('../External/$html.js'),
|
||||
Plugins = require('../Common/Plugins.js'),
|
||||
EmailModel = require('../Models/EmailModel.js')
|
||||
;
|
||||
|
||||
$html.addClass(Globals.bMobileDevice ? 'mobile' : 'no-mobile');
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToHide
|
||||
*/
|
||||
Knoin.prototype.hideScreenPopup = function (ViewModelClassToHide)
|
||||
{
|
||||
if (ViewModelClassToHide && ViewModelClassToHide.__vm && ViewModelClassToHide.__dom)
|
||||
{
|
||||
ViewModelClassToHide.__vm.modalVisibility(false);
|
||||
Plugins.runHook('view-model-on-hide', [ViewModelClassToHide.__name, ViewModelClassToHide.__vm]);
|
||||
}
|
||||
};
|
||||
$window.keydown(Utils.killCtrlAandS).keyup(Utils.killCtrlAandS);
|
||||
$window.unload(function () {
|
||||
Globals.bUnload = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToShow
|
||||
* @param {Array=} aParameters
|
||||
*/
|
||||
Knoin.prototype.showScreenPopup = function (ViewModelClassToShow, aParameters)
|
||||
{
|
||||
if (ViewModelClassToShow)
|
||||
{
|
||||
this.buildViewModel(ViewModelClassToShow);
|
||||
$html.on('click.dropdown.data-api', function () {
|
||||
Utils.detectDropdownVisibility();
|
||||
});
|
||||
|
||||
if (ViewModelClassToShow.__vm && ViewModelClassToShow.__dom)
|
||||
{
|
||||
ViewModelClassToShow.__vm.modalVisibility(true);
|
||||
Utils.delegateRun(ViewModelClassToShow.__vm, 'onShow', aParameters || []);
|
||||
Plugins.runHook('view-model-on-show', [ViewModelClassToShow.__name, ViewModelClassToShow.__vm, aParameters || []]);
|
||||
}
|
||||
}
|
||||
};
|
||||
// export
|
||||
window['rl'] = window['rl'] || {};
|
||||
window['rl']['addHook'] = Plugins.addHook;
|
||||
window['rl']['settingsGet'] = Plugins.mainSettingsGet;
|
||||
window['rl']['remoteRequest'] = Plugins.remoteRequest;
|
||||
window['rl']['pluginSettingsGet'] = Plugins.settingsGet;
|
||||
window['rl']['addSettingsViewModel'] = Utils.addSettingsViewModel;
|
||||
window['rl']['createCommand'] = Utils.createCommand;
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToShow
|
||||
* @return {boolean}
|
||||
*/
|
||||
Knoin.prototype.isPopupVisible = function (ViewModelClassToShow)
|
||||
{
|
||||
return ViewModelClassToShow && ViewModelClassToShow.__vm ? ViewModelClassToShow.__vm.modalVisibility() : false;
|
||||
};
|
||||
window['rl']['EmailModel'] = EmailModel;
|
||||
window['rl']['Enums'] = Enums;
|
||||
|
||||
/**
|
||||
* @param {string} sScreenName
|
||||
* @param {string} sSubPart
|
||||
*/
|
||||
Knoin.prototype.screenOnRoute = function (sScreenName, sSubPart)
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
oScreen = null,
|
||||
oCross = null
|
||||
;
|
||||
window['__RLBOOT'] = function (fCall) {
|
||||
|
||||
if ('' === Utils.pString(sScreenName))
|
||||
{
|
||||
sScreenName = this.sDefaultScreenName;
|
||||
}
|
||||
// boot
|
||||
$(function () {
|
||||
|
||||
if ('' !== sScreenName)
|
||||
{
|
||||
oScreen = this.screen(sScreenName);
|
||||
if (!oScreen)
|
||||
{
|
||||
oScreen = this.screen(this.sDefaultScreenName);
|
||||
if (oScreen)
|
||||
{
|
||||
sSubPart = sScreenName + '/' + sSubPart;
|
||||
sScreenName = this.sDefaultScreenName;
|
||||
}
|
||||
}
|
||||
|
||||
if (oScreen && oScreen.__started)
|
||||
{
|
||||
if (!oScreen.__builded)
|
||||
{
|
||||
oScreen.__builded = true;
|
||||
|
||||
if (Utils.isNonEmptyArray(oScreen.viewModels()))
|
||||
if (window['rainloopTEMPLATES'] && window['rainloopTEMPLATES'][0])
|
||||
{
|
||||
_.each(oScreen.viewModels(), function (ViewModelClass) {
|
||||
this.buildViewModel(ViewModelClass, oScreen);
|
||||
}, this);
|
||||
$('#rl-templates').html(window['rainloopTEMPLATES'][0]);
|
||||
|
||||
_.delay(function () {
|
||||
|
||||
RL.bootstart();
|
||||
|
||||
$html.removeClass('no-js rl-booted-trigger').addClass('rl-booted');
|
||||
}, 50);
|
||||
}
|
||||
else
|
||||
{
|
||||
fCall(false);
|
||||
}
|
||||
|
||||
Utils.delegateRun(oScreen, 'onBuild');
|
||||
}
|
||||
|
||||
_.defer(function () {
|
||||
|
||||
// hide screen
|
||||
if (self.oCurrentScreen)
|
||||
{
|
||||
Utils.delegateRun(self.oCurrentScreen, 'onHide');
|
||||
|
||||
if (Utils.isNonEmptyArray(self.oCurrentScreen.viewModels()))
|
||||
{
|
||||
_.each(self.oCurrentScreen.viewModels(), function (ViewModelClass) {
|
||||
|
||||
if (ViewModelClass.__vm && ViewModelClass.__dom &&
|
||||
'Popups' !== ViewModelClass.__vm.viewModelPosition())
|
||||
{
|
||||
ViewModelClass.__dom.hide();
|
||||
ViewModelClass.__vm.viewModelVisibility(false);
|
||||
Utils.delegateRun(ViewModelClass.__vm, 'onHide');
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
// --
|
||||
|
||||
self.oCurrentScreen = oScreen;
|
||||
|
||||
// show screen
|
||||
if (self.oCurrentScreen)
|
||||
{
|
||||
Utils.delegateRun(self.oCurrentScreen, 'onShow');
|
||||
|
||||
Plugins.runHook('screen-on-show', [self.oCurrentScreen.screenName(), self.oCurrentScreen]);
|
||||
|
||||
if (Utils.isNonEmptyArray(self.oCurrentScreen.viewModels()))
|
||||
{
|
||||
_.each(self.oCurrentScreen.viewModels(), function (ViewModelClass) {
|
||||
|
||||
if (ViewModelClass.__vm && ViewModelClass.__dom &&
|
||||
'Popups' !== ViewModelClass.__vm.viewModelPosition())
|
||||
{
|
||||
ViewModelClass.__dom.show();
|
||||
ViewModelClass.__vm.viewModelVisibility(true);
|
||||
Utils.delegateRun(ViewModelClass.__vm, 'onShow');
|
||||
Utils.delegateRun(ViewModelClass.__vm, 'onFocus', [], 200);
|
||||
|
||||
Plugins.runHook('view-model-on-show', [ViewModelClass.__name, ViewModelClass.__vm]);
|
||||
}
|
||||
|
||||
}, self);
|
||||
}
|
||||
}
|
||||
// --
|
||||
|
||||
oCross = oScreen.__cross();
|
||||
if (oCross)
|
||||
{
|
||||
oCross.parse(sSubPart);
|
||||
}
|
||||
window['__RLBOOT'] = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array} aScreensClasses
|
||||
*/
|
||||
Knoin.prototype.startScreens = function (aScreensClasses)
|
||||
{
|
||||
$('#rl-content').css({
|
||||
'visibility': 'hidden'
|
||||
});
|
||||
module.exports = new Knoin();
|
||||
|
||||
_.each(aScreensClasses, function (CScreen) {
|
||||
|
||||
var
|
||||
oScreen = new CScreen(),
|
||||
sScreenName = oScreen ? oScreen.screenName() : ''
|
||||
;
|
||||
|
||||
if (oScreen && '' !== sScreenName)
|
||||
{
|
||||
if ('' === this.sDefaultScreenName)
|
||||
{
|
||||
this.sDefaultScreenName = sScreenName;
|
||||
}
|
||||
|
||||
this.oScreens[sScreenName] = oScreen;
|
||||
}
|
||||
|
||||
}, this);
|
||||
|
||||
|
||||
_.each(this.oScreens, function (oScreen) {
|
||||
if (oScreen && !oScreen.__started && oScreen.__start)
|
||||
{
|
||||
oScreen.__started = true;
|
||||
oScreen.__start();
|
||||
|
||||
Plugins.runHook('screen-pre-start', [oScreen.screenName(), oScreen]);
|
||||
Utils.delegateRun(oScreen, 'onStart');
|
||||
Plugins.runHook('screen-post-start', [oScreen.screenName(), oScreen]);
|
||||
}
|
||||
}, this);
|
||||
|
||||
var oCross = crossroads.create();
|
||||
oCross.addRoute(/^([a-zA-Z0-9\-]*)\/?(.*)$/, _.bind(this.screenOnRoute, this));
|
||||
|
||||
hasher.initialized.add(oCross.parse, oCross);
|
||||
hasher.changed.add(oCross.parse, oCross);
|
||||
hasher.init();
|
||||
|
||||
$('#rl-content').css({
|
||||
'visibility': 'visible'
|
||||
});
|
||||
|
||||
_.delay(function () {
|
||||
$html.removeClass('rl-started-trigger').addClass('rl-started');
|
||||
}, 50);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sHash
|
||||
* @param {boolean=} bSilence = false
|
||||
* @param {boolean=} bReplace = false
|
||||
*/
|
||||
Knoin.prototype.setHash = function (sHash, bSilence, bReplace)
|
||||
{
|
||||
sHash = '#' === sHash.substr(0, 1) ? sHash.substr(1) : sHash;
|
||||
sHash = '/' === sHash.substr(0, 1) ? sHash.substr(1) : sHash;
|
||||
|
||||
bReplace = Utils.isUnd(bReplace) ? false : !!bReplace;
|
||||
|
||||
if (Utils.isUnd(bSilence) ? false : !!bSilence)
|
||||
{
|
||||
hasher.changed.active = false;
|
||||
hasher[bReplace ? 'replaceHash' : 'setHash'](sHash);
|
||||
hasher.changed.active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
hasher.changed.active = true;
|
||||
hasher[bReplace ? 'replaceHash' : 'setHash'](sHash);
|
||||
hasher.setHash(sHash);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Knoin}
|
||||
*/
|
||||
Knoin.prototype.bootstart = function ()
|
||||
{
|
||||
if (this.oBoot && this.oBoot.bootstart)
|
||||
{
|
||||
this.oBoot.bootstart();
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
kn = new Knoin();
|
||||
}(module));
|
||||
22
dev/Knoin/KnoinAbstractBoot.js
Normal file
22
dev/Knoin/KnoinAbstractBoot.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
(function (module) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function KnoinAbstractBoot()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
KnoinAbstractBoot.prototype.bootstart = function ()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
module.exports = KnoinAbstractBoot;
|
||||
|
||||
}(module));
|
||||
90
dev/Knoin/KnoinAbstractScreen.js
Normal file
90
dev/Knoin/KnoinAbstractScreen.js
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
(function (module) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
crossroads = require('../External/crossroads.js'),
|
||||
Utils = require('../Common/Utils.js')
|
||||
;
|
||||
|
||||
/**
|
||||
* @param {string} sScreenName
|
||||
* @param {?=} aViewModels = []
|
||||
* @constructor
|
||||
*/
|
||||
function KnoinAbstractScreen(sScreenName, aViewModels)
|
||||
{
|
||||
this.sScreenName = sScreenName;
|
||||
this.aViewModels = Utils.isArray(aViewModels) ? aViewModels : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.oCross = null;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.sScreenName = '';
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.aViewModels = [];
|
||||
|
||||
/**
|
||||
* @return {Array}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.viewModels = function ()
|
||||
{
|
||||
return this.aViewModels;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.screenName = function ()
|
||||
{
|
||||
return this.sScreenName;
|
||||
};
|
||||
|
||||
KnoinAbstractScreen.prototype.routes = function ()
|
||||
{
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {?Object}
|
||||
*/
|
||||
KnoinAbstractScreen.prototype.__cross = function ()
|
||||
{
|
||||
return this.oCross;
|
||||
};
|
||||
|
||||
KnoinAbstractScreen.prototype.__start = function ()
|
||||
{
|
||||
var
|
||||
aRoutes = this.routes(),
|
||||
oRoute = null,
|
||||
fMatcher = null
|
||||
;
|
||||
|
||||
if (Utils.isNonEmptyArray(aRoutes))
|
||||
{
|
||||
fMatcher = _.bind(this.onRoute || Utils.emptyFunction, this);
|
||||
oRoute = crossroads.create();
|
||||
|
||||
_.each(aRoutes, function (aItem) {
|
||||
oRoute.addRoute(aItem[0], fMatcher).rules = aItem[1];
|
||||
});
|
||||
|
||||
this.oCross = oRoute;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = KnoinAbstractScreen;
|
||||
|
||||
}(module));
|
||||
109
dev/Knoin/KnoinAbstractViewModel.js
Normal file
109
dev/Knoin/KnoinAbstractViewModel.js
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
(function (module) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('../External/ko.js'),
|
||||
$window = require('../External/$window.js'),
|
||||
Utils = require('../Common/Utils.js'),
|
||||
Enums = require('../Common/Enums.js')
|
||||
;
|
||||
|
||||
/**
|
||||
* @param {string=} sPosition = ''
|
||||
* @param {string=} sTemplate = ''
|
||||
* @constructor
|
||||
*/
|
||||
function KnoinAbstractViewModel(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.viewModelName = '';
|
||||
this.viewModelVisibility = ko.observable(false);
|
||||
this.modalVisibility = ko.observable(false).extend({'rateLimit': 0});
|
||||
|
||||
this.viewModelDom = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.sPosition = '';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.sTemplate = '';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.viewModelName = '';
|
||||
|
||||
/**
|
||||
* @type {?}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.viewModelDom = null;
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.viewModelTemplate = function ()
|
||||
{
|
||||
return this.sTemplate;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
KnoinAbstractViewModel.prototype.viewModelPosition = function ()
|
||||
{
|
||||
return this.sPosition;
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.cancelCommand = KnoinAbstractViewModel.prototype.closeCommand = function ()
|
||||
{
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.storeAndSetKeyScope = function ()
|
||||
{
|
||||
this.sCurrentKeyScope = RL.data().keyScope(); // TODO cjs
|
||||
RL.data().keyScope(this.sDefaultKeyScope); // TODO cjs
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.restoreKeyScope = function ()
|
||||
{
|
||||
RL.data().keyScope(this.sCurrentKeyScope); // TODO cjs
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.registerPopupKeyDown = function ()
|
||||
{
|
||||
var self = this;
|
||||
$window.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 = KnoinAbstractViewModel;
|
||||
|
||||
}(module));
|
||||
Loading…
Add table
Add a link
Reference in a new issue