2015-08-18 21:27:14 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
2023-08-24 02:11:26 +00:00
|
|
|
const { MenuModule } = require('./menu_module.js');
|
2022-06-05 20:04:25 +00:00
|
|
|
const messageArea = require('./message_area.js');
|
|
|
|
const { Errors } = require('./enig_error.js');
|
|
|
|
const UserProps = require('./user_property.js');
|
2018-06-23 03:26:46 +00:00
|
|
|
|
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2015-08-18 21:27:14 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2022-06-05 20:04:25 +00:00
|
|
|
name: 'Message Area List',
|
|
|
|
desc: 'Module for listing / choosing message areas',
|
|
|
|
author: 'NuSkooler',
|
2015-08-18 21:27:14 +00:00
|
|
|
};
|
|
|
|
|
2018-07-23 01:06:43 +00:00
|
|
|
// :TODO: Obv/2 others can show # of messages in area
|
2015-08-27 05:04:04 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const MciViewIds = {
|
2022-06-05 20:04:25 +00:00
|
|
|
areaList: 1,
|
|
|
|
areaDesc: 2, // area desc updated @ index update
|
|
|
|
customRangeStart: 10, // updated @ index update
|
2015-10-15 05:09:10 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class MessageAreaListModule extends MenuModule {
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
2018-07-23 01:06:43 +00:00
|
|
|
this.initList();
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
this.menuMethods = {
|
2022-06-05 20:04:25 +00:00
|
|
|
changeArea: (formData, extraArgs, cb) => {
|
|
|
|
if (1 === formData.submitId) {
|
2018-07-23 01:06:43 +00:00
|
|
|
const area = this.messageAreas[formData.value.area];
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-07-23 01:06:43 +00:00
|
|
|
messageArea.changeMessageArea(this.client, area.areaTag, err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
|
|
|
this.client.term.pipeWrite(
|
|
|
|
`\n|00Cannot change area: ${err.message}\n`
|
|
|
|
);
|
2018-07-23 01:06:43 +00:00
|
|
|
return this.prevMenuOnTimeout(1000, cb);
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (area.hasArt) {
|
2018-07-23 01:06:43 +00:00
|
|
|
const menuOpts = {
|
2022-06-05 20:04:25 +00:00
|
|
|
extraArgs: {
|
|
|
|
areaTag: area.areaTag,
|
2018-07-23 01:06:43 +00:00
|
|
|
},
|
2023-08-24 02:11:26 +00:00
|
|
|
menuFlags: ['popParent', 'noHistory'],
|
2018-07-23 01:06:43 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
return this.gotoMenu(
|
|
|
|
this.menuConfig.config.changeAreaPreArtMenu ||
|
|
|
|
'changeMessageAreaPreArt',
|
|
|
|
menuOpts,
|
|
|
|
cb
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2018-07-23 01:06:43 +00:00
|
|
|
|
|
|
|
return this.prevMenu(cb);
|
2018-06-22 05:15:04 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return cb(null);
|
|
|
|
}
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
2022-06-05 20:04:25 +00:00
|
|
|
next => {
|
2018-07-23 01:06:43 +00:00
|
|
|
return this.prepViewController('areaList', 0, mciData.menu, next);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
next => {
|
|
|
|
const areaListView = this.viewControllers.areaList.getView(
|
|
|
|
MciViewIds.areaList
|
|
|
|
);
|
|
|
|
if (!areaListView) {
|
|
|
|
return cb(
|
|
|
|
Errors.MissingMci(
|
|
|
|
`Missing area list MCI ${MciViewIds.areaList}`
|
|
|
|
)
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 01:06:43 +00:00
|
|
|
areaListView.on('index update', idx => {
|
|
|
|
this.selectionIndexUpdate(idx);
|
2018-06-22 05:15:04 +00:00
|
|
|
});
|
|
|
|
|
2018-07-23 01:06:43 +00:00
|
|
|
areaListView.setItems(this.messageAreas);
|
2018-06-22 05:15:04 +00:00
|
|
|
areaListView.redraw();
|
2018-07-23 01:06:43 +00:00
|
|
|
this.selectionIndexUpdate(0);
|
|
|
|
return next(null);
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
],
|
2018-07-23 01:06:43 +00:00
|
|
|
err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
|
|
|
this.client.log.error(
|
|
|
|
{ error: err.message },
|
|
|
|
'Failed loading message area list'
|
|
|
|
);
|
2018-07-23 01:06:43 +00:00
|
|
|
}
|
2018-06-22 05:15:04 +00:00
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2018-07-23 01:06:43 +00:00
|
|
|
|
|
|
|
selectionIndexUpdate(idx) {
|
|
|
|
const area = this.messageAreas[idx];
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!area) {
|
2018-07-23 01:06:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setViewText('areaList', MciViewIds.areaDesc, area.desc);
|
2022-06-05 20:04:25 +00:00
|
|
|
this.updateCustomViewTextsWithFilter(
|
|
|
|
'areaList',
|
|
|
|
MciViewIds.customRangeStart,
|
|
|
|
area
|
|
|
|
);
|
2018-07-23 01:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initList() {
|
|
|
|
let index = 1;
|
2022-06-05 20:04:25 +00:00
|
|
|
this.messageAreas = messageArea
|
|
|
|
.getSortedAvailMessageAreasByConfTag(
|
|
|
|
this.client.user.properties[UserProps.MessageConfTag],
|
|
|
|
{ client: this.client }
|
|
|
|
)
|
|
|
|
.map(area => {
|
|
|
|
return {
|
|
|
|
index: index++,
|
|
|
|
areaTag: area.areaTag,
|
|
|
|
name: area.area.name,
|
|
|
|
text: area.area.name, // standard
|
|
|
|
desc: area.area.desc,
|
|
|
|
hasArt: _.isString(area.area.art),
|
|
|
|
};
|
|
|
|
});
|
2018-07-23 01:06:43 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
};
|