snappymail/dev/Knoin/AbstractScreen.js

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