Many updates to view validation framework

This commit is contained in:
Bryan Ashby 2015-12-10 21:45:02 -07:00
parent 490d71c180
commit cb3ae84bc5
1 changed files with 27 additions and 8 deletions

View File

@ -72,6 +72,7 @@ function ViewController(options) {
case 'accept' :
if(self.focusedView && self.focusedView.submit) {
// :TODO: need to do validation here!!!
self.submitForm(key);
} else {
self.nextFocus();
@ -161,6 +162,10 @@ function ViewController(options) {
// :TODO: handle propAsset.location for @method script specification
if('systemMethod' === propAsset.type) {
// :TODO: implementation validation @systemMethod handling!
var methodModule = require(paths.join(__dirname, 'system_view_validate.js'));
if(_.isFunction(methodModule[propAsset.asset])) {
propValue = methodModule[propAsset.asset];
}
} else {
if(_.isFunction(self.client.currentMenuModule.menuMethods[propAsset.asset])) {
propValue = self.client.currentMenuModule.menuMethods[propAsset.asset];
@ -391,14 +396,28 @@ ViewController.prototype.switchFocus = function(id) {
if(focusedView && focusedView.validate) {
focusedView.validate(focusedView.getData(), function validated(isValid, msgProp) {
if(isValid) {
performSwitch();
} else {
if(_.isFunction(self.client.currentMenuModule.menuMethods.validationFailure)) {
self.client.currentMenuModule.menuMethods.validationFailure(focusedView, msgProp, function validateFailNext() {
focusedView.validate(focusedView.getData(), function validated(err) {
if(_.isFunction(self.client.currentMenuModule.menuMethods.viewValidationListener)) {
if(err) {
err.view = focusedView;
}
self.client.currentMenuModule.menuMethods.viewValidationListener(err, function validateComplete(newFocusId) {
if(err) {
// :TODO: switchFocus() really needs a cb --
var newFocusView;
if(newFocusId) {
newFocusView = self.getView(newFocusId) || focusedView;
}
self.setViewFocusWithEvents(newFocusView, true);
} else {
performSwitch();
}
});
} else {
if(!err) {
performSwitch();
}
}
});