From cb3ae84bc572c33c6a1eeea77906555e2f33fe1e Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 10 Dec 2015 21:45:02 -0700 Subject: [PATCH] Many updates to view validation framework --- core/view_controller.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/core/view_controller.js b/core/view_controller.js index caef9e0f..02b13b83 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -70,8 +70,9 @@ function ViewController(options) { self.nextFocus(); break; - case 'accept' : + 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(); + 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(_.isFunction(self.client.currentMenuModule.menuMethods.validationFailure)) { - self.client.currentMenuModule.menuMethods.validationFailure(focusedView, msgProp, function validateFailNext() { - - }); + if(!err) { + performSwitch(); } } });