2016-02-03 04:35:59 +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');
|
2016-02-03 04:35:59 +00:00
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
// deps
|
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2016-02-03 04:35:59 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Message Conference List',
|
|
|
|
desc : 'Module for listing / choosing message conferences',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const MciViewIds = {
|
2016-02-03 04:35:59 +00:00
|
|
|
ConfList : 1,
|
|
|
|
|
|
|
|
// :TODO:
|
2016-07-25 20:35:58 +00:00
|
|
|
// # areas in conf .... see Obv/2, iNiQ, ...
|
2016-02-03 04:35:59 +00:00
|
|
|
//
|
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class MessageConfListModule extends MenuModule {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
this.messageConfs = messageArea.getSortedAvailMessageConferences(this.client);
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
this.menuMethods = {
|
|
|
|
changeConference : function(formData, extraArgs, cb) {
|
|
|
|
if(1 === formData.submitId) {
|
|
|
|
let conf = self.messageConfs[formData.value.conf];
|
|
|
|
const confTag = conf.confTag;
|
|
|
|
conf = conf.conf; // what we want is embedded
|
|
|
|
|
|
|
|
messageArea.changeMessageConference(self.client, confTag, err => {
|
|
|
|
if(err) {
|
|
|
|
self.client.term.pipeWrite(`\n|00Cannot change conference: ${err.message}\n`);
|
|
|
|
|
|
|
|
setTimeout( () => {
|
|
|
|
return self.prevMenu(cb);
|
|
|
|
}, 1000);
|
2016-08-04 01:48:45 +00:00
|
|
|
} else {
|
2017-01-26 05:18:05 +00:00
|
|
|
if(_.isString(conf.art)) {
|
|
|
|
const dispOptions = {
|
|
|
|
client : self.client,
|
|
|
|
name : conf.art,
|
|
|
|
};
|
|
|
|
|
|
|
|
self.client.term.rawWrite(resetScreen());
|
|
|
|
|
|
|
|
displayThemeArt(dispOptions, () => {
|
|
|
|
// pause by default, unless explicitly told not to
|
|
|
|
if(_.has(conf, 'options.pause') && false === conf.options.pause) {
|
|
|
|
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
|
|
|
}
|
2016-07-25 20:35:58 +00:00
|
|
|
});
|
2017-01-26 05:18:05 +00:00
|
|
|
} else {
|
|
|
|
return cb(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-02-03 04:35:59 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
prevMenuOnTimeout(timeout, cb) {
|
|
|
|
setTimeout( () => {
|
|
|
|
return this.prevMenu(cb);
|
|
|
|
}, timeout);
|
|
|
|
}
|
2016-02-03 04:35:59 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
|
|
|
if(err) {
|
|
|
|
return cb(err);
|
2016-02-03 04:35:59 +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) {
|
|
|
|
let loadOpts = {
|
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu,
|
|
|
|
formId : 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
vc.loadFromMenuConfig(loadOpts, callback);
|
|
|
|
},
|
|
|
|
function populateConfListView(callback) {
|
|
|
|
const listFormat = self.menuConfig.config.listFormat || '{index} ) - {name}';
|
|
|
|
const focusListFormat = self.menuConfig.config.focusListFormat || listFormat;
|
|
|
|
|
|
|
|
const confListView = vc.getView(MciViewIds.ConfList);
|
|
|
|
let i = 1;
|
|
|
|
confListView.setItems(_.map(self.messageConfs, v => {
|
|
|
|
return stringFormat(listFormat, {
|
|
|
|
index : i++,
|
|
|
|
confTag : v.conf.confTag,
|
|
|
|
name : v.conf.name,
|
|
|
|
desc : v.conf.desc,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
confListView.setFocusItems(_.map(self.messageConfs, v => {
|
|
|
|
return stringFormat(focusListFormat, {
|
|
|
|
index : i++,
|
|
|
|
confTag : v.conf.confTag,
|
|
|
|
name : v.conf.name,
|
|
|
|
desc : v.conf.desc,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
confListView.redraw();
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function populateTextViews(callback) {
|
|
|
|
// :TODO: populate other avail MCI, e.g. current conf name
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|