* 'action' must be part of a *menu* not a prompt (they remain generic)

* Menus and prompts in better harmony
* Very eary WIP of converting login/apply/etc. to new system. These can now be helper scirpts and not full MenuModules (very simple!)
This commit is contained in:
Bryan Ashby 2015-04-19 22:58:18 -06:00
parent bac2f63c1a
commit 8db72430d3
7 changed files with 270 additions and 267 deletions

View file

@ -30,13 +30,13 @@ function ApplyModule(menuConfig) {
var self = this;
this.menuMethods.submitApplication = function(args) {
this.menuMethods.submitApplication = function(formData, extraArgs) {
var usernameView = self.viewController.getView(1);
var passwordView = self.viewController.getView(9);
var pwConfirmView = self.viewController.getView(10);
var statusView = self.viewController.getView(11);
self.validateApplication(args, function validated(errString, clearFields) {
self.validateApplication(formData, function validated(errString, clearFields) {
if(errString) {
statusView.setText(errString);
@ -47,15 +47,17 @@ function ApplyModule(menuConfig) {
self.viewController.switchFocus(clearFields[0]);
} else {
var newUser = new user.User();
newUser.username = args.username;
newUser.username = formData.value.username;
newUser.properties = {
real_name : args.realName,
age : args.age,
sex : args.sex,
location : args.location,
affiliation : args.affils,
email_address : args.email,
web_address : args.web,
real_name : formData.value.realName,
age : formData.value.age,
sex : formData.value.sex,
location : formData.value.location,
affiliation : formData.value.affils,
email_address : formData.value.email,
web_address : formData.value.web,
art_theme_id : Config.defaults.theme, // :TODO: allow '*' = random
account_status : user.User.AccountStatus.inactive,
@ -64,16 +66,16 @@ function ApplyModule(menuConfig) {
// :TODO: set account_status to default based on Config.user...
};
newUser.create({ password : args.pw }, function created(err) {
newUser.create({ password : formData.value.pw }, function created(err) {
if(err) {
self.client.gotoMenuModule( { name : args.next.error } );
self.client.gotoMenuModule( { name : extraArgs.error } );
} else {
Log.info( { username : args.username, userId : newUser.userId }, 'New user created');
Log.info( { username : formData.value.username, userId : newUser.userId }, 'New user created');
if(user.User.AccountStatus.inactive === self.client.user.properties.account_status) {
self.client.gotoMenuModule( { name : args.next.inactive } );
self.client.gotoMenuModule( { name : extraArgs.inactive } );
} else {
self.client.gotoMenuModule( { name : args.next.active } );
self.client.gotoMenuModule( { name : this.menuConfig.next } );
}
}
});
@ -81,34 +83,34 @@ function ApplyModule(menuConfig) {
});
};
this.validateApplication = function(args, cb) {
if(args.username.length < Config.users.usernameMin) {
this.validateApplication = function(formData, cb) {
if(formData.value.username.length < Config.users.usernameMin) {
cb('Handle too short!', [ 1 ]);
return;
}
if(args.username.length > Config.users.usernameMax) {
if(formData.value.username.length > Config.users.usernameMax) {
cb('Handle too long!', [ 1 ]);
return;
}
var re = new RegExp(Config.users.usernamePattern);
if(!re.test(args.username)) {
if(!re.test(formData.value.username)) {
cb('Handle contains invalid characters!', [ 1 ] );
return;
}
if(args.pw.length < Config.users.passwordMin) {
if(formData.value.pw.length < Config.users.passwordMin) {
cb('Password too short!', [ 9, 10 ]);
return;
}
if(args.pw !== args.pwConfirm) {
if(formData.value.pw !== formData.value.pwConfirm) {
cb('Passwords do not match!', [ 9, 10 ]);
return;
}
user.getUserIdAndName(args.username, function userIdAndName(err) {
user.getUserIdAndName(formData.value.username, function userIdAndName(err) {
var alreadyExists = !err;
if(alreadyExists) {
cb('Username unavailable!', [ 1 ] );
@ -129,13 +131,13 @@ ApplyModule.prototype.beforeArt = function() {
ApplyModule.super_.prototype.beforeArt.call(this);
};
ApplyModule.prototype.mciReady = function(mciMaps) {
ApplyModule.super_.prototype.mciReady.call(this, mciMaps);
ApplyModule.prototype.mciReady = function(mciData) {
ApplyModule.super_.prototype.mciReady.call(this, mciData);
var self = this;
self.viewController = self.addViewController(new ViewController({ client : self.client } ));
self.viewController.loadFromMCIMapAndConfig( { mciMap : mciMaps.menu, menuConfig : self.menuConfig }, function onViewReady(err) {
self.viewController.loadFromMCIMapAndConfig( { mciMap : mciData.menu, menuConfig : self.menuConfig }, function onViewReady(err) {
});
};

View file

@ -13,13 +13,13 @@ var async = require('async');
// :TODO: clean up requires
exports.moduleInfo = {
/*exports.moduleInfo = {
name : 'Login',
desc : 'Login Module',
author : 'NuSkooler',
};
};*/
exports.getModule = LoginModule;
//exports.getModule = LoginModule;
exports.attemptLogin = attemptLogin;
@ -52,7 +52,7 @@ function attemptLogin(callingMenu, formData, extraArgs) {
});
}
/*
function LoginModule(menuConfig) {
MenuModule.call(this, menuConfig);
@ -130,4 +130,5 @@ LoginModule.prototype.mciReady = function(mciData) {
self.viewController = self.addViewController(new ViewController( { client : self.client } ));
self.viewController.loadFromMCIMapAndConfig( { mciMap : mciData.menu, menuConfig : self.menuConfig }, function onViewReady(err) {
});
};
};
*/

View file

@ -66,59 +66,11 @@
}
},
"login" : {
//"art" : "login", // TODO: rename to login_form
// :TODO: may want { "prompt" : { "name" : "blah", "action" : ... }}
"prompt" : "userCredentials",
"fallback" : "matrix",
"next" : "newUserActive",
//"module" : "login",
/*
"form" : {
"0" : {
"BT3BT4ET1ET2TL5" :{
"mci" :{
// :TODO: LIke prompts, assign "argName" values here, e.g.:
// "argName" : "username", ...
"ET1" : {
"focus" : true
},
"BT3" : {
"submit" : true,
"text" : "Login"
},
"BT4" : {
"submit" : true,
"text" : "Cancel"
}
},
"submit" : {
"3" : [ // Login
{
"value" : { "3" : null },
"action" : "@method:attemptLogin",
// :TODO: see above about argName;
// any other args should be "extraArgs"
"args" : {
"next" : {
// :TODO: just use menu.next
"success" : "newUserActive"
},
"username" : "{1}",
"password" : "{2}"
}
}
],
"4" : [ // Cancel
{
"value" : { "4" : null },
"action" : "@menu:matrix"
// :TODO: Just use menu.fallback, e.g. @fallback
}
]
}
}
}
},
*/
"action" : "@method:login.js/attemptLogin",
"options" : {
"clearScreen" : true
}
@ -130,13 +82,24 @@
"apply" : {
"art" : "apply",
"module" : "apply",
"next" : "newUserActive",
"form" : {
"0" : {
"BT12BT13ET1ET10ET2ET3ET4ET5ET6ET7ET8ET9TL11" : {
"mci" : {
"ET1" : {
"focus" : true
"focus" : true,
"argName" : "username"
},
"ET2" : { "argName" : "realName" },
"ET3" : { "argName" : "age" },
"ET4" : { "argName" : "sex" },
"ET5" : { "argName" : "location" },
"ET6" : { "argName" : "affils" },
"ET7" : { "argName" : "email" },
"ET8" : { "argName" : "web" },
"ET9" : { "argName" : "pw" },
"ET10" : { "argName" : "pwConfirm" },
"BT12" : {
"submit" : true,
"text" : "Apply"
@ -151,23 +114,10 @@
{
"value" : { "12" : null },
"action" : "@method:submitApplication",
"args" : {
"next" : {
"inactive" : "userNeedsActivated",
"active" : "newUserActive",
"error" : "newUserCreateError"
},
"username" : "{1}",
"realName" : "{2}",
"age" : "{3}",
"sex" : "{4}",
"location" : "{5}",
"affils" : "{6}",
"email" : "{7}",
"web" : "{8}",
"pw" : "{9}",
"pwConfirm" : "{10}"
}
"extraArgs" : {
"inactive" : "userNeedsActivated",
"error" : "newUserCreateError"
}
}
],
"13" : [ // Cancel

View file

@ -6,6 +6,8 @@ var MenuModule = require('../core/menu_module.js').MenuModule;
var ViewController = require('../core/view_controller.js').ViewController;
var menuUtil = require('../core/menu_util.js');
var _ = require('lodash');
exports.getModule = StandardMenuModule;
exports.moduleInfo = {
@ -40,6 +42,7 @@ StandardMenuModule.prototype.mciReady = function(mciData) {
// * Prompt form is favored over menu form if both are present.
// * Standard/prefdefined MCI entries must load both (e.g. %BN is expected to resolve)
//
// :TODO: Create MenuModule.standardMciReady() method that others can call that does this -- even custom modules will generally want most of this
self.viewControllers = {};
var vcOpts = { client : self.client };
@ -60,21 +63,21 @@ StandardMenuModule.prototype.mciReady = function(mciData) {
if(self.viewControllers.menu) {
var menuLoadOpts = {
mciMap : mciData.menu,
menuConfig : self.menuConfig,
withForm : !mciData.prompt,
callingMenu : self,
//menuConfig : self.menuConfig,
withoutForm : _.isObject(mciData.prompt),
};
self.viewControllers.menu.loadFromMCIMapAndConfig(menuLoadOpts, viewsReady);
self.viewControllers.menu.loadFromMenuConfig(menuLoadOpts, viewsReady);
}
if(self.viewControllers.prompt) {
var promptLoadOpts = {
callingMenu : self,
mciMap : mciData.prompt,
//promptConfig : self.menuConfig.promptConfig,
};
self.viewControllers.prompt.loadFromPrompt(promptLoadOpts, viewsReady);
self.viewControllers.prompt.loadFromPromptConfig(promptLoadOpts, viewsReady);
}
/*