snappymail/dev/Knoin/AbstractView.js

130 lines
2.5 KiB
JavaScript
Raw Normal View History

2014-08-20 23:03:12 +08:00
2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-20 23:03:12 +08:00
var
2014-08-25 23:49:01 +08:00
ko = require('ko'),
2014-08-25 15:10:51 +08:00
2014-09-05 06:49:03 +08:00
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Globals = require('Common/Globals')
2014-08-20 23:03:12 +08:00
;
/**
* @constructor
2014-08-20 23:03:12 +08:00
* @param {string=} sPosition = ''
* @param {string=} sTemplate = ''
*/
function AbstractView(sPosition, sTemplate)
2014-08-20 23:03:12 +08:00
{
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 = [];
2014-08-20 23:03:12 +08:00
this.viewModelDom = null;
}
/**
* @type {boolean}
*/
AbstractView.prototype.bDisabeCloseOnEsc = false;
2014-08-20 23:03:12 +08:00
/**
* @type {string}
*/
AbstractView.prototype.sPosition = '';
2014-08-20 23:03:12 +08:00
/**
* @type {string}
*/
AbstractView.prototype.sTemplate = '';
2014-08-20 23:03:12 +08:00
/**
* @type {string}
*/
AbstractView.prototype.sDefaultKeyScope = Enums.KeyState.None;
/**
* @type {string}
*/
AbstractView.prototype.sCurrentKeyScope = Enums.KeyState.None;
2014-08-20 23:03:12 +08:00
/**
* @type {string}
*/
AbstractView.prototype.viewModelName = '';
2014-08-20 23:03:12 +08:00
/**
* @type {Array}
*/
AbstractView.prototype.viewModelNames = [];
2014-08-20 23:03:12 +08:00
/**
* @type {?}
*/
AbstractView.prototype.viewModelDom = null;
2014-08-20 23:03:12 +08:00
/**
* @return {string}
*/
AbstractView.prototype.viewModelTemplate = function ()
2014-08-20 23:03:12 +08:00
{
return this.sTemplate;
};
/**
* @return {string}
*/
AbstractView.prototype.viewModelPosition = function ()
2014-08-20 23:03:12 +08:00
{
return this.sPosition;
};
AbstractView.prototype.cancelCommand = function () {};
AbstractView.prototype.closeCommand = function () {};
2014-08-20 23:03:12 +08:00
AbstractView.prototype.storeAndSetKeyScope = function ()
2014-08-20 23:03:12 +08:00
{
2014-08-22 23:08:56 +08:00
this.sCurrentKeyScope = Globals.keyScope();
Globals.keyScope(this.sDefaultKeyScope);
2014-08-20 23:03:12 +08:00
};
AbstractView.prototype.restoreKeyScope = function ()
2014-08-20 23:03:12 +08:00
{
2014-08-22 23:08:56 +08:00
Globals.keyScope(this.sCurrentKeyScope);
2014-08-20 23:03:12 +08:00
};
AbstractView.prototype.registerPopupKeyDown = function ()
2014-08-20 23:03:12 +08:00
{
var self = this;
2014-08-25 15:10:51 +08:00
2014-09-02 00:05:32 +08:00
Globals.$win.on('keydown', function (oEvent) {
2014-08-20 23:03:12 +08:00
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;
2014-08-20 23:03:12 +08:00
2014-09-05 06:49:03 +08:00
}());