* WIP on standard menu and menu.json MCI / form mapping. Much to do...

This commit is contained in:
Bryan Ashby 2015-03-26 22:58:22 -06:00
parent 4c4b0de54c
commit cca9334bd3
4 changed files with 180 additions and 2 deletions

View File

@ -9,9 +9,12 @@ var conf = require('./config.js');
var fs = require('fs');
var paths = require('path');
var async = require('async');
var assert = require('assert');
var stripJsonComments = require('strip-json-comments');
exports.loadMenu = loadMenu;
exports.getFormConfig = getFormConfig;
function loadMenu(name, client, cb) {
/*
@ -59,3 +62,52 @@ function loadMenu(name, client, cb) {
}
);
}
function getFormConfig(menuConfig, mciMap, cb) {
async.filter(
menuConfig.form,
function check(form, callback) {
if(!form.mciReq || form.mciReq.length <= 0) {
callback(false);
return;
}
var count = form.mciReq.length;
for(var i = 0; i < count; ++i) {
if(!mciMap[form.mciReq[i]]) {
callback(false);
}
}
callback(true);
},
function filtered(form) {
if(form.length > 0) {
assert(1 === form.length);
cb(form[0]);
} else {
cb(null);
}
}
);
}
/*
function getFormConfig(menuConfig, mciMap) {
var count = menuConfig.form ? menuConfig.form.length : 0;
var mciReq;
for(var i = 0; i < count; ++i) {
mciReq = menuConfig.form[i].mciReq;
if(mciReq) {
if(mciReq.length === mciMap.length) {
for(var m = 0; m < mciReq.length; ++m) {
if(!mciMap[mciReq[m]]) {
return null;
}
}
}
}
}
}
*/

View File

@ -35,5 +35,7 @@ LogOffModule.prototype.mciReady = function(mciMap) {
LogOffModule.prototype.finishedLoading = function() {
LogOffModule.super_.prototype.finishedLoading.call(this);
this.client.term.write(ansi.normal() + '\nATH0\n');
this.client.end();
};

View File

@ -4,7 +4,17 @@
*/
"matrix" : {
"art" : "matrix",
"module" : "matrix"
"form" : [
{
"mciReq" : [ "VM1" ],
"VM1" : {
"submit" : true,
"focus" : true,
"items" : [ "Login", "Apply", "Log Off" ]
}
}
]
//"module" : "matrix"
},
"login" : {
"art" : "login",

114
mods/standard_menu.js Normal file
View File

@ -0,0 +1,114 @@
/* jslint node: true */
'use strict';
var ansi = require('../core/ansi_term.js');
var MenuModule = require('../core/menu_module.js').MenuModule;
var ViewController = require('../core/view_controller.js').ViewController;
var menuUtil = require('../core/menu_util.js');
exports.getModule = StandardMenuModule;
exports.moduleInfo = {
name : 'Standard Menu Module',
desc : 'Menu module handling most standard stuff',
author : 'NuSkooler',
};
function StandardMenuModule(menuConfig) {
MenuModule.call(this, menuConfig);
}
require('util').inherits(StandardMenuModule, MenuModule);
StandardMenuModule.prototype.enter = function(client) {
StandardMenuModule.super_.prototype.enter.call(this, client);
};
StandardMenuModule.prototype.beforeArt = function() {
StandardMenuModule.super_.prototype.beforeArt.call(this);
this.client.term.write(ansi.resetScreen()); // :TODO: this should be optional
};
StandardMenuModule.prototype.mciReady = function(mciMap) {
StandardMenuModule.super_.prototype.mciReady.call(this, mciMap);
var self = this;
menuUtil.getFormConfig(self.menuConfig, mciMap, function onFormConfig(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!']);
vc.getView(1).submit = true;
vc.switchFocus(1);
});
/*
{
"menuName" : {
"form" : [
{
"mciReq" : [ "MC1", "MC2", ... ],
"MC1" : {
"text" : "...",
"focus" : true,
"submit" : true,
},
}
]
}
}*/
/*
if(mciMap.ET1 && mciMap.ET2 && mciMap.BN1 && mciMap.BN2 && mciMap.BN3) {
//
// Form via EditTextViews and ButtonViews
// * ET1 - userName
// * ET2 - password
// * BN1 - Login
// * BN2 - New
// * BN3 - Bye!
//
} else if(mciMap.VM1) {
//
// Menu via VerticalMenuView
//
// * VM1 - menu with the following items:
// 0 - Login
// 1 - New
// 2 - Bye!
//
//var vc = new ViewController(client);
var vc = self.addViewController(new ViewController(self.client));
vc.on('submit', function onSubmit(form) {
console.log(form);
var viewModuleMap = {
'0' : 'login',
'1' : 'new',
'2' : 'logoff',
};
if(0 === form.id && 1 === form.submitId) {
console.log(viewModuleMap[form.values[1]]);
self.client.gotoMenuModule(viewModuleMap[form.values[1]]);
}
});
vc.loadFromMCIMap(mciMap);
vc.setViewOrder();
// :TODO: Localize
vc.getView(1).setItems(['Login', 'New User', 'Goodbye!']);
vc.getView(1).submit = true;
vc.switchFocus(1);
}
*/
};