lazo-next
Version:
A client-server web framework built on Node.js that allows front-end developers to easily create a 100% SEO compliant, component MVC structured web application with an optimized first page load.
62 lines (49 loc) • 2.12 kB
JavaScript
define(['underscore', 'lazoModel'], function (_, Model) {
'use strict';
return {
serialize: function (ctl, rootCtx) {
var serObj = {},
viewRef,
omit = rootCtx ? ['cookies', '_request', '_reply', 'models', 'collections', 'location', 'userAgent'] :
['cookies', '_request', '_reply', 'models', 'collections', '_rootCtx', 'location', 'userAgent'];
serObj.cid = ctl.cid;
serObj.ctx = _.omit(ctl.ctx, omit);
serObj.ctx.models = {};
serObj.ctx.collections = {};
serObj.isBase = ctl.isBase;
serObj.name = ctl.name;
if (ctl.currentView && ctl.currentView) {
viewRef = ctl.currentView.ref;
serObj.currentView = {
cid: ctl.currentView.cid,
name: ctl.currentView.name,
ref: ctl.currentView.ref,
templatePath: ctl.currentView.templatePath,
compiledTemplatePath: ctl.currentView.compiledTemplatePath,
basePath: ctl.currentView.basePath,
isBase: ctl.currentView.isBase,
hasTemplate: ctl.currentView.hasTemplate
};
}
//children
var serializedKids = {};
_.each(ctl.children, function (regionChildren, region) {
var comps = [];
_.each(regionChildren, function (child) {
comps.push(child.toJSON());
});
serializedKids[region] = comps;
});
serObj.children = serializedKids;
//models
Model._serialize(ctl.ctx.models, serObj.ctx.models);
Model._serialize(ctl.ctx.collections, serObj.ctx.collections);
_.each(ctl.ctx.collections, function (value, key, list) {
serObj.ctx.collections[key] = value._getGlobalId();
});
return serObj;
},
deserialize: function (ctl, options) {
}
};
});