2015-08-26 05:17:09 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var MenuModule = require('../core/menu_module.js').MenuModule;
|
2015-08-27 05:04:04 +00:00
|
|
|
var ViewController = require('../core/view_controller.js').ViewController;
|
2015-08-28 04:20:24 +00:00
|
|
|
var messageArea = require('../core/message_area.js');
|
2015-09-01 05:18:46 +00:00
|
|
|
var Message = require('../core/message.js');
|
2015-08-27 05:04:04 +00:00
|
|
|
|
|
|
|
//var moment = require('moment');
|
|
|
|
var async = require('async');
|
|
|
|
var assert = require('assert');
|
|
|
|
var _ = require('lodash');
|
2015-08-26 05:17:09 +00:00
|
|
|
|
|
|
|
exports.getModule = MessageListModule;
|
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Message List',
|
|
|
|
desc : 'Module for listing/browsing available messages',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// :TODO:
|
|
|
|
// * Avail data:
|
2015-08-27 05:04:04 +00:00
|
|
|
// To - {to}
|
|
|
|
// From - {from}
|
2015-08-26 05:17:09 +00:00
|
|
|
// Subject
|
|
|
|
// Date
|
|
|
|
// Status (New/Read)
|
|
|
|
// Message Num (Area)
|
|
|
|
// Message Total (Area)
|
2015-08-27 05:04:04 +00:00
|
|
|
// Message Area desc - {areaDesc} / %TL2
|
|
|
|
// Message Area Name - {areaName}
|
2015-08-26 05:17:09 +00:00
|
|
|
//
|
|
|
|
// Ideas
|
|
|
|
// * Module config can define custom formats for items & focused items (inc. Pipe Codes)
|
2015-08-28 04:20:24 +00:00
|
|
|
// * Single list view with advanced formatting (would need textOverflow stuff), advanced formatting...
|
2015-08-27 05:04:04 +00:00
|
|
|
// * Multiple LV's in sync with keyboard input
|
|
|
|
// * New Table LV (TV)
|
2015-08-26 05:17:09 +00:00
|
|
|
// *
|
2015-08-27 05:04:04 +00:00
|
|
|
//
|
|
|
|
// See Obv/2, Iniq, and Mystic docs
|
2015-08-26 05:17:09 +00:00
|
|
|
|
|
|
|
function MessageListModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
|
|
|
|
var self = this;
|
2015-08-31 03:42:24 +00:00
|
|
|
|
2015-09-04 06:02:28 +00:00
|
|
|
var config = this.menuConfig.config;
|
|
|
|
// config.listType : public | private
|
|
|
|
|
|
|
|
this.listType = config.listType || 'public';
|
|
|
|
|
2015-08-31 03:42:24 +00:00
|
|
|
this.messageList = [];
|
|
|
|
|
|
|
|
this.menuMethods = {
|
|
|
|
selectMessage : function(formData, extraArgs) {
|
|
|
|
if(1 === formData.submitId) {
|
2015-09-06 21:58:58 +00:00
|
|
|
/*
|
|
|
|
extraArgs.messageAreaName
|
|
|
|
extraArgs.messageList
|
|
|
|
extraArgs.messageListIndex
|
|
|
|
*/
|
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
var selected = self.messageList[formData.value.message];
|
2015-09-06 21:58:58 +00:00
|
|
|
//console.log(selected);
|
|
|
|
|
|
|
|
var modOpts = {
|
|
|
|
name : 'messageAreaViewPost', // :TODO: should come from config?
|
|
|
|
extraArgs : {
|
|
|
|
messageAreaName : self.messageAreaName,
|
|
|
|
messageList : self.messageList,
|
|
|
|
messageListIndex : formData.value.message,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.client.gotoMenuModule(modOpts);
|
|
|
|
|
|
|
|
/*
|
|
|
|
//
|
2015-09-01 05:18:46 +00:00
|
|
|
// Load full Message object
|
|
|
|
//
|
|
|
|
var msg = new Message();
|
|
|
|
msg.load( { uuid : selected.messageUuid, user : self.client.user }, function loaded(err) {
|
|
|
|
|
|
|
|
if(err) {
|
|
|
|
// :TODO: Now what?!
|
|
|
|
console.log(err)
|
|
|
|
} else {
|
|
|
|
var modOpts = {
|
|
|
|
// :TODO: get this name from config
|
|
|
|
name : 'messageAreaViewPost',
|
2015-09-04 22:35:08 +00:00
|
|
|
extraArgs : {
|
|
|
|
message : msg,
|
|
|
|
messageAreaName : self.messageAreaName,
|
|
|
|
messageNumber : formData.value.message + 1,
|
|
|
|
messageTotal : self.messageList.length,
|
|
|
|
},
|
2015-09-01 05:18:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
self.client.gotoMenuModule(modOpts);
|
|
|
|
}
|
|
|
|
});
|
2015-09-06 21:58:58 +00:00
|
|
|
*/
|
2015-08-31 03:42:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-08-26 05:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(MessageListModule, MenuModule);
|
|
|
|
|
2015-09-04 06:02:28 +00:00
|
|
|
MessageListModule.prototype.enter = function(client) {
|
|
|
|
|
|
|
|
if('private' === this.listType) {
|
|
|
|
this.messageAreaName = Message.WellKnownAreaNames.Private;
|
|
|
|
} else {
|
|
|
|
this.messageAreaName = client.user.properties.message_area_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageListModule.super_.prototype.enter.call(this, client);
|
|
|
|
};
|
|
|
|
|
2015-08-27 05:04:04 +00:00
|
|
|
MessageListModule.prototype.mciReady = function(mciData, cb) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var vc = self.viewControllers.msgList = new ViewController( { client : self.client } );
|
|
|
|
|
2015-08-31 03:42:24 +00:00
|
|
|
async.series(
|
2015-08-27 05:04:04 +00:00
|
|
|
[
|
|
|
|
function callParentMciReady(callback) {
|
|
|
|
MessageListModule.super_.prototype.mciReady.call(this, mciData, callback);
|
|
|
|
},
|
|
|
|
function loadFromConfig(callback) {
|
|
|
|
var loadOpts = {
|
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu
|
|
|
|
};
|
|
|
|
|
|
|
|
vc.loadFromMenuConfig(loadOpts, callback);
|
2015-08-27 05:25:49 +00:00
|
|
|
},
|
|
|
|
function fetchMessagesInArea(callback) {
|
2015-09-04 06:02:28 +00:00
|
|
|
messageArea.getMessageListForArea( { client : self.client }, self.messageAreaName, function msgs(err, msgList) {
|
|
|
|
if(msgList && 0 === msgList.length) {
|
|
|
|
callback(new Error('No messages in area'));
|
|
|
|
} else {
|
|
|
|
self.messageList = msgList;
|
|
|
|
callback(err);
|
|
|
|
}
|
2015-08-28 04:20:24 +00:00
|
|
|
});
|
|
|
|
},
|
2015-08-31 03:42:24 +00:00
|
|
|
function populateList(callback) {
|
2015-08-28 04:20:24 +00:00
|
|
|
var msgListView = vc.getView(1);
|
|
|
|
|
|
|
|
// :TODO: {name!over5}, ...over6, over7... -> "text..." for format()
|
|
|
|
|
|
|
|
var msgNum = 1;
|
2015-08-31 03:42:24 +00:00
|
|
|
msgListView.setItems(_.map(self.messageList, function formatMsgListEntry(mle) {
|
2015-08-28 04:20:24 +00:00
|
|
|
return '{msgNum} - {subj} {to}'.format( {
|
|
|
|
msgNum : msgNum++,
|
|
|
|
subj : mle.subject,
|
2015-08-28 04:33:36 +00:00
|
|
|
to : mle.toUsername
|
2015-08-28 04:20:24 +00:00
|
|
|
} );
|
|
|
|
}));
|
|
|
|
|
|
|
|
msgListView.redraw();
|
2015-09-01 05:18:46 +00:00
|
|
|
|
|
|
|
callback(null);
|
2015-08-27 05:04:04 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
2015-08-28 04:20:24 +00:00
|
|
|
if(err) {
|
2015-09-04 06:02:28 +00:00
|
|
|
// :TODO: log this properly
|
|
|
|
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
2015-08-28 04:20:24 +00:00
|
|
|
console.log(err)
|
|
|
|
}
|
2015-08-27 05:04:04 +00:00
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|