mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-29 22:16:11 +02:00
* Code cleanup and eslint since -- remove unused variables, clean up RegExs, so on...
This commit is contained in:
parent
a106050ba3
commit
ac1433e84b
112 changed files with 1375 additions and 1898 deletions
|
@ -28,10 +28,10 @@ const MciCodeIds = {
|
|||
TermHeight : 8,
|
||||
Theme : 9,
|
||||
Password : 10,
|
||||
PassConfirm : 11,
|
||||
PassConfirm : 11,
|
||||
ThemeInfo : 20,
|
||||
ErrorMsg : 21,
|
||||
|
||||
|
||||
SaveCancel : 25,
|
||||
};
|
||||
|
||||
|
@ -52,11 +52,11 @@ exports.getModule = class UserConfigModule extends MenuModule {
|
|||
if(self.client.user.properties.email_address.toLowerCase() === data.toLowerCase()) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
|
||||
// Otherwise we can use the standard system method
|
||||
return sysValidate.validateEmailAvail(data, cb);
|
||||
},
|
||||
|
||||
|
||||
validatePassword : function(data, cb) {
|
||||
//
|
||||
// Blank is OK - this means we won't be changing it
|
||||
|
@ -64,23 +64,23 @@ exports.getModule = class UserConfigModule extends MenuModule {
|
|||
if(!data || 0 === data.length) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
|
||||
// Otherwise we can use the standard system method
|
||||
return sysValidate.validatePasswordSpec(data, cb);
|
||||
},
|
||||
|
||||
|
||||
validatePassConfirmMatch : function(data, cb) {
|
||||
var passwordView = self.getView(MciCodeIds.Password);
|
||||
cb(passwordView.getData() === data ? null : new Error('Passwords do not match'));
|
||||
},
|
||||
|
||||
|
||||
viewValidationListener : function(err, cb) {
|
||||
var errMsgView = self.getView(MciCodeIds.ErrorMsg);
|
||||
var newFocusId;
|
||||
if(errMsgView) {
|
||||
if(err) {
|
||||
errMsgView.setText(err.message);
|
||||
|
||||
|
||||
if(err.view.getId() === MciCodeIds.PassConfirm) {
|
||||
newFocusId = MciCodeIds.Password;
|
||||
var passwordView = self.getView(MciCodeIds.Password);
|
||||
|
@ -93,13 +93,13 @@ exports.getModule = class UserConfigModule extends MenuModule {
|
|||
}
|
||||
cb(newFocusId);
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// Handlers
|
||||
//
|
||||
saveChanges : function(formData, extraArgs, cb) {
|
||||
assert(formData.value.password === formData.value.passwordConfirm);
|
||||
|
||||
|
||||
const newProperties = {
|
||||
real_name : formData.value.realName,
|
||||
birthdate : new Date(Date.parse(formData.value.birthdate)).toISOString(),
|
||||
|
@ -108,15 +108,15 @@ exports.getModule = class UserConfigModule extends MenuModule {
|
|||
affiliation : formData.value.affils,
|
||||
email_address : formData.value.email,
|
||||
web_address : formData.value.web,
|
||||
term_height : formData.value.termHeight.toString(),
|
||||
term_height : formData.value.termHeight.toString(),
|
||||
theme_id : self.availThemeInfo[formData.value.theme].themeId,
|
||||
};
|
||||
|
||||
|
||||
// runtime set theme
|
||||
theme.setClientTheme(self.client, newProperties.theme_id);
|
||||
|
||||
|
||||
// persist all changes
|
||||
self.client.user.persistProperties(newProperties, err => {
|
||||
self.client.user.persistProperties(newProperties, err => {
|
||||
if(err) {
|
||||
self.client.log.warn( { error : err.toString() }, 'Failed persisting updated properties');
|
||||
// :TODO: warn end user!
|
||||
|
@ -126,7 +126,7 @@ exports.getModule = class UserConfigModule extends MenuModule {
|
|||
// New password if it's not empty
|
||||
//
|
||||
self.client.log.info('User updated properties');
|
||||
|
||||
|
||||
if(formData.value.password.length > 0) {
|
||||
self.client.user.setNewAuthCredentials(formData.value.password, err => {
|
||||
if(err) {
|
||||
|
@ -155,7 +155,7 @@ exports.getModule = class UserConfigModule extends MenuModule {
|
|||
}
|
||||
|
||||
const self = this;
|
||||
const vc = self.viewControllers.menu = new ViewController( { client : self.client} );
|
||||
const vc = self.viewControllers.menu = new ViewController( { client : self.client} );
|
||||
let currentThemeIdIndex = 0;
|
||||
|
||||
async.series(
|
||||
|
@ -164,7 +164,7 @@ exports.getModule = class UserConfigModule extends MenuModule {
|
|||
vc.loadFromMenuConfig( { callingMenu : self, mciMap : mciData.menu }, callback);
|
||||
},
|
||||
function prepareAvailableThemes(callback) {
|
||||
self.availThemeInfo = _.sortBy(_.map(theme.getAvailableThemes(), function makeThemeInfo(t, themeId) {
|
||||
self.availThemeInfo = _.sortBy(_.map(theme.getAvailableThemes(), function makeThemeInfo(t, themeId) {
|
||||
return {
|
||||
themeId : themeId,
|
||||
name : t.info.name,
|
||||
|
@ -173,11 +173,11 @@ exports.getModule = class UserConfigModule extends MenuModule {
|
|||
group : _.isString(t.info.group) ? t.info.group : '',
|
||||
};
|
||||
}), 'name');
|
||||
|
||||
|
||||
currentThemeIdIndex = _.findIndex(self.availThemeInfo, function cmp(ti) {
|
||||
return ti.themeId === self.client.user.properties.theme_id;
|
||||
});
|
||||
|
||||
|
||||
callback(null);
|
||||
},
|
||||
function populateViews(callback) {
|
||||
|
@ -191,19 +191,19 @@ exports.getModule = class UserConfigModule extends MenuModule {
|
|||
self.setViewText('menu', MciCodeIds.Email, user.properties.email_address);
|
||||
self.setViewText('menu', MciCodeIds.Web, user.properties.web_address);
|
||||
self.setViewText('menu', MciCodeIds.TermHeight, user.properties.term_height.toString());
|
||||
|
||||
|
||||
|
||||
|
||||
var themeView = self.getView(MciCodeIds.Theme);
|
||||
if(themeView) {
|
||||
themeView.setItems(_.map(self.availThemeInfo, 'name'));
|
||||
themeView.setFocusItemIndex(currentThemeIdIndex);
|
||||
}
|
||||
|
||||
|
||||
var realNameView = self.getView(MciCodeIds.RealName);
|
||||
if(realNameView) {
|
||||
realNameView.setFocus(true); // :TODO: HACK! menu.hjson sets focus, but manual population above breaks this. Needs a real fix!
|
||||
}
|
||||
|
||||
|
||||
callback(null);
|
||||
}
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue