diff --git a/core/mci_view_factory.js b/core/mci_view_factory.js index 1b0f700d..fbfb175c 100644 --- a/core/mci_view_factory.js +++ b/core/mci_view_factory.js @@ -122,4 +122,3 @@ MCIViewFactory.prototype.createFromMCI = function(mci) { return view; }; - diff --git a/core/menu_util.js b/core/menu_util.js index 634fd9e0..79fc1e80 100644 --- a/core/menu_util.js +++ b/core/menu_util.js @@ -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')); } } ); diff --git a/core/view_controller.js b/core/view_controller.js index 6315c9b3..cfd2c030 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -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); + } + } + ); +}; diff --git a/mods/menu.json b/mods/menu.json index fe33e05c..8f3ac6e0 100644 --- a/mods/menu.json +++ b/mods/menu.json @@ -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" ] + } } } ] diff --git a/mods/standard_menu.js b/mods/standard_menu.js index ac7cad48..e8467949 100644 --- a/mods/standard_menu.js +++ b/mods/standard_menu.js @@ -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); }); +*/ /* {