2015-09-01 05:18:46 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
// ENiGMA½
|
|
|
|
const FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
|
|
|
|
const Message = require('../core/message.js');
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
// deps
|
|
|
|
const _ = require('lodash');
|
2015-09-01 05:18:46 +00:00
|
|
|
|
|
|
|
exports.getModule = AreaViewFSEModule;
|
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Message Area View',
|
|
|
|
desc : 'Module for viewing an area message',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
|
|
|
function AreaViewFSEModule(options) {
|
|
|
|
FullScreenEditorModule.call(this, options);
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
const self = this;
|
2015-09-01 05:18:46 +00:00
|
|
|
|
|
|
|
this.editorType = 'area';
|
|
|
|
this.editorMode = 'view';
|
|
|
|
|
2015-09-06 21:58:58 +00:00
|
|
|
if(_.isObject(options.extraArgs)) {
|
|
|
|
this.messageList = options.extraArgs.messageList;
|
|
|
|
this.messageIndex = options.extraArgs.messageIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.messageList = this.messageList || [];
|
|
|
|
this.messageIndex = this.messageIndex || 0;
|
|
|
|
this.messageTotal = this.messageList.length;
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
this.menuMethods.nextMessage = function(formData, extraArgs, cb) {
|
2015-09-06 21:58:58 +00:00
|
|
|
if(self.messageIndex + 1 < self.messageList.length) {
|
2015-09-07 06:12:01 +00:00
|
|
|
self.messageIndex++;
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
return self.loadMessageByUuid(self.messageList[self.messageIndex].messageUuid, cb);
|
2015-09-06 21:58:58 +00:00
|
|
|
}
|
2016-07-25 20:35:58 +00:00
|
|
|
|
|
|
|
return cb(null);
|
2015-09-07 06:12:01 +00:00
|
|
|
};
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
this.menuMethods.prevMessage = function(formData, extraArgs, cb) {
|
2015-09-07 06:12:01 +00:00
|
|
|
if(self.messageIndex > 0) {
|
|
|
|
self.messageIndex--;
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
return self.loadMessageByUuid(self.messageList[self.messageIndex].messageUuid, cb);
|
2015-09-07 06:12:01 +00:00
|
|
|
}
|
2016-07-25 20:35:58 +00:00
|
|
|
|
|
|
|
return cb(null);
|
2015-09-07 06:12:01 +00:00
|
|
|
};
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
this.menuMethods.movementKeyPressed = function(formData, extraArgs, cb) {
|
|
|
|
const bodyView = self.viewControllers.body.getView(1); // :TODO: use const here vs magic #
|
2015-09-07 06:12:01 +00:00
|
|
|
|
2015-09-18 05:11:21 +00:00
|
|
|
// :TODO: Create methods for up/down vs using keyPressXXXXX
|
2015-09-07 06:12:01 +00:00
|
|
|
switch(formData.key.name) {
|
2016-07-25 20:35:58 +00:00
|
|
|
case 'down arrow' : bodyView.scrollDocumentUp(); break;
|
|
|
|
case 'up arrow' : bodyView.scrollDocumentDown(); break;
|
|
|
|
case 'page up' : bodyView.keyPressPageUp(); break;
|
|
|
|
case 'page down' : bodyView.keyPressPageDown(); break;
|
2015-09-07 06:12:01 +00:00
|
|
|
}
|
2015-09-20 04:55:09 +00:00
|
|
|
|
|
|
|
// :TODO: need to stop down/page down if doing so would push the last
|
2016-07-25 20:35:58 +00:00
|
|
|
// visible page off the screen at all .... this should be handled by MLTEV though...
|
|
|
|
|
|
|
|
return cb(null);
|
2015-09-20 04:55:09 +00:00
|
|
|
|
2015-09-06 21:58:58 +00:00
|
|
|
};
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
this.menuMethods.replyMessage = function(formData, extraArgs, cb) {
|
2015-09-13 00:18:46 +00:00
|
|
|
if(_.isString(extraArgs.menu)) {
|
2016-07-25 20:35:58 +00:00
|
|
|
const modOpts = {
|
2015-09-13 01:18:08 +00:00
|
|
|
extraArgs : {
|
2016-02-03 04:35:59 +00:00
|
|
|
messageAreaTag : self.messageAreaTag,
|
2015-09-13 01:18:08 +00:00
|
|
|
replyToMessage : self.message,
|
|
|
|
}
|
2015-09-13 00:18:46 +00:00
|
|
|
};
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
return self.gotoMenu(extraArgs.menu, modOpts, cb);
|
2015-09-13 00:18:46 +00:00
|
|
|
}
|
2016-07-25 20:35:58 +00:00
|
|
|
|
|
|
|
self.client.log(extraArgs, 'Missing extraArgs.menu');
|
|
|
|
return cb(null);
|
2015-09-13 00:18:46 +00:00
|
|
|
};
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
this.loadMessageByUuid = function(uuid, cb) {
|
|
|
|
const msg = new Message();
|
|
|
|
msg.load( { uuid : uuid, user : self.client.user }, () => {
|
2015-09-06 21:58:58 +00:00
|
|
|
self.setMessage(msg);
|
2016-07-25 20:35:58 +00:00
|
|
|
if(cb) {
|
|
|
|
return cb(null);
|
|
|
|
}
|
2015-09-06 21:58:58 +00:00
|
|
|
});
|
|
|
|
};
|
2015-09-01 05:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(AreaViewFSEModule, FullScreenEditorModule);
|
|
|
|
|
|
|
|
AreaViewFSEModule.prototype.finishedLoading = function() {
|
2015-09-06 21:58:58 +00:00
|
|
|
if(this.messageList.length) {
|
|
|
|
this.loadMessageByUuid(this.messageList[this.messageIndex].messageUuid);
|
|
|
|
}
|
2015-09-18 05:11:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AreaViewFSEModule.prototype.getSaveState = function() {
|
|
|
|
AreaViewFSEModule.super_.prototype.getSaveState.call(this);
|
|
|
|
|
|
|
|
return {
|
|
|
|
messageList : this.messageList,
|
|
|
|
messageIndex : this.messageIndex,
|
|
|
|
messageTotal : this.messageList.length,
|
2016-07-25 20:35:58 +00:00
|
|
|
};
|
2015-09-18 05:11:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AreaViewFSEModule.prototype.restoreSavedState = function(savedState) {
|
|
|
|
AreaViewFSEModule.super_.prototype.restoreSavedState.call(this, savedState);
|
|
|
|
|
|
|
|
this.messageList = savedState.messageList;
|
|
|
|
this.messageIndex = savedState.messageIndex;
|
|
|
|
this.messageTotal = savedState.messageTotal;
|
2015-09-01 05:18:46 +00:00
|
|
|
};
|