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.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)) {
|
|
|
|
this.messageList = options.extraArgs.messageList;
|
|
|
|
this.messageIndex = options.extraArgs.messageIndex;
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
|
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-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
|
|
|
|
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;
|
|
|
|
case 'page down' : bodyView.keyPressPageDown(); break;
|
|
|
|
}
|
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,
|
|
|
|
replyToMessage : self.message,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return self.gotoMenu(extraArgs.menu, modOpts, cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
return this.messageIndex;
|
|
|
|
}
|
2016-09-05 03:36:26 +00:00
|
|
|
};
|