2014-08-20 23:03:12 +08:00
|
|
|
/* 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'),
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
Utils = require('../Common/Utils.js'),
|
2014-08-22 23:08:56 +08:00
|
|
|
Enums = require('../Common/Enums.js'),
|
|
|
|
Globals = require('../Common/Globals.js')
|
2014-08-20 23:03:12 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
};
|
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
KnoinAbstractViewModel.prototype.cancelCommand = function () {};
|
|
|
|
KnoinAbstractViewModel.prototype.closeCommand = function () {};
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
KnoinAbstractViewModel.prototype.storeAndSetKeyScope = function ()
|
|
|
|
{
|
2014-08-22 23:08:56 +08:00
|
|
|
this.sCurrentKeyScope = Globals.keyScope();
|
|
|
|
Globals.keyScope(this.sDefaultKeyScope);
|
2014-08-20 23:03:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
KnoinAbstractViewModel.prototype.restoreKeyScope = function ()
|
|
|
|
{
|
2014-08-22 23:08:56 +08:00
|
|
|
Globals.keyScope(this.sCurrentKeyScope);
|
2014-08-20 23:03:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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));
|