2015-08-18 21:27:14 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
|
|
|
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');
|
|
|
|
const Errors = require('./enig_error.js').Errors;
|
|
|
|
|
|
|
|
// deps
|
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2015-08-18 21:27:14 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2018-06-23 03:26:46 +00:00
|
|
|
name : 'Message Area List',
|
|
|
|
desc : 'Module for listing / choosing message areas',
|
|
|
|
author : 'NuSkooler',
|
2015-08-18 21:27:14 +00:00
|
|
|
};
|
|
|
|
|
2015-08-27 05:04:04 +00:00
|
|
|
/*
|
2018-06-23 03:26:46 +00:00
|
|
|
:TODO:
|
2015-08-27 05:04:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
Obv/2 has the following:
|
|
|
|
CHANGE .ANS - Message base changing ansi
|
2015-08-27 05:04:04 +00:00
|
|
|
|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 = {
|
2018-06-23 03:26:46 +00:00
|
|
|
AreaList : 1,
|
|
|
|
SelAreaInfo1 : 2,
|
|
|
|
SelAreaInfo2 : 3,
|
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);
|
|
|
|
|
|
|
|
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) {
|
2018-06-23 03:26:46 +00:00
|
|
|
let area = self.messageAreas[formData.value.area];
|
|
|
|
const areaTag = area.areaTag;
|
|
|
|
area = area.area; // what we want is actually embedded
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
messageArea.changeMessageArea(self.client, areaTag, err => {
|
|
|
|
if(err) {
|
|
|
|
self.client.term.pipeWrite(`\n|00Cannot change area: ${err.message}\n`);
|
|
|
|
|
|
|
|
self.prevMenuOnTimeout(1000, cb);
|
|
|
|
} else {
|
|
|
|
if(_.isString(area.art)) {
|
|
|
|
const dispOptions = {
|
2018-06-23 03:26:46 +00:00
|
|
|
client : self.client,
|
|
|
|
name : area.art,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
self.client.term.rawWrite(resetScreen());
|
|
|
|
|
|
|
|
displayThemeArt(dispOptions, () => {
|
2018-06-23 03:26:46 +00:00
|
|
|
// pause by default, unless explicitly told not to
|
2018-06-22 05:15:04 +00:00
|
|
|
if(_.has(area, 'options.pause') && false === area.options.pause) {
|
|
|
|
return self.prevMenuOnTimeout(1000, cb);
|
|
|
|
} else {
|
|
|
|
self.pausePrompt( () => {
|
|
|
|
return self.prevMenu(cb);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return self.prevMenu(cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return cb(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
prevMenuOnTimeout(timeout, cb) {
|
|
|
|
setTimeout( () => {
|
|
|
|
return this.prevMenu(cb);
|
|
|
|
}, timeout);
|
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: these concepts have been replaced with the {someKey} style formatting - update me!
|
2018-06-22 05:15:04 +00:00
|
|
|
updateGeneralAreaInfoViews(areaIndex) {
|
|
|
|
/*
|
2018-06-23 03:26:46 +00:00
|
|
|
const areaInfo = self.messageAreas[areaIndex];
|
|
|
|
|
|
|
|
[ MciViewIds.SelAreaInfo1, MciViewIds.SelAreaInfo2 ].forEach(mciId => {
|
|
|
|
const v = self.viewControllers.areaList.getView(mciId);
|
|
|
|
if(v) {
|
|
|
|
v.setFormatObject(areaInfo.area);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
*/
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
|
|
|
if(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
const self = this;
|
|
|
|
const vc = self.viewControllers.areaList = new ViewController( { client : self.client } );
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function loadFromConfig(callback) {
|
|
|
|
const loadOpts = {
|
2018-06-23 03:26:46 +00:00
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu,
|
|
|
|
formId : 0,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
vc.loadFromMenuConfig(loadOpts, function startingViewReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function populateAreaListView(callback) {
|
|
|
|
const areaListView = vc.getView(MciViewIds.AreaList);
|
|
|
|
if(!areaListView) {
|
|
|
|
return callback(Errors.MissingMci('A MenuView compatible MCI code is required'));
|
|
|
|
}
|
|
|
|
|
2018-06-23 17:17:21 +00:00
|
|
|
let i = 1;
|
|
|
|
areaListView.setItems(self.messageAreas.map(a => {
|
|
|
|
return {
|
|
|
|
index : i++,
|
|
|
|
areaTag : a.area.areaTag,
|
|
|
|
text : a.area.name, // standard
|
|
|
|
name : a.area.name,
|
|
|
|
desc : a.area.desc,
|
|
|
|
};
|
2018-06-22 05:15:04 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
areaListView.on('index update', areaIndex => {
|
|
|
|
self.updateGeneralAreaInfoViews(areaIndex);
|
|
|
|
});
|
|
|
|
|
|
|
|
areaListView.redraw();
|
2018-06-23 17:17:21 +00:00
|
|
|
return callback(null);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
};
|