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
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
2014-09-02 08:15:31 +08:00
|
|
|
* @constructor
|
2014-08-20 23:03:12 +08:00
|
|
|
* @param {string=} sPosition = ''
|
|
|
|
* @param {string=} sTemplate = ''
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
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});
|
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
this.viewModelName = '';
|
|
|
|
this.viewModelNames = [];
|
2014-08-20 23:03:12 +08:00
|
|
|
this.viewModelDom = null;
|
|
|
|
}
|
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.bDisabeCloseOnEsc = false;
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.sPosition = '';
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.sTemplate = '';
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.sDefaultKeyScope = Enums.KeyState.None;
|
2014-09-02 08:15:31 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.sCurrentKeyScope = Enums.KeyState.None;
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.viewModelName = '';
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
/**
|
|
|
|
* @type {Array}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.viewModelNames = [];
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @type {?}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.viewModelDom = null;
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.viewModelTemplate = function ()
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
return this.sTemplate;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.viewModelPosition = function ()
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
return this.sPosition;
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.prototype.cancelCommand = function () {};
|
|
|
|
AbstractView.prototype.closeCommand = function () {};
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +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
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +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
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +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;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
module.exports = AbstractView;
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|