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-09-02 08:15:31 +08:00
|
|
|
_ = require('_'),
|
2014-08-25 23:49:01 +08:00
|
|
|
crossroads = require('crossroads'),
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Utils = require('Common/Utils')
|
2014-08-20 23:03:12 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} sScreenName
|
|
|
|
* @param {?=} aViewModels = []
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
function AbstractScreen(sScreenName, aViewModels)
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
this.sScreenName = sScreenName;
|
|
|
|
this.aViewModels = Utils.isArray(aViewModels) ? aViewModels : [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Array}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractScreen.prototype.oCross = null;
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractScreen.prototype.sScreenName = '';
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Array}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractScreen.prototype.aViewModels = [];
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {Array}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractScreen.prototype.viewModels = function ()
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
return this.aViewModels;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractScreen.prototype.screenName = function ()
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
return this.sScreenName;
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractScreen.prototype.routes = function ()
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {?Object}
|
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractScreen.prototype.__cross = function ()
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
return this.oCross;
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractScreen.prototype.__start = function ()
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
module.exports = AbstractScreen;
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|