* WIP ViewController.loadFromMCIMapAndConfig()

This commit is contained in:
Bryan Ashby 2015-03-27 18:02:00 -06:00
parent cca9334bd3
commit 8c9b0e729f
5 changed files with 96 additions and 9 deletions

View File

@ -122,4 +122,3 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
return view;
};

View File

@ -85,9 +85,9 @@ function getFormConfig(menuConfig, mciMap, cb) {
function filtered(form) {
if(form.length > 0) {
assert(1 === form.length);
cb(form[0]);
cb(null, form[0]);
} else {
cb(null);
cb(new Error('No matching form configuration found'));
}
}
);

View File

@ -5,6 +5,9 @@ var events = require('events');
var util = require('util');
var assert = require('assert');
var MCIViewFactory = require('./mci_view_factory.js').MCIViewFactory;
var menuUtil = require('./menu_util.js');
var async = require('async');
exports.ViewController = ViewController;
@ -200,3 +203,67 @@ ViewController.prototype.loadFromMCIMap = function(mciMap) {
});
};
ViewController.prototype.loadFromMCIMapAndConfig = function(mciMap, menuConfig, cb) {
var factory = new MCIViewFactory(this.client);
var self = this;
async.waterfall(
[
function getFormConfig(callback) {
menuUtil.getFormConfig(menuConfig, mciMap, function onFormConfig(err, formConfig) {
if(err) {
// :TODO: Log about missing form config -- this is not fatal, however
}
callback(null, formConfig);
});
},
function createViewsFromMCIMap(formConfig, callback) {
async.each(Object.keys(mciMap), function onMciEntry(name, eachCb) {
var mci = mciMap[name];
var view = factory.createFromMCI(mci);
if(view) {
view.on('action', self.onViewAction);
self.addView(view);
view.redraw(); // :TODO: This can result in double redraw() if we set focus on this item after
}
eachCb(null);
},
function eachMciComplete(err) {
self.setViewOrder();
callback(err, formConfig);
});
},
function applyFormConfig(formConfig, callback) {
async.each(Object.keys(formConfig.mci), function onMciConf(mci, eachCb) {
var viewId = parseInt(mci[2]); // :TODO: what about auto-generated ID's? Do they simply not apply to menu configs?
var mciConf = formConfig.mci[mci];
// :TODO: Break all of this up ... and/or better way of doing it
if(mciConf.items) {
self.getView(viewId).setItems(mciConf.items);
}
if(mciConf.submit) {
self.getView(viewId).submit = true; // :TODO: should really be actual value
}
if(mciConf.focus) {
self.switchFocus(viewId);
}
eachCb(null);
},
function eachMciConfComplete(err) {
callback(err);
});
}
],
function complete(err) {
if(cb) {
cb(err);
}
}
);
};

View File

@ -7,10 +7,12 @@
"form" : [
{
"mciReq" : [ "VM1" ],
"VM1" : {
"submit" : true,
"focus" : true,
"items" : [ "Login", "Apply", "Log Off" ]
"mci" : {
"VM1" : {
"submit" : true,
"focus" : true,
"items" : [ "Login", "Apply", "Log Off" ]
}
}
}
]

View File

@ -36,16 +36,35 @@ StandardMenuModule.prototype.mciReady = function(mciMap) {
var self = this;
menuUtil.getFormConfig(self.menuConfig, mciMap, function onFormConfig(formConfig) {
var vc = self.addViewController(new ViewController(self.client));
vc.loadFromMCIMapAndConfig(mciMap, self.menuConfig, function onViewReady(err) {
if(err) {
console.log(err);
} else {
// vc.switchFocus(1);
}
});
/*
menuUtil.getFormConfig(self.menuConfig, mciMap, function onFormConfig(err, formConfig) {
console.log(formConfig);
var vc = self.addViewController(new ViewController(self.client));
vc.loadFromMCIMap(mciMap);
vc.setViewOrder();
vc.getView(1).setItems(['Login', 'New User', 'Goodbye!']);
Object.keys(formConfig.mci).forEach(function onFormMci(mci) {
var viewId = parseInt(mci[2]);
if(formConfig.mci[mci].items && formConfig.mci[mci].items.length > 0) {
vc.getView(viewId).setItems(formConfig.mci[mci].items);
}
});
//vc.getView(1).setItems(['Login', 'New User', 'Goodbye!']);
vc.getView(1).submit = true;
vc.switchFocus(1);
});
*/
/*
{