2015-08-18 21:27:14 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
var ViewController = require('../core/view_controller.js').ViewController;
|
|
|
|
var messageArea = require('../core/message_area.js');
|
2015-08-18 23:00:18 +00:00
|
|
|
var strUtil = require('../core/string_util.js');
|
2015-08-18 21:27:14 +00:00
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
var assert = require('assert');
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
exports.getModule = MessageAreaListModule;
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2015-10-15 05:09:10 +00:00
|
|
|
var MciCodesIds = {
|
|
|
|
AreaList : 1,
|
|
|
|
CurrentArea : 2,
|
|
|
|
};
|
|
|
|
|
2015-08-18 21:27:14 +00:00
|
|
|
function MessageAreaListModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
this.messageAreas = messageArea.getSortedAvailMessageAreasByConfTag(
|
|
|
|
self.client.user.properties.message_conf_tag,
|
|
|
|
{ client : self.client }
|
|
|
|
);
|
2015-08-20 23:00:35 +00:00
|
|
|
|
2015-08-18 23:00:18 +00:00
|
|
|
this.menuMethods = {
|
|
|
|
changeArea : function(formData, extraArgs) {
|
2015-08-19 04:45:47 +00:00
|
|
|
if(1 === formData.submitId) {
|
2016-02-03 04:35:59 +00:00
|
|
|
const areaTag = self.messageAreas[formData.value.area].areaTag;
|
|
|
|
|
|
|
|
messageArea.changeMessageArea(self.client, areaTag, function areaChanged(err) {
|
|
|
|
if(err) {
|
|
|
|
self.client.term.pipeWrite('\n|00Cannot change area: ' + err.message + '\n');
|
|
|
|
|
|
|
|
setTimeout(function timeout() {
|
|
|
|
self.prevMenu();
|
|
|
|
}, 1000);
|
|
|
|
} else {
|
|
|
|
self.prevMenu();
|
|
|
|
}
|
|
|
|
});
|
2015-08-19 04:45:47 +00:00
|
|
|
}
|
2015-08-18 23:00:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-15 05:09:10 +00:00
|
|
|
this.setViewText = function(id, text) {
|
2016-02-03 04:35:59 +00:00
|
|
|
const v = self.viewControllers.areaList.getView(id);
|
2015-10-15 05:09:10 +00:00
|
|
|
if(v) {
|
|
|
|
v.setText(text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-18 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(MessageAreaListModule, MenuModule);
|
2015-08-19 04:45:47 +00:00
|
|
|
|
2015-08-18 21:27:14 +00:00
|
|
|
MessageAreaListModule.prototype.mciReady = function(mciData, cb) {
|
|
|
|
var self = this;
|
2016-02-03 04:35:59 +00:00
|
|
|
const vc = self.viewControllers.areaList = new ViewController( { client : self.client } );
|
2015-08-18 21:27:14 +00:00
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function callParentMciReady(callback) {
|
|
|
|
MessageAreaListModule.super_.prototype.mciReady.call(this, mciData, function parentMciReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function loadFromConfig(callback) {
|
|
|
|
var loadOpts = {
|
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu,
|
2015-08-19 04:45:47 +00:00
|
|
|
formId : 0,
|
2015-08-18 21:27:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
vc.loadFromMenuConfig(loadOpts, function startingViewReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function populateAreaListView(callback) {
|
2016-02-03 04:35:59 +00:00
|
|
|
const listFormat = self.menuConfig.config.listFormat || '{index} ) - {name}';
|
|
|
|
const focusListFormat = self.menuConfig.config.focusListFormat || listFormat;
|
|
|
|
|
|
|
|
const areaListView = vc.getView(1);
|
|
|
|
let i = 1;
|
|
|
|
areaListView.setItems(_.map(self.messageAreas, v => {
|
|
|
|
return listFormat.format({
|
|
|
|
index : i++,
|
|
|
|
areaTag : v.area.areaTag,
|
|
|
|
name : v.area.name,
|
|
|
|
desc : v.area.desc,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
areaListView.setFocusItems(_.map(self.messageAreas, v => {
|
|
|
|
return focusListFormat.format({
|
|
|
|
index : i++,
|
|
|
|
areaTag : v.area.areaTag,
|
|
|
|
name : v.area.name,
|
|
|
|
desc : v.area.desc,
|
|
|
|
})
|
|
|
|
}));
|
2015-10-15 05:09:10 +00:00
|
|
|
|
2015-08-18 21:27:14 +00:00
|
|
|
areaListView.redraw();
|
2015-10-15 05:09:10 +00:00
|
|
|
|
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function populateTextViews(callback) {
|
|
|
|
// :TODO: populate current message area desc!
|
|
|
|
//self.setViewText(MciCodesIds.CurrentArea,
|
|
|
|
|
|
|
|
callback(null);
|
2015-08-18 21:27:14 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
2015-08-20 23:00:35 +00:00
|
|
|
cb(null);
|
2015-08-18 21:27:14 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|