2016-02-03 04:35:59 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
// ENiGMA½
|
2016-08-04 01:48:45 +00:00
|
|
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
const ViewController = require('../core/view_controller.js').ViewController;
|
|
|
|
const messageArea = require('../core/message_area.js');
|
|
|
|
const displayThemeArt = require('../core/theme.js').displayThemeArt;
|
|
|
|
const displayThemedPause = require('../core/theme.js').displayThemedPause;
|
|
|
|
const resetScreen = require('../core/ansi_term.js').resetScreen;
|
2016-09-05 03:36:26 +00:00
|
|
|
const stringFormat = require('../core/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.getModule = MessageConfListModule;
|
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Message Conference List',
|
|
|
|
desc : 'Module for listing / choosing message conferences',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
const MCICodeIDs = {
|
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
|
|
|
//
|
|
|
|
};
|
|
|
|
|
|
|
|
function MessageConfListModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.messageConfs = messageArea.getSortedAvailMessageConferences(self.client);
|
|
|
|
|
2016-08-04 01:48:45 +00:00
|
|
|
this.prevMenuOnTimeout = function(timeout, cb) {
|
|
|
|
setTimeout( () => {
|
|
|
|
self.prevMenu(cb);
|
|
|
|
}, timeout);
|
|
|
|
};
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
this.menuMethods = {
|
2016-07-25 20:35:58 +00:00
|
|
|
changeConference : function(formData, extraArgs, cb) {
|
2016-02-03 04:35:59 +00:00
|
|
|
if(1 === formData.submitId) {
|
2016-08-04 01:48:45 +00:00
|
|
|
let conf = self.messageConfs[formData.value.conf];
|
|
|
|
const confTag = conf.confTag;
|
|
|
|
conf = conf.conf; // what we want is embedded
|
2016-02-03 04:35:59 +00:00
|
|
|
|
|
|
|
messageArea.changeMessageConference(self.client, confTag, err => {
|
|
|
|
if(err) {
|
|
|
|
self.client.term.pipeWrite(`\n|00Cannot change conference: ${err.message}\n`);
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
setTimeout( () => {
|
|
|
|
return self.prevMenu(cb);
|
|
|
|
}, 1000);
|
2016-02-03 04:35:59 +00:00
|
|
|
} else {
|
2016-08-04 01:48:45 +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 {
|
|
|
|
displayThemedPause( { client : self.client }, () => {
|
|
|
|
return self.prevMenu(cb);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return self.prevMenu(cb);
|
|
|
|
}
|
2016-02-03 04:35:59 +00:00
|
|
|
}
|
|
|
|
});
|
2016-07-25 20:35:58 +00:00
|
|
|
} else {
|
|
|
|
return cb(null);
|
2016-02-03 04:35:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setViewText = function(id, text) {
|
|
|
|
const v = self.viewControllers.areaList.getView(id);
|
|
|
|
if(v) {
|
|
|
|
v.setText(text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(MessageConfListModule, MenuModule);
|
|
|
|
|
|
|
|
MessageConfListModule.prototype.mciReady = function(mciData, cb) {
|
|
|
|
var self = this;
|
|
|
|
const vc = self.viewControllers.areaList = new ViewController( { client : self.client } );
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function callParentMciReady(callback) {
|
|
|
|
MessageConfListModule.super_.prototype.mciReady.call(this, mciData, callback);
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
const confListView = vc.getView(MCICodeIDs.ConfList);
|
|
|
|
let i = 1;
|
|
|
|
confListView.setItems(_.map(self.messageConfs, v => {
|
2016-09-05 03:36:26 +00:00
|
|
|
return stringFormat(listFormat, {
|
2016-07-25 20:35:58 +00:00
|
|
|
index : i++,
|
|
|
|
confTag : v.conf.confTag,
|
|
|
|
name : v.conf.name,
|
|
|
|
desc : v.conf.desc,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
confListView.setFocusItems(_.map(self.messageConfs, v => {
|
2016-09-05 03:36:26 +00:00
|
|
|
return stringFormat(focusListFormat, {
|
2016-07-25 20:35:58 +00:00
|
|
|
index : i++,
|
|
|
|
confTag : v.conf.confTag,
|
|
|
|
name : v.conf.name,
|
|
|
|
desc : v.conf.desc,
|
|
|
|
});
|
|
|
|
}));
|
2016-02-03 04:35:59 +00:00
|
|
|
|
|
|
|
confListView.redraw();
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function populateTextViews(callback) {
|
|
|
|
// :TODO: populate other avail MCI, e.g. current conf name
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|