* Work with prompts. Prompts now handle special menu "submit" block without form IDs/etc.
This commit is contained in:
parent
a0a97350fe
commit
b8d4741c18
|
@ -107,7 +107,6 @@ function Client(input, output) {
|
||||||
//
|
//
|
||||||
// Every 1m, check for idle.
|
// Every 1m, check for idle.
|
||||||
//
|
//
|
||||||
console.log('idleLogoutSeconds=' + Config.misc.idleLogoutSeconds)
|
|
||||||
this.idleCheck = setInterval(function checkForIdle() {
|
this.idleCheck = setInterval(function checkForIdle() {
|
||||||
var nowMs = Date.now();
|
var nowMs = Date.now();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ MCIViewFactory.prototype.getPredefinedViewLabel = function(code) {
|
||||||
UW : this.client.user.properties.web_address,
|
UW : this.client.user.properties.web_address,
|
||||||
UF : this.client.user.properties.affiliation,
|
UF : this.client.user.properties.affiliation,
|
||||||
UT : this.client.user.properties.theme_id,
|
UT : this.client.user.properties.theme_id,
|
||||||
MS : moment(this.client.user.properties.timestamp).format(this.client.currentTheme.helpers.getDateFormat()),
|
MS : moment(this.client.user.properties.account_created).format(this.client.currentTheme.helpers.getDateFormat()),
|
||||||
|
|
||||||
|
|
||||||
SH : this.client.term.termHeight.toString(),
|
SH : this.client.term.termHeight.toString(),
|
||||||
|
|
|
@ -252,6 +252,42 @@ function ViewController(options) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// method for comparing submitted form data to configuration entries
|
||||||
|
this.actionBlockValueComparator = function(formValue, actionValue) {
|
||||||
|
//
|
||||||
|
// For a match to occur, one of the following must be true:
|
||||||
|
//
|
||||||
|
// * actionValue is a Object:
|
||||||
|
// a) All key/values must exactly match
|
||||||
|
// b) value is null; The key (view ID or "argName") must be present
|
||||||
|
// in formValue. This is a wildcard/any match.
|
||||||
|
// * actionValue is a Number: This represents a view ID that
|
||||||
|
// must be present in formValue.
|
||||||
|
// * actionValue is a string: This represents a view with
|
||||||
|
// "argName" set that must be present in formValue.
|
||||||
|
//
|
||||||
|
if(_.isNumber(actionValue) || _.isString(actionValue)) {
|
||||||
|
if(_.isUndefined(formValue[actionValue])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var actionValueKeys = Object.keys(actionValue);
|
||||||
|
for(var i = 0; i < actionValueKeys.length; ++i) {
|
||||||
|
var viewId = actionValueKeys[i];
|
||||||
|
if(!_.has(formValue, viewId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(null !== actionValue[viewId] && actionValue[viewId] !== formValue[viewId]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.client.log.trace( { formValue : formValue, actionValue : actionValue }, 'Action match');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
if(!options.detached) {
|
if(!options.detached) {
|
||||||
this.attachClientEvents();
|
this.attachClientEvents();
|
||||||
}
|
}
|
||||||
|
@ -334,7 +370,7 @@ ViewController.prototype.switchFocus = function(id) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ViewController.prototype.nextFocus = function() {
|
ViewController.prototype.nextFocus = function() {
|
||||||
if(!this.focusedView) {
|
if(!this.focusedView) {
|
||||||
this.switchFocus(this.views[this.firstId].id);
|
this.switchFocus(this.views[this.firstId].id);
|
||||||
} else {
|
} else {
|
||||||
|
@ -421,12 +457,41 @@ ViewController.prototype.loadFromPromptConfig = function(options, cb) {
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function prepareFormSubmission(callback) {
|
function prepareFormSubmission(callback) {
|
||||||
if(false === self.noInput) {
|
if(false === self.noInput) {
|
||||||
self.on('submit', function promptSubmit(formData) {
|
self.on('submit', function promptSubmit(formData) {
|
||||||
self.client.log.trace( { formData : self.getLogFriendlyFormData(formData) }, 'Prompt submit');
|
self.client.log.trace( { formData : self.getLogFriendlyFormData(formData) }, 'Prompt submit');
|
||||||
|
|
||||||
menuUtil.handleAction(self.client, formData, self.client.currentMenuModule.menuConfig);
|
if(_.isString(self.client.currentMenuModule.menuConfig.action)) {
|
||||||
|
menuUtil.handleAction(self.client, formData, self.client.currentMenuModule.menuConfig);
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
// Menus that reference prompts can have a sepcial "submit" block without the
|
||||||
|
// hassle of by-form-id configurations, etc.
|
||||||
|
//
|
||||||
|
// "submit" : [
|
||||||
|
// { ... }
|
||||||
|
// ]
|
||||||
|
//
|
||||||
|
var menuSubmit = self.client.currentMenuModule.menuConfig.submit;
|
||||||
|
if(!_.isArray(menuSubmit)) {
|
||||||
|
self.client.log.debug('No configuration to handle submit');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate matching action block
|
||||||
|
//
|
||||||
|
// :TODO: this is bacially the same as for menus -- DRY it up!
|
||||||
|
for(var c = 0; c < menuSubmit.length; ++c) {
|
||||||
|
var actionBlock = menuSubmit[c];
|
||||||
|
|
||||||
|
if(_.isEqual(formData.value, actionBlock.value, self.actionBlockValueComparator)) {
|
||||||
|
menuUtil.handleAction(self.client, formData, actionBlock);
|
||||||
|
break; // there an only be one...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,6 +526,7 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
|
||||||
// :TODO: honor options.withoutForm
|
// :TODO: honor options.withoutForm
|
||||||
|
|
||||||
// method for comparing submitted form data to configuration entries
|
// method for comparing submitted form data to configuration entries
|
||||||
|
/*
|
||||||
var actionBlockValueComparator = function(formValue, actionValue) {
|
var actionBlockValueComparator = function(formValue, actionValue) {
|
||||||
//
|
//
|
||||||
// For a match to occur, one of the following must be true:
|
// For a match to occur, one of the following must be true:
|
||||||
|
@ -495,6 +561,7 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
|
||||||
self.client.log.trace( { formValue : formValue, actionValue : actionValue }, 'Action match');
|
self.client.log.trace( { formValue : formValue, actionValue : actionValue }, 'Action match');
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
|
@ -569,7 +636,7 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
|
||||||
for(var c = 0; c < confForFormId.length; ++c) {
|
for(var c = 0; c < confForFormId.length; ++c) {
|
||||||
var actionBlock = confForFormId[c];
|
var actionBlock = confForFormId[c];
|
||||||
|
|
||||||
if(_.isEqual(formData.value, actionBlock.value, actionBlockValueComparator)) {
|
if(_.isEqual(formData.value, actionBlock.value, self.actionBlockValueComparator)) {
|
||||||
menuUtil.handleAction(self.client, formData, actionBlock);
|
menuUtil.handleAction(self.client, formData, actionBlock);
|
||||||
break; // there an only be one...
|
break; // there an only be one...
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -220,6 +220,7 @@
|
||||||
"mainMenu" : {
|
"mainMenu" : {
|
||||||
"art" : "MAINMENU",
|
"art" : "MAINMENU",
|
||||||
"options" : { "cls" : true },
|
"options" : { "cls" : true },
|
||||||
|
/*
|
||||||
"form" : {
|
"form" : {
|
||||||
"0" : {
|
"0" : {
|
||||||
"ET" : {
|
"ET" : {
|
||||||
|
@ -254,7 +255,26 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},*/
|
||||||
|
"prompt" : "menuCommand",
|
||||||
|
"submit" : [
|
||||||
|
{
|
||||||
|
"value" : { "command" : "G" },
|
||||||
|
"action" : "@menu:logoff"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value" : { "command" : "D" },
|
||||||
|
"action" : "@menu:doorPimpWars"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value" : { "command" : "L" },
|
||||||
|
"action" : "@menu:doorLORD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value" : 1,
|
||||||
|
"action" : "@menu:mainMenu"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"doorPimpWars" : {
|
"doorPimpWars" : {
|
||||||
"module" : "abracadabra",
|
"module" : "abracadabra",
|
||||||
|
|
|
@ -15,6 +15,22 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"menuCommand" : {
|
||||||
|
"art" : "menu_prompt.ans",
|
||||||
|
"mci" : {
|
||||||
|
"ET2" : {
|
||||||
|
"argName" : "command",
|
||||||
|
"width" : 20,
|
||||||
|
"maxLength" : 20,
|
||||||
|
"submit" : true,
|
||||||
|
"textStyle" : "U",
|
||||||
|
"focus" : true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// Standard / Required
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
"pause" : {
|
"pause" : {
|
||||||
//
|
//
|
||||||
// Any menu 'pause' will use this prompt
|
// Any menu 'pause' will use this prompt
|
||||||
|
@ -40,7 +56,8 @@
|
||||||
* echoKey : false
|
* echoKey : false
|
||||||
|
|
||||||
*/
|
*/
|
||||||
}/*,
|
}
|
||||||
|
/*,
|
||||||
"standard" : {
|
"standard" : {
|
||||||
// any menu 'pause' will display this, pause for a key, then erase and move on
|
// any menu 'pause' will display this, pause for a key, then erase and move on
|
||||||
"pause" : {
|
"pause" : {
|
||||||
|
|
Loading…
Reference in New Issue