2015-08-18 21:27:14 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
// ENiGMA½
|
2017-11-24 23:23:15 +00:00
|
|
|
const MenuModule = require('./menu_module.js').MenuModule;
|
|
|
|
const ViewController = require('./view_controller.js').ViewController;
|
|
|
|
const messageArea = require('./message_area.js');
|
|
|
|
const displayThemeArt = require('./theme.js').displayThemeArt;
|
|
|
|
const resetScreen = require('./ansi_term.js').resetScreen;
|
|
|
|
const stringFormat = require('./string_format.js');
|
2018-03-23 02:48:31 +00:00
|
|
|
const Errors = require('./enig_error.js').Errors;
|
2015-08-18 21:27:14 +00:00
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
// deps
|
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2015-08-18 21:27:14 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Message Area List',
|
|
|
|
desc : 'Module for listing / choosing message areas',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
2015-08-27 05:04:04 +00:00
|
|
|
/*
|
|
|
|
:TODO:
|
|
|
|
|
|
|
|
Obv/2 has the following:
|
|
|
|
CHANGE .ANS - Message base changing ansi
|
|
|
|
|SN Current base name
|
|
|
|
|SS Current base sponsor
|
|
|
|
|NM Number of messages in current base
|
|
|
|
|UP Number of posts current user made (total)
|
|
|
|
|LR Last read message by current user
|
|
|
|
|DT Current date
|
|
|
|
|TI Current time
|
|
|
|
*/
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const MciViewIds = {
|
2016-08-04 01:48:45 +00:00
|
|
|
AreaList : 1,
|
|
|
|
SelAreaInfo1 : 2,
|
2018-01-15 19:22:11 +00:00
|
|
|
SelAreaInfo2 : 3,
|
2015-10-15 05:09:10 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class MessageAreaListModule extends MenuModule {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
this.messageAreas = messageArea.getSortedAvailMessageAreasByConfTag(
|
|
|
|
this.client.user.properties.message_conf_tag,
|
|
|
|
{ client : this.client }
|
|
|
|
);
|
|
|
|
|
|
|
|
const self = this;
|
|
|
|
this.menuMethods = {
|
|
|
|
changeArea : function(formData, extraArgs, cb) {
|
|
|
|
if(1 === formData.submitId) {
|
|
|
|
let area = self.messageAreas[formData.value.area];
|
|
|
|
const areaTag = area.areaTag;
|
|
|
|
area = area.area; // what we want is actually embedded
|
|
|
|
|
|
|
|
messageArea.changeMessageArea(self.client, areaTag, err => {
|
|
|
|
if(err) {
|
|
|
|
self.client.term.pipeWrite(`\n|00Cannot change area: ${err.message}\n`);
|
|
|
|
|
|
|
|
self.prevMenuOnTimeout(1000, cb);
|
2018-01-15 19:22:11 +00:00
|
|
|
} else {
|
2017-01-26 05:18:05 +00:00
|
|
|
if(_.isString(area.art)) {
|
|
|
|
const dispOptions = {
|
|
|
|
client : self.client,
|
|
|
|
name : area.art,
|
|
|
|
};
|
|
|
|
|
|
|
|
self.client.term.rawWrite(resetScreen());
|
|
|
|
|
|
|
|
displayThemeArt(dispOptions, () => {
|
|
|
|
// pause by default, unless explicitly told not to
|
2018-01-15 19:22:11 +00:00
|
|
|
if(_.has(area, 'options.pause') && false === area.options.pause) {
|
2017-01-26 05:18:05 +00:00
|
|
|
return self.prevMenuOnTimeout(1000, cb);
|
|
|
|
} else {
|
2017-02-08 03:20:10 +00:00
|
|
|
self.pausePrompt( () => {
|
2017-01-26 05:18:05 +00:00
|
|
|
return self.prevMenu(cb);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return self.prevMenu(cb);
|
|
|
|
}
|
2016-08-04 01:48:45 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return cb(null);
|
|
|
|
}
|
2015-08-19 04:45:47 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
};
|
|
|
|
}
|
2015-08-18 23:00:18 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
prevMenuOnTimeout(timeout, cb) {
|
|
|
|
setTimeout( () => {
|
|
|
|
return this.prevMenu(cb);
|
|
|
|
}, timeout);
|
|
|
|
}
|
2015-10-15 05:09:10 +00:00
|
|
|
|
2018-01-15 19:22:11 +00:00
|
|
|
// :TODO: these concepts have been replaced with the {someKey} style formatting - update me!
|
2018-01-16 04:05:55 +00:00
|
|
|
updateGeneralAreaInfoViews(areaIndex) {
|
|
|
|
/*
|
2016-08-04 01:48:45 +00:00
|
|
|
const areaInfo = self.messageAreas[areaIndex];
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
[ MciViewIds.SelAreaInfo1, MciViewIds.SelAreaInfo2 ].forEach(mciId => {
|
2016-08-04 01:48:45 +00:00
|
|
|
const v = self.viewControllers.areaList.getView(mciId);
|
|
|
|
if(v) {
|
|
|
|
v.setFormatObject(areaInfo.area);
|
|
|
|
}
|
|
|
|
});
|
2018-01-16 04:05:55 +00:00
|
|
|
*/
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-10-15 05:09:10 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
|
|
|
if(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
2016-08-04 01:48:45 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const self = this;
|
|
|
|
const vc = self.viewControllers.areaList = new ViewController( { client : self.client } );
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function loadFromConfig(callback) {
|
|
|
|
const loadOpts = {
|
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu,
|
|
|
|
formId : 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
vc.loadFromMenuConfig(loadOpts, function startingViewReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function populateAreaListView(callback) {
|
|
|
|
const listFormat = self.menuConfig.config.listFormat || '{index} ) - {name}';
|
|
|
|
const focusListFormat = self.menuConfig.config.focusListFormat || listFormat;
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const areaListView = vc.getView(MciViewIds.AreaList);
|
2018-03-23 02:48:31 +00:00
|
|
|
if(!areaListView) {
|
|
|
|
return callback(Errors.MissingMci('A MenuView compatible MCI code is required'));
|
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
let i = 1;
|
|
|
|
areaListView.setItems(_.map(self.messageAreas, v => {
|
|
|
|
return stringFormat(listFormat, {
|
|
|
|
index : i++,
|
|
|
|
areaTag : v.area.areaTag,
|
|
|
|
name : v.area.name,
|
2018-01-15 19:22:11 +00:00
|
|
|
desc : v.area.desc,
|
2017-01-26 05:18:05 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
areaListView.setFocusItems(_.map(self.messageAreas, v => {
|
|
|
|
return stringFormat(focusListFormat, {
|
|
|
|
index : i++,
|
|
|
|
areaTag : v.area.areaTag,
|
|
|
|
name : v.area.name,
|
2018-01-15 19:22:11 +00:00
|
|
|
desc : v.area.desc,
|
2017-01-26 05:18:05 +00:00
|
|
|
});
|
|
|
|
}));
|
2015-10-15 05:09:10 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
areaListView.on('index update', areaIndex => {
|
|
|
|
self.updateGeneralAreaInfoViews(areaIndex);
|
|
|
|
});
|
|
|
|
|
|
|
|
areaListView.redraw();
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|