enigma-bbs/core/autosig_edit.js

85 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2019-08-10 05:17:41 +00:00
/* jslint node: true */
'use strict';
// ENiGMA½
const { MenuModule } = require('./menu_module.js');
const UserProps = require('./user_property.js');
2019-08-10 05:17:41 +00:00
// deps
const async = require('async');
const _ = require('lodash');
2019-08-10 05:17:41 +00:00
exports.moduleInfo = {
name: 'User Auto-Sig Editor',
desc: 'Module for editing auto-sigs',
author: 'NuSkooler',
2019-08-10 05:17:41 +00:00
};
const FormIds = {
edit: 0,
2019-08-10 05:17:41 +00:00
};
const MciViewIds = {
editor: 1,
save: 2,
2019-08-10 05:17:41 +00:00
};
exports.getModule = class UserAutoSigEditorModule extends MenuModule {
constructor(options) {
super(options);
this.config = Object.assign({}, _.get(options, 'menuConfig.config'), {
extraArgs: options.extraArgs,
});
2019-08-10 05:17:41 +00:00
this.menuMethods = {
saveChanges: (formData, extraArgs, cb) => {
2019-08-10 05:17:41 +00:00
return this.saveChanges(cb);
},
2019-08-10 05:17:41 +00:00
};
}
mciReady(mciData, cb) {
super.mciReady(mciData, err => {
if (err) {
2019-08-10 05:17:41 +00:00
return cb(err);
}
async.series(
[
callback => {
return this.prepViewController(
'edit',
FormIds.edit,
mciData.menu,
callback
);
2019-08-10 05:17:41 +00:00
},
callback => {
const requiredCodes = [MciViewIds.editor, MciViewIds.save];
2019-08-10 05:17:41 +00:00
return this.validateMCIByViewIds('edit', requiredCodes, callback);
},
callback => {
const sig =
this.client.user.getProperty(UserProps.AutoSignature) || '';
2019-08-10 05:17:41 +00:00
this.setViewText('edit', MciViewIds.editor, sig);
return callback(null);
},
2019-08-10 05:17:41 +00:00
],
err => {
return cb(err);
}
);
});
}
saveChanges(cb) {
const sig = this.getView('edit', MciViewIds.editor).getData().trim();
this.client.user.persistProperty(UserProps.AutoSignature, sig, err => {
if (err) {
this.client.log.error({ error: err.message }, 'Could not save auto-sig');
2019-08-10 05:17:41 +00:00
}
return this.prevMenu(cb);
});
}
};