2015-09-01 05:18:46 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
// ENiGMA½
|
2017-11-24 23:23:15 +00:00
|
|
|
const FullScreenEditorModule = require('./fse.js').FullScreenEditorModule;
|
|
|
|
const Message = require('./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.moduleInfo = {
|
|
|
|
name : 'Message Area View',
|
|
|
|
desc : 'Module for viewing an area message',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class AreaViewFSEModule extends FullScreenEditorModule {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.editorType = 'area';
|
|
|
|
this.editorMode = 'view';
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
if(_.isObject(options.extraArgs)) {
|
2017-08-30 01:38:34 +00:00
|
|
|
this.messageList = options.extraArgs.messageList;
|
|
|
|
this.messageIndex = options.extraArgs.messageIndex;
|
|
|
|
this.lastMessageNextExit = options.extraArgs.lastMessageNextExit;
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.messageList = this.messageList || [];
|
|
|
|
this.messageIndex = this.messageIndex || 0;
|
|
|
|
this.messageTotal = this.messageList.length;
|
2015-09-07 06:12:01 +00:00
|
|
|
|
2018-02-01 05:45:03 +00:00
|
|
|
if(this.messageList.length > 0) {
|
|
|
|
this.messageAreaTag = this.messageList[this.messageIndex].areaTag;
|
|
|
|
}
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const self = this;
|
2016-07-25 20:35:58 +00:00
|
|
|
|
2017-01-28 19:33:06 +00:00
|
|
|
// assign *additional* menuMethods
|
|
|
|
Object.assign(this.menuMethods, {
|
2017-01-26 05:18:05 +00:00
|
|
|
nextMessage : (formData, extraArgs, cb) => {
|
|
|
|
if(self.messageIndex + 1 < self.messageList.length) {
|
|
|
|
self.messageIndex++;
|
2015-09-07 06:12:01 +00:00
|
|
|
|
2018-02-01 05:45:03 +00:00
|
|
|
this.messageAreaTag = this.messageList[this.messageIndex].areaTag;
|
|
|
|
this.tempMessageConfAndAreaSwitch(this.messageAreaTag, false); // false=don't record prev; we want what we entered the module with
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
return self.loadMessageByUuid(self.messageList[self.messageIndex].messageUuid, cb);
|
|
|
|
}
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2017-08-30 01:38:34 +00:00
|
|
|
// auto-exit if no more to go?
|
|
|
|
if(self.lastMessageNextExit) {
|
|
|
|
self.lastMessageReached = true;
|
|
|
|
return self.prevMenu(cb);
|
|
|
|
}
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
return cb(null);
|
|
|
|
},
|
2016-07-25 20:35:58 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
prevMessage : (formData, extraArgs, cb) => {
|
|
|
|
if(self.messageIndex > 0) {
|
|
|
|
self.messageIndex--;
|
2015-09-07 06:12:01 +00:00
|
|
|
|
2018-02-01 05:45:03 +00:00
|
|
|
this.messageAreaTag = this.messageList[this.messageIndex].areaTag;
|
|
|
|
this.tempMessageConfAndAreaSwitch(this.messageAreaTag, false); // false=don't record prev; we want what we entered the module with
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
return self.loadMessageByUuid(self.messageList[self.messageIndex].messageUuid, cb);
|
|
|
|
}
|
2015-09-07 06:12:01 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
return cb(null);
|
|
|
|
},
|
2015-09-20 04:55:09 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
movementKeyPressed : (formData, extraArgs, cb) => {
|
|
|
|
const bodyView = self.viewControllers.body.getView(1); // :TODO: use const here vs magic #
|
2016-07-25 20:35:58 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
// :TODO: Create methods for up/down vs using keyPressXXXXX
|
|
|
|
switch(formData.key.name) {
|
|
|
|
case 'down arrow' : bodyView.scrollDocumentUp(); break;
|
|
|
|
case 'up arrow' : bodyView.scrollDocumentDown(); break;
|
|
|
|
case 'page up' : bodyView.keyPressPageUp(); break;
|
2018-01-15 19:22:11 +00:00
|
|
|
case 'page down' : bodyView.keyPressPageDown(); break;
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-09-20 04:55:09 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
// :TODO: need to stop down/page down if doing so would push the last
|
|
|
|
// visible page off the screen at all .... this should be handled by MLTEV though...
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
return cb(null);
|
|
|
|
},
|
|
|
|
|
|
|
|
replyMessage : (formData, extraArgs, cb) => {
|
|
|
|
if(_.isString(extraArgs.menu)) {
|
|
|
|
const modOpts = {
|
|
|
|
extraArgs : {
|
|
|
|
messageAreaTag : self.messageAreaTag,
|
2018-01-15 19:22:11 +00:00
|
|
|
replyToMessage : self.message,
|
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return self.gotoMenu(extraArgs.menu, modOpts, cb);
|
|
|
|
}
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
self.client.log(extraArgs, 'Missing extraArgs.menu');
|
|
|
|
return cb(null);
|
|
|
|
}
|
2017-01-28 19:33:06 +00:00
|
|
|
});
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-09-13 00:18:46 +00:00
|
|
|
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
loadMessageByUuid(uuid, cb) {
|
2016-07-25 20:35:58 +00:00
|
|
|
const msg = new Message();
|
2017-01-26 05:18:05 +00:00
|
|
|
msg.load( { uuid : uuid, user : this.client.user }, () => {
|
|
|
|
this.setMessage(msg);
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
if(cb) {
|
|
|
|
return cb(null);
|
|
|
|
}
|
2015-09-06 21:58:58 +00:00
|
|
|
});
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
finishedLoading() {
|
2015-09-06 21:58:58 +00:00
|
|
|
this.loadMessageByUuid(this.messageList[this.messageIndex].messageUuid);
|
|
|
|
}
|
2015-09-18 05:11:21 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
getSaveState() {
|
|
|
|
return {
|
|
|
|
messageList : this.messageList,
|
|
|
|
messageIndex : this.messageIndex,
|
|
|
|
messageTotal : this.messageList.length,
|
|
|
|
};
|
|
|
|
}
|
2015-09-18 05:11:21 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
restoreSavedState(savedState) {
|
|
|
|
this.messageList = savedState.messageList;
|
|
|
|
this.messageIndex = savedState.messageIndex;
|
|
|
|
this.messageTotal = savedState.messageTotal;
|
|
|
|
}
|
2016-09-05 03:36:26 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
getMenuResult() {
|
2017-08-30 01:38:34 +00:00
|
|
|
return {
|
|
|
|
messageIndex : this.messageIndex,
|
|
|
|
lastMessageReached : this.lastMessageReached,
|
|
|
|
};
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2016-09-05 03:36:26 +00:00
|
|
|
};
|