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 msgDb = require('./database.js').dbs.message;
|
|
|
|
|
|
|
|
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-08-18 21:27:14 +00:00
|
|
|
function MessageAreaListModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2015-08-20 23:00:35 +00:00
|
|
|
this.messageAreas = messageArea.getAvailableMessageAreas();
|
|
|
|
|
2015-08-18 23:00:18 +00:00
|
|
|
if(_.isObject(this.menuConfig.config)) {
|
|
|
|
if(_.isString(this.menuConfig.config.entryFormat)) {
|
|
|
|
this.entryFormat = this.menuConfig.config.entryFormat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-20 22:35:04 +00:00
|
|
|
this.entryFormat = this.entryFormat || '( {index} ) - {desc}';
|
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) {
|
2015-08-20 22:35:04 +00:00
|
|
|
var areaName = self.messageAreas[formData.value.area].name;
|
|
|
|
|
|
|
|
messageArea.changeMessageArea(self.client, areaName, function areaChanged(err) {
|
|
|
|
if(err) {
|
|
|
|
self.client.term.pipeWrite('\n|00Cannot change area: ' + err.message + '\n');
|
|
|
|
|
|
|
|
setTimeout(function timeout() {
|
|
|
|
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
|
|
|
}, 1000);
|
|
|
|
} else {
|
|
|
|
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
|
|
|
}
|
|
|
|
});
|
2015-08-19 04:45:47 +00:00
|
|
|
}
|
2015-08-18 23:00:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-18 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(MessageAreaListModule, MenuModule);
|
2015-08-20 23:00:35 +00:00
|
|
|
/*
|
2015-08-19 04:45:47 +00:00
|
|
|
MessageAreaListModule.prototype.enter = function(client) {
|
2015-08-20 23:00:35 +00:00
|
|
|
this.messageAreas = messageArea.getAvailableMessageAreas();
|
2015-08-20 22:35:04 +00:00
|
|
|
|
2015-08-20 23:00:35 +00:00
|
|
|
MessageAreaListModule.super_.prototype.enter.call(this, client);
|
2015-08-19 04:45:47 +00:00
|
|
|
};
|
2015-08-20 23:00:35 +00:00
|
|
|
*/
|
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;
|
|
|
|
var vc = self.viewControllers.areaList = new ViewController( { client : self.client } );
|
|
|
|
|
|
|
|
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) {
|
2015-08-20 22:35:04 +00:00
|
|
|
var areaListItems = [];
|
|
|
|
for(var i = 0; i < self.messageAreas.length; ++i) {
|
2015-08-27 22:14:56 +00:00
|
|
|
areaListItems.push(self.entryFormat.format(
|
|
|
|
{ index : i, name : self.messageAreas[i].name, desc : self.messageAreas[i].desc } )
|
2015-08-20 22:35:04 +00:00
|
|
|
);
|
|
|
|
}
|
2015-08-18 21:27:14 +00:00
|
|
|
|
2015-08-20 23:00:35 +00:00
|
|
|
var areaListView = vc.getView(1);
|
2015-08-20 22:35:04 +00:00
|
|
|
areaListView.setItems(areaListItems);
|
2015-08-18 21:27:14 +00:00
|
|
|
areaListView.redraw();
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
2015-08-20 23:00:35 +00:00
|
|
|
cb(null);
|
2015-08-18 21:27:14 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|