* Cleaner action block discovery for 'submit'
* Allow "embedded" prompts to use form action matching
This commit is contained in:
parent
3e06e2fa6b
commit
ab9ffc715a
|
@ -32,15 +32,17 @@ function ViewController(options) {
|
||||||
this.formId = options.formId || 0;
|
this.formId = options.formId || 0;
|
||||||
this.mciViewFactory = new MCIViewFactory(this.client); // :TODO: can this not be a singleton?
|
this.mciViewFactory = new MCIViewFactory(this.client); // :TODO: can this not be a singleton?
|
||||||
this.noInput = _.isBoolean(options.noInput) ? options.noInput : false;
|
this.noInput = _.isBoolean(options.noInput) ? options.noInput : false;
|
||||||
|
|
||||||
this.actionKeyMap = {};
|
this.actionKeyMap = {};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Small wrapper/proxy around handleAction() to ensure we do not allow
|
// Small wrapper/proxy around handleAction() to ensure we do not allow
|
||||||
// input/additional actions queued while performing an action
|
// input/additional actions queued while performing an action
|
||||||
//
|
//
|
||||||
this.handleActionWrapper = function(formData, actionBlock) {
|
this.handleActionWrapper = function(formData, actionBlock, cb) {
|
||||||
if(self.waitActionCompletion) {
|
if(self.waitActionCompletion) {
|
||||||
|
if(cb) {
|
||||||
|
return cb(null);
|
||||||
|
}
|
||||||
return; // ignore until this is finished!
|
return; // ignore until this is finished!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +58,9 @@ function ViewController(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.waitActionCompletion = false;
|
self.waitActionCompletion = false;
|
||||||
|
if(cb) {
|
||||||
|
return cb(null);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -570,34 +575,51 @@ ViewController.prototype.loadFromPromptConfig = function(options, cb) {
|
||||||
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');
|
||||||
|
|
||||||
|
const doSubmitNotify = () => {
|
||||||
|
if(options.submitNotify) {
|
||||||
|
options.submitNotify();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleIt = (fd, conf) => {
|
||||||
|
self.handleActionWrapper(fd, conf, () => {
|
||||||
|
doSubmitNotify();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if(_.isString(self.client.currentMenuModule.menuConfig.action)) {
|
if(_.isString(self.client.currentMenuModule.menuConfig.action)) {
|
||||||
self.handleActionWrapper(formData, self.client.currentMenuModule.menuConfig);
|
handleIt(formData, self.client.currentMenuModule.menuConfig);
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// Menus that reference prompts can have a sepcial "submit" block without the
|
// Menus that reference prompts can have a special "submit" block without the
|
||||||
// hassle of by-form-id configurations, etc.
|
// hassle of by-form-id configurations, etc.
|
||||||
//
|
//
|
||||||
// "submit" : [
|
// "submit" : [
|
||||||
// { ... }
|
// { ... }
|
||||||
// ]
|
// ]
|
||||||
//
|
//
|
||||||
var menuSubmit = self.client.currentMenuModule.menuConfig.submit;
|
const menuConfig = self.client.currentMenuModule.menuConfig;
|
||||||
if(!_.isArray(menuSubmit)) {
|
let submitConf;
|
||||||
self.client.log.debug('No configuration to handle submit');
|
if(Array.isArray(menuConfig.submit)) { // standalone prompts)) {
|
||||||
return;
|
submitConf = menuConfig.submit;
|
||||||
|
} else {
|
||||||
|
// look for embedded prompt configurations - using their own form ID within the menu
|
||||||
|
submitConf =
|
||||||
|
_.get(menuConfig, [ 'form', formData.id, 'submit', formData.submitId ]) ||
|
||||||
|
_.get(menuConfig, [ 'form', formData.id, 'submit', '*' ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
if(!Array.isArray(submitConf)) {
|
||||||
// Locate matching action block
|
doSubmitNotify();
|
||||||
//
|
return self.client.log.debug('No configuration to handle submit');
|
||||||
// :TODO: this is basically the same as for menus -- DRY it up!
|
}
|
||||||
for(var c = 0; c < menuSubmit.length; ++c) {
|
|
||||||
var actionBlock = menuSubmit[c];
|
|
||||||
|
|
||||||
if(_.isEqualWith(formData.value, actionBlock.value, self.actionBlockValueComparator)) {
|
// locate any matching action block
|
||||||
self.handleActionWrapper(formData, actionBlock);
|
const actionBlock = submitConf.find(actionBlock => _.isEqualWith(formData.value, actionBlock.value, self.actionBlockValueComparator));
|
||||||
break; // there an only be one...
|
if(actionBlock) {
|
||||||
}
|
handleIt(formData, actionBlock);
|
||||||
|
} else {
|
||||||
|
doSubmitNotify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -732,27 +754,18 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
|
||||||
//
|
//
|
||||||
// Locate configuration for this form ID
|
// Locate configuration for this form ID
|
||||||
//
|
//
|
||||||
var confForFormId;
|
const confForFormId =
|
||||||
if(_.isObject(formConfig.submit[formData.submitId])) {
|
_.get(formConfig, [ 'submit', formData.submitId ]) ||
|
||||||
confForFormId = formConfig.submit[formData.submitId];
|
_.get(formConfig, [ 'submit', '*' ]);
|
||||||
} else if(_.isObject(formConfig.submit['*'])) {
|
|
||||||
confForFormId = formConfig.submit['*'];
|
if(!Array.isArray(confForFormId)) {
|
||||||
} else {
|
return self.client.log.debug( { formId : formData.submitId }, 'No configuration for form ID');
|
||||||
// no configuration for this submitId
|
|
||||||
self.client.log.debug( { formId : formData.submitId }, 'No configuration for form ID');
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// locate a matching action block, if any
|
||||||
// Locate a matching action block based on the submitted data
|
const actionBlock = confForFormId.find(actionBlock => _.isEqualWith(formData.value, actionBlock.value, self.actionBlockValueComparator));
|
||||||
//
|
if(actionBlock) {
|
||||||
for(var c = 0; c < confForFormId.length; ++c) {
|
self.handleActionWrapper(formData, actionBlock);
|
||||||
var actionBlock = confForFormId[c];
|
|
||||||
|
|
||||||
if(_.isEqualWith(formData.value, actionBlock.value, self.actionBlockValueComparator)) {
|
|
||||||
self.handleActionWrapper(formData, actionBlock);
|
|
||||||
break; // there an only be one...
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue