2015-06-25 04:45:21 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2015-07-11 22:39:42 +00:00
|
|
|
var MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
var ViewController = require('../core/view_controller.js').ViewController;
|
|
|
|
var ansi = require('../core/ansi_term.js');
|
|
|
|
var theme = require('../core/theme.js');
|
|
|
|
var MultiLineEditTextView = require('../core/multi_line_edit_text_view.js').MultiLineEditTextView;
|
2015-07-16 05:51:00 +00:00
|
|
|
var Message = require('../core/message.js');
|
2015-06-25 04:45:21 +00:00
|
|
|
|
2015-07-11 22:39:42 +00:00
|
|
|
var async = require('async');
|
|
|
|
var assert = require('assert');
|
|
|
|
var _ = require('lodash');
|
2015-09-02 04:20:29 +00:00
|
|
|
var moment = require('moment');
|
2015-06-25 05:09:26 +00:00
|
|
|
|
2015-08-14 20:49:06 +00:00
|
|
|
exports.FullScreenEditorModule = FullScreenEditorModule;
|
|
|
|
|
|
|
|
// :TODO: clean this up:
|
|
|
|
|
2015-06-25 22:33:17 +00:00
|
|
|
exports.getModule = FullScreenEditorModule;
|
2015-06-25 04:45:21 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2015-06-25 22:33:17 +00:00
|
|
|
name : 'Full Screen Editor (FSE)',
|
|
|
|
desc : 'A full screen editor/viewer',
|
2015-06-25 04:45:21 +00:00
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
2015-09-02 04:20:29 +00:00
|
|
|
/*
|
|
|
|
MCI Codes - General
|
|
|
|
MA - Message Area Desc
|
|
|
|
|
|
|
|
MCI Codes - View Mode
|
|
|
|
Header
|
|
|
|
TL1 - From
|
|
|
|
TL2 - To
|
|
|
|
TL3 - Subject
|
|
|
|
|
|
|
|
TL5 - Date/Time (TODO: format)
|
2015-09-04 22:17:41 +00:00
|
|
|
TL6 - Message number
|
|
|
|
TL7 - Mesage total (in area)
|
|
|
|
TL8 - View Count
|
|
|
|
TL9 - Hash tags
|
|
|
|
TL10 - Message ID
|
|
|
|
TL11 - Reply to message ID
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2015-09-08 03:18:09 +00:00
|
|
|
TL12 - User1
|
|
|
|
TL13 - User2
|
|
|
|
|
2015-09-06 21:58:58 +00:00
|
|
|
Footer - Viewing
|
|
|
|
HM1 - Menu (prev/next/etc.)
|
|
|
|
|
|
|
|
TL6 - Message number
|
|
|
|
TL7 - Message total (in area)
|
|
|
|
|
2015-09-08 03:18:09 +00:00
|
|
|
TL12 - User1 (fmt message object)
|
|
|
|
TL13 - User2
|
|
|
|
|
2015-09-02 04:20:29 +00:00
|
|
|
|
|
|
|
*/
|
2015-09-04 06:02:28 +00:00
|
|
|
var MCICodeIds = {
|
2015-09-06 21:58:58 +00:00
|
|
|
ViewModeHeader : {
|
2015-09-04 22:17:41 +00:00
|
|
|
From : 1,
|
|
|
|
To : 2,
|
|
|
|
Subject : 3,
|
|
|
|
|
|
|
|
DateTime : 5,
|
|
|
|
MsgNum : 6,
|
|
|
|
MsgTotal : 7,
|
|
|
|
ViewCount : 8,
|
|
|
|
HashTags : 9,
|
|
|
|
MessageID : 10,
|
|
|
|
ReplyToMsgID : 11
|
2015-09-08 03:18:09 +00:00
|
|
|
},
|
|
|
|
ViewModeFooter : {
|
|
|
|
MsgNum : 6,
|
|
|
|
MsgTotal : 7,
|
2015-09-04 06:02:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-25 22:33:17 +00:00
|
|
|
function FullScreenEditorModule(options) {
|
2015-06-25 05:09:26 +00:00
|
|
|
MenuModule.call(this, options);
|
|
|
|
|
2015-06-26 04:34:33 +00:00
|
|
|
var self = this;
|
2015-08-14 20:49:06 +00:00
|
|
|
var config = this.menuConfig.config;
|
2015-07-13 20:58:45 +00:00
|
|
|
|
|
|
|
//
|
2015-08-10 01:32:38 +00:00
|
|
|
// menuConfig.config:
|
|
|
|
// editorType : email | area
|
2015-09-04 20:28:05 +00:00
|
|
|
// editorMode : view | edit | quote
|
2015-08-10 01:32:38 +00:00
|
|
|
//
|
2015-09-07 06:12:01 +00:00
|
|
|
// extraArgs - view mode
|
2015-08-20 23:05:02 +00:00
|
|
|
// messageAreaName
|
2015-09-07 06:12:01 +00:00
|
|
|
// messageIndex / messageTotal
|
2015-08-10 01:32:38 +00:00
|
|
|
//
|
2015-08-14 20:49:06 +00:00
|
|
|
//
|
|
|
|
this.editorType = config.editorType;
|
|
|
|
this.editorMode = config.editorMode;
|
2015-08-06 04:22:17 +00:00
|
|
|
|
2015-08-16 19:35:34 +00:00
|
|
|
if(_.isObject(options.extraArgs)) {
|
2015-09-04 22:35:08 +00:00
|
|
|
this.messageAreaName = options.extraArgs.messageAreaName || Message.WellKnownAreaNames.Private;
|
2015-09-07 06:12:01 +00:00
|
|
|
this.messageIndex = options.extraArgs.messageIndex || 0;
|
2015-09-04 22:35:08 +00:00
|
|
|
this.messageTotal = options.extraArgs.messageTotal || 0;
|
2015-08-16 19:35:34 +00:00
|
|
|
}
|
2015-09-06 21:58:58 +00:00
|
|
|
|
|
|
|
this.isReady = false;
|
2015-09-02 04:20:29 +00:00
|
|
|
|
|
|
|
this.isEditMode = function() {
|
|
|
|
return 'edit' === self.editorMode;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.isViewMode = function() {
|
|
|
|
return 'view' === self.editorMode;
|
|
|
|
};
|
2015-07-16 05:51:00 +00:00
|
|
|
|
2015-08-20 04:10:18 +00:00
|
|
|
this.isLocalEmail = function() {
|
2015-09-02 04:20:29 +00:00
|
|
|
return 'email' === self.editorType && Message.WellKnownAreaNames.Private === self.messageAreaName;
|
2015-08-20 04:10:18 +00:00
|
|
|
};
|
2015-07-09 04:07:25 +00:00
|
|
|
|
2015-09-04 20:28:05 +00:00
|
|
|
this.getFooterName = function() {
|
|
|
|
return 'footer' + _.capitalize(self.footerMode); // e.g. 'footerEditor', 'footerEditorMenu', ...
|
2015-07-09 04:07:25 +00:00
|
|
|
};
|
|
|
|
|
2015-07-10 05:23:37 +00:00
|
|
|
this.getFormId = function(name) {
|
2015-07-09 04:07:25 +00:00
|
|
|
return {
|
2015-09-04 20:28:05 +00:00
|
|
|
header : 0,
|
|
|
|
body : 1,
|
|
|
|
footerEditor : 2,
|
|
|
|
footerEditorMenu : 3,
|
|
|
|
footerView : 4,
|
2015-07-11 22:39:42 +00:00
|
|
|
|
2015-09-04 20:28:05 +00:00
|
|
|
help : 50,
|
2015-07-10 05:23:37 +00:00
|
|
|
}[name];
|
2015-07-09 04:07:25 +00:00
|
|
|
};
|
|
|
|
|
2015-09-04 20:28:05 +00:00
|
|
|
this.setInitialFooterMode = function() {
|
|
|
|
switch(self.editorMode) {
|
|
|
|
case 'edit' : self.footerMode = 'editor'; break;
|
|
|
|
case 'view' : self.footerMode = 'view'; break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
this.buildMessage = function() {
|
2015-07-13 20:58:45 +00:00
|
|
|
var headerValues = self.viewControllers.header.getFormData().value;
|
2015-07-13 04:56:33 +00:00
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
var msgOpts = {
|
2015-08-20 23:05:02 +00:00
|
|
|
areaName : self.messageAreaName,
|
2015-07-13 20:58:45 +00:00
|
|
|
toUserName : headerValues.to,
|
|
|
|
fromUserName : headerValues.from,
|
|
|
|
subject : headerValues.subject,
|
|
|
|
message : self.viewControllers.body.getFormData().value.message,
|
2015-07-13 04:56:33 +00:00
|
|
|
};
|
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
self.message = new Message(msgOpts);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setMessage = function(message) {
|
2015-09-06 21:58:58 +00:00
|
|
|
//console.log(message)
|
2015-09-02 04:20:29 +00:00
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
self.message = message;
|
2015-09-06 21:58:58 +00:00
|
|
|
|
|
|
|
if(self.isReady) {
|
|
|
|
self.initHeaderViewMode();
|
2015-09-08 03:18:09 +00:00
|
|
|
self.initFooterViewMode();
|
2015-09-06 21:58:58 +00:00
|
|
|
|
|
|
|
var bodyMessageView = self.viewControllers.body.getView(1);
|
|
|
|
if(bodyMessageView && _.has(self, 'message.message')) {
|
|
|
|
bodyMessageView.setText(self.message.message);
|
2015-09-07 06:12:01 +00:00
|
|
|
//bodyMessageView.redraw();
|
2015-09-06 21:58:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.getMessage = function() {
|
2015-09-02 04:20:29 +00:00
|
|
|
if(self.isEditMode()) {
|
2015-09-01 05:18:46 +00:00
|
|
|
self.buildMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.message;
|
2015-07-13 04:56:33 +00:00
|
|
|
};
|
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
this.redrawFooter = function(options, cb) {
|
|
|
|
async.waterfall(
|
|
|
|
[
|
|
|
|
function moveToFooterPosition(callback) {
|
|
|
|
//
|
|
|
|
// Calculate footer staring position
|
|
|
|
//
|
|
|
|
// row = (header height + body height)
|
|
|
|
//
|
|
|
|
// Header: mciData.body.height
|
|
|
|
// Body : We must find this in the config / theme
|
|
|
|
//
|
2015-07-10 21:24:30 +00:00
|
|
|
// :TODO: don't hard code this -- allow footer height to be part of theme/etc.
|
2015-09-08 03:18:09 +00:00
|
|
|
self.client.term.rawWrite(ansi.goto(24, 1));
|
2015-07-09 04:07:25 +00:00
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function clearFooterArea(callback) {
|
|
|
|
if(options.clear) {
|
2015-07-10 21:24:30 +00:00
|
|
|
self.client.term.rawWrite(ansi.reset() + ansi.deleteLine(3));
|
2015-07-09 04:07:25 +00:00
|
|
|
}
|
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function displayFooterArt(callback) {
|
|
|
|
var footerArt = self.menuConfig.config.art[options.footerName];
|
|
|
|
|
2015-07-25 22:10:12 +00:00
|
|
|
theme.displayThemedAsset(
|
2015-07-25 00:33:59 +00:00
|
|
|
footerArt,
|
|
|
|
self.client,
|
2015-07-25 22:10:12 +00:00
|
|
|
{ font : self.menuConfig.font },
|
|
|
|
function displayed(err, artData) {
|
2015-07-25 00:33:59 +00:00
|
|
|
callback(err, artData);
|
2015-07-25 22:10:12 +00:00
|
|
|
}
|
|
|
|
);
|
2015-07-09 04:07:25 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err, artData) {
|
|
|
|
cb(err, artData);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-07-11 22:39:42 +00:00
|
|
|
this.redrawScreen = function(options, cb) {
|
|
|
|
var comps = [ 'header', 'body' ];
|
|
|
|
var art = self.menuConfig.config.art;
|
|
|
|
|
|
|
|
self.client.term.rawWrite(ansi.resetScreen());
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function displayHeaderAndBody(callback) {
|
|
|
|
async.eachSeries( comps, function dispArt(n, next) {
|
2015-07-25 22:10:12 +00:00
|
|
|
theme.displayThemedAsset(
|
2015-07-25 00:33:59 +00:00
|
|
|
art[n],
|
|
|
|
self.client,
|
2015-07-25 22:10:12 +00:00
|
|
|
{ font : self.menuConfig.font },
|
2015-07-25 00:33:59 +00:00
|
|
|
function displayed(err, artData) {
|
|
|
|
next(err);
|
2015-07-25 22:10:12 +00:00
|
|
|
}
|
|
|
|
);
|
2015-07-11 22:39:42 +00:00
|
|
|
}, function complete(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function displayFooter(callback) {
|
|
|
|
// we have to treat the footer special
|
|
|
|
self.redrawFooter( { clear : false, footerName : self.getFooterName() }, function footerDisplayed(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function refreshViews(callback) {
|
|
|
|
comps.push(self.getFooterName());
|
|
|
|
|
|
|
|
comps.forEach(function artComp(n) {
|
|
|
|
self.viewControllers[n].redrawAll();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
this.switchFooter = function(cb) {
|
|
|
|
var footerName = self.getFooterName();
|
|
|
|
|
|
|
|
self.redrawFooter( { footerName : footerName, clear : true }, function artDisplayed(err, artData) {
|
|
|
|
if(err) {
|
|
|
|
cb(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var formId = self.getFormId(footerName);
|
|
|
|
|
|
|
|
if(_.isUndefined(self.viewControllers[footerName])) {
|
|
|
|
var menuLoadOpts = {
|
|
|
|
callingMenu : self,
|
|
|
|
formId : formId,
|
|
|
|
mciMap : artData.mciMap
|
|
|
|
};
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
footerName,
|
|
|
|
new ViewController( { client : self.client, formId : formId } )
|
|
|
|
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.viewControllers[footerName].redrawAll();
|
|
|
|
cb(null);
|
|
|
|
}
|
|
|
|
});
|
2015-07-06 01:05:55 +00:00
|
|
|
};
|
|
|
|
|
2015-06-25 05:09:26 +00:00
|
|
|
this.initSequence = function() {
|
2015-06-26 04:34:33 +00:00
|
|
|
var mciData = { };
|
2015-07-04 18:02:37 +00:00
|
|
|
var art = self.menuConfig.config.art;
|
|
|
|
assert(_.isObject(art));
|
2015-06-26 04:34:33 +00:00
|
|
|
|
2015-07-06 01:05:55 +00:00
|
|
|
async.series(
|
2015-06-25 05:09:26 +00:00
|
|
|
[
|
|
|
|
function beforeDisplayArt(callback) {
|
|
|
|
self.beforeArt();
|
|
|
|
callback(null);
|
|
|
|
},
|
2015-07-09 04:07:25 +00:00
|
|
|
function displayHeaderAndBodyArt(callback) {
|
2015-07-04 18:02:37 +00:00
|
|
|
assert(_.isString(art.header));
|
|
|
|
assert(_.isString(art.body));
|
|
|
|
|
|
|
|
async.eachSeries( [ 'header', 'body' ], function dispArt(n, next) {
|
2015-08-03 00:27:05 +00:00
|
|
|
theme.displayThemedAsset(
|
2015-07-25 00:33:59 +00:00
|
|
|
art[n],
|
|
|
|
self.client,
|
2015-07-25 22:10:12 +00:00
|
|
|
{ font : self.menuConfig.font },
|
2015-07-25 00:33:59 +00:00
|
|
|
function displayed(err, artData) {
|
|
|
|
mciData[n] = artData;
|
|
|
|
next(err);
|
2015-07-25 22:10:12 +00:00
|
|
|
}
|
|
|
|
);
|
2015-07-04 18:02:37 +00:00
|
|
|
}, function complete(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
2015-07-09 04:07:25 +00:00
|
|
|
function displayFooter(callback) {
|
2015-09-04 20:28:05 +00:00
|
|
|
self.setInitialFooterMode();
|
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
var footerName = self.getFooterName();
|
2015-09-06 21:58:58 +00:00
|
|
|
console.log(footerName)
|
2015-07-09 04:07:25 +00:00
|
|
|
self.redrawFooter( { footerName : footerName }, function artDisplayed(err, artData) {
|
2015-07-06 01:05:55 +00:00
|
|
|
mciData[footerName] = artData;
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
2015-06-26 04:34:33 +00:00
|
|
|
function afterArtDisplayed(callback) {
|
2015-09-06 21:58:58 +00:00
|
|
|
self.mciReady(mciData, callback);
|
2015-06-26 04:34:33 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
2015-09-01 05:18:46 +00:00
|
|
|
if(err) {
|
|
|
|
console.log(err)
|
2015-09-06 21:58:58 +00:00
|
|
|
} else {
|
|
|
|
self.isReady = true;
|
|
|
|
self.finishedLoading();
|
2015-09-01 05:18:46 +00:00
|
|
|
}
|
2015-06-26 04:34:33 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-08-16 19:35:34 +00:00
|
|
|
this.createInitialViews = function(mciData, cb) {
|
|
|
|
|
|
|
|
var menuLoadOpts = { callingMenu : self };
|
2015-08-14 20:49:06 +00:00
|
|
|
|
2015-07-04 18:02:37 +00:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function header(callback) {
|
2015-07-09 04:07:25 +00:00
|
|
|
menuLoadOpts.formId = self.getFormId('header');
|
2015-07-04 18:02:37 +00:00
|
|
|
menuLoadOpts.mciMap = mciData.header.mciMap;
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
'header',
|
2015-07-09 04:07:25 +00:00
|
|
|
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
|
2015-07-04 18:02:37 +00:00
|
|
|
).loadFromMenuConfig(menuLoadOpts, function headerReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function body(callback) {
|
2015-07-09 04:07:25 +00:00
|
|
|
menuLoadOpts.formId = self.getFormId('body');
|
2015-07-04 18:02:37 +00:00
|
|
|
menuLoadOpts.mciMap = mciData.body.mciMap;
|
|
|
|
|
2015-09-06 21:58:58 +00:00
|
|
|
console.log('creating body.l..')
|
|
|
|
|
2015-07-04 18:02:37 +00:00
|
|
|
self.addViewController(
|
|
|
|
'body',
|
2015-07-09 04:07:25 +00:00
|
|
|
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
|
2015-07-04 18:02:37 +00:00
|
|
|
).loadFromMenuConfig(menuLoadOpts, function bodyReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
2015-07-06 01:05:55 +00:00
|
|
|
},
|
|
|
|
function footer(callback) {
|
2015-07-09 04:07:25 +00:00
|
|
|
var footerName = self.getFooterName();
|
2015-07-06 01:05:55 +00:00
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
menuLoadOpts.formId = self.getFormId(footerName);
|
2015-07-06 01:05:55 +00:00
|
|
|
menuLoadOpts.mciMap = mciData[footerName].mciMap;
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
footerName,
|
2015-07-09 04:07:25 +00:00
|
|
|
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
|
2015-07-06 01:05:55 +00:00
|
|
|
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
2015-08-16 19:35:34 +00:00
|
|
|
},
|
|
|
|
function prepareViewStates(callback) {
|
|
|
|
var header = self.viewControllers.header;
|
|
|
|
var from = header.getView(1);
|
|
|
|
from.acceptsFocus = false;
|
2015-09-01 21:37:03 +00:00
|
|
|
//from.setText(self.client.user.username);
|
2015-08-16 19:35:34 +00:00
|
|
|
|
2015-09-02 04:20:29 +00:00
|
|
|
// :TODO: make this a method
|
2015-08-16 19:35:34 +00:00
|
|
|
var body = self.viewControllers.body.getView(1);
|
|
|
|
self.updateTextEditMode(body.getTextEditMode());
|
|
|
|
self.updateEditModePosition(body.getEditPosition());
|
|
|
|
|
2015-09-02 04:20:29 +00:00
|
|
|
// :TODO: If view mode, set body to read only... which needs an impl...
|
|
|
|
|
2015-08-16 19:35:34 +00:00
|
|
|
callback(null);
|
|
|
|
},
|
2015-09-01 21:37:03 +00:00
|
|
|
function setInitialData(callback) {
|
2015-09-02 04:20:29 +00:00
|
|
|
|
2015-09-03 05:11:17 +00:00
|
|
|
switch(self.editorMode) {
|
2015-09-01 21:37:03 +00:00
|
|
|
case 'view' :
|
|
|
|
if(self.message) {
|
2015-09-03 05:11:17 +00:00
|
|
|
self.initHeaderViewMode();
|
2015-09-08 03:18:09 +00:00
|
|
|
self.initFooterViewMode();
|
2015-09-02 04:20:29 +00:00
|
|
|
|
|
|
|
var bodyMessageView = self.viewControllers.body.getView(1);
|
|
|
|
if(bodyMessageView && _.has(self, 'message.message')) {
|
|
|
|
bodyMessageView.setText(self.message.message);
|
|
|
|
}
|
2015-09-01 21:37:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'edit' :
|
|
|
|
self.viewControllers.header.getView(1).setText(self.client.user.username); // from
|
|
|
|
break;
|
2015-09-01 05:18:46 +00:00
|
|
|
}
|
2015-09-01 21:37:03 +00:00
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
callback(null);
|
|
|
|
},
|
2015-08-16 19:35:34 +00:00
|
|
|
function setInitialFocus(callback) {
|
2015-09-02 04:20:29 +00:00
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
switch(self.editorMode) {
|
2015-09-04 20:28:05 +00:00
|
|
|
case 'edit' :
|
2015-09-01 05:18:46 +00:00
|
|
|
self.switchToHeader();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'view' :
|
2015-09-06 21:58:58 +00:00
|
|
|
self.switchToFooter();
|
2015-09-01 05:18:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-08-16 19:35:34 +00:00
|
|
|
|
|
|
|
callback(null);
|
2015-07-04 18:02:37 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
2015-08-16 19:35:34 +00:00
|
|
|
cb(err);
|
2015-07-04 18:02:37 +00:00
|
|
|
}
|
2015-08-16 19:35:34 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-09-06 21:58:58 +00:00
|
|
|
this.mciReadyHandler = function(mciData, cb) {
|
2015-08-16 19:35:34 +00:00
|
|
|
|
|
|
|
self.createInitialViews(mciData, function viewsCreated(err) {
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2015-08-20 04:10:18 +00:00
|
|
|
self.viewControllers.header.on('leave', function headerViewLeave(view) {
|
|
|
|
|
|
|
|
if(2 === view.id) { // "to" field
|
|
|
|
self.validateToUserName(view.getData(), function result(err) {
|
|
|
|
if(err) {
|
|
|
|
// :TODO: display a error in a %TL area or such
|
|
|
|
view.clearText();
|
|
|
|
self.viewControllers.headers.switchFocus(2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-09-06 21:58:58 +00:00
|
|
|
|
|
|
|
cb(err);
|
2015-08-16 19:35:34 +00:00
|
|
|
});
|
2015-07-04 18:02:37 +00:00
|
|
|
};
|
|
|
|
|
2015-07-06 01:05:55 +00:00
|
|
|
this.updateEditModePosition = function(pos) {
|
2015-09-06 21:58:58 +00:00
|
|
|
if(self.isEditMode()) {
|
2015-09-04 20:28:05 +00:00
|
|
|
var posView = self.viewControllers.footerEditor.getView(1);
|
2015-07-06 01:05:55 +00:00
|
|
|
if(posView) {
|
2015-07-06 05:16:22 +00:00
|
|
|
self.client.term.rawWrite(ansi.savePos());
|
|
|
|
posView.setText(_.padLeft(String(pos.row + 1), 2, '0') + ',' + _.padLeft(String(pos.col + 1), 2, '0'));
|
|
|
|
self.client.term.rawWrite(ansi.restorePos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.updateTextEditMode = function(mode) {
|
2015-09-06 21:58:58 +00:00
|
|
|
if(self.isEditMode()) {
|
2015-09-04 20:28:05 +00:00
|
|
|
var modeView = self.viewControllers.footerEditor.getView(2);
|
2015-07-06 05:16:22 +00:00
|
|
|
if(modeView) {
|
|
|
|
self.client.term.rawWrite(ansi.savePos());
|
|
|
|
modeView.setText('insert' === mode ? 'INS' : 'OVR');
|
|
|
|
self.client.term.rawWrite(ansi.restorePos());
|
2015-07-06 01:05:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-03 05:11:17 +00:00
|
|
|
this.initHeaderViewMode = function() {
|
2015-09-02 04:20:29 +00:00
|
|
|
assert(_.isObject(self.message));
|
|
|
|
|
2015-09-03 05:11:17 +00:00
|
|
|
function setHeaderText(id, text) {
|
|
|
|
var v = self.viewControllers.header.getView(id);
|
|
|
|
if(v) {
|
|
|
|
v.setText(text);
|
|
|
|
}
|
|
|
|
}
|
2015-09-04 06:02:28 +00:00
|
|
|
|
2015-09-06 21:58:58 +00:00
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.From, self.message.fromUserName);
|
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.To, self.message.toUserName);
|
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.Subject, self.message.subject);
|
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.DateTime, moment(self.message.modTimestamp).format(self.client.currentTheme.helpers.getDateTimeFormat()));
|
2015-09-07 06:12:01 +00:00
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.MsgNum, (self.messageIndex + 1).toString());
|
2015-09-06 21:58:58 +00:00
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.MsgTotal, self.messageTotal.toString());
|
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.ViewCount, self.message.viewCount);
|
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.HashTags, 'TODO hash tags');
|
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.MessageID, self.message.messageId);
|
|
|
|
setHeaderText(MCICodeIds.ViewModeHeader.ReplyToMsgID, self.message.replyToMessageId);
|
2015-07-11 22:39:42 +00:00
|
|
|
};
|
|
|
|
|
2015-09-08 03:18:09 +00:00
|
|
|
this.initFooterViewMode = function() {
|
|
|
|
|
|
|
|
function setFooterText(id, text) {
|
|
|
|
var v = self.viewControllers.footerView.getView(id);
|
|
|
|
if(v) {
|
|
|
|
v.setText(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setFooterText(MCICodeIds.ViewModeFooter.MsgNum, (self.messageIndex + 1).toString());
|
|
|
|
setFooterText(MCICodeIds.ViewModeFooter.MsgTotal, self.messageTotal.toString());
|
|
|
|
};
|
|
|
|
|
2015-07-12 02:12:07 +00:00
|
|
|
this.displayHelp = function() {
|
2015-07-11 22:39:42 +00:00
|
|
|
self.client.term.rawWrite(ansi.resetScreen());
|
|
|
|
|
|
|
|
theme.displayThemeArt( { name : self.menuConfig.config.art.help, client : self.client },
|
2015-07-12 02:12:07 +00:00
|
|
|
function helpDisplayed(err, artData) {
|
2015-07-11 22:39:42 +00:00
|
|
|
self.client.waitForKeyPress(function keyPress(ch, key) {
|
|
|
|
self.redrawScreen();
|
2015-09-04 20:28:05 +00:00
|
|
|
self.viewControllers.footerEditorMenu.setFocus(true);
|
2015-07-11 22:39:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
this.observeEditorEvents = function() {
|
2015-07-12 02:12:07 +00:00
|
|
|
var bodyView = self.viewControllers.body.getView(1);
|
2015-07-09 22:28:44 +00:00
|
|
|
|
|
|
|
bodyView.on('edit position', function cursorPosUpdate(pos) {
|
|
|
|
self.updateEditModePosition(pos);
|
|
|
|
});
|
|
|
|
|
|
|
|
bodyView.on('text edit mode', function textEditMode(mode) {
|
|
|
|
self.updateTextEditMode(mode);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
this.switchToHeader = function() {
|
|
|
|
self.viewControllers.body.setFocus(false);
|
|
|
|
self.viewControllers.header.switchFocus(2); // to
|
|
|
|
};
|
|
|
|
|
|
|
|
this.switchToBody = function() {
|
|
|
|
self.viewControllers.header.setFocus(false);
|
|
|
|
self.viewControllers.body.switchFocus(1);
|
|
|
|
|
|
|
|
self.observeEditorEvents();
|
|
|
|
};
|
|
|
|
|
2015-09-06 21:58:58 +00:00
|
|
|
this.switchToFooter = function() {
|
|
|
|
self.viewControllers.header.setFocus(false);
|
|
|
|
self.viewControllers.body.setFocus(false);
|
|
|
|
|
|
|
|
self.viewControllers[self.getFooterName()].switchFocus(1); // HM1
|
|
|
|
};
|
|
|
|
|
2015-06-25 05:12:03 +00:00
|
|
|
|
2015-06-27 21:32:29 +00:00
|
|
|
this.menuMethods = {
|
2015-09-04 22:58:54 +00:00
|
|
|
// :TODO: rename to editModeHeaderSubmit
|
2015-07-04 18:02:37 +00:00
|
|
|
headerSubmit : function(formData, extraArgs) {
|
2015-09-01 05:18:46 +00:00
|
|
|
self.switchToBody();
|
2015-07-04 18:02:37 +00:00
|
|
|
},
|
2015-07-09 04:49:22 +00:00
|
|
|
editModeEscPressed : function(formData, extraArgs) {
|
2015-09-04 20:28:05 +00:00
|
|
|
self.footerMode = 'editor' === self.footerMode ? 'editorMenu' : 'editor';
|
2015-07-10 05:23:37 +00:00
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
self.switchFooter(function next(err) {
|
|
|
|
if(err) {
|
|
|
|
// :TODO:... what now?
|
|
|
|
console.log(err)
|
|
|
|
} else {
|
2015-09-04 20:28:05 +00:00
|
|
|
switch(self.footerMode) {
|
2015-09-04 06:02:28 +00:00
|
|
|
case 'editor' :
|
2015-09-04 20:28:05 +00:00
|
|
|
if(!_.isUndefined(self.viewControllers.footerEditorMenu)) {
|
|
|
|
self.viewControllers.footerEditorMenu.setFocus(false);
|
2015-07-09 04:49:22 +00:00
|
|
|
}
|
|
|
|
self.viewControllers.body.switchFocus(1);
|
2015-09-01 05:18:46 +00:00
|
|
|
self.observeEditorEvents();
|
2015-07-09 04:49:22 +00:00
|
|
|
break;
|
|
|
|
|
2015-09-04 20:28:05 +00:00
|
|
|
case 'editorMenu' :
|
2015-07-09 04:49:22 +00:00
|
|
|
self.viewControllers.body.setFocus(false);
|
2015-09-04 20:28:05 +00:00
|
|
|
self.viewControllers.footerEditorMenu.switchFocus(1);
|
2015-07-09 04:49:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default : throw new Error('Unexpected mode');
|
|
|
|
}
|
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
}
|
|
|
|
});
|
2015-07-09 04:49:22 +00:00
|
|
|
},
|
2015-08-16 19:35:34 +00:00
|
|
|
/*
|
2015-07-12 02:12:07 +00:00
|
|
|
editModeMenuSave : function(formData, extraArgs) {
|
2015-08-10 01:32:38 +00:00
|
|
|
var msg = self.getMessage();
|
|
|
|
console.log(msg);
|
2015-08-16 19:35:34 +00:00
|
|
|
},*/
|
2015-07-12 06:32:31 +00:00
|
|
|
editModeMenuQuote : function(formData, extraArgs) {
|
|
|
|
|
2015-07-12 02:12:07 +00:00
|
|
|
},
|
|
|
|
editModeMenuHelp : function(formData, extraArgs) {
|
2015-09-04 20:28:05 +00:00
|
|
|
self.viewControllers.footerEditorMenu.setFocus(false);
|
2015-07-12 02:12:07 +00:00
|
|
|
self.displayHelp();
|
2015-09-04 22:58:54 +00:00
|
|
|
},
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// View Mode
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
viewModeEscPressed : function(formData, extraArgs) {
|
|
|
|
//
|
|
|
|
// MLTEV won't get key events -- we need to handle them all here?
|
|
|
|
// ...up/down, page up/page down... both should go by pages
|
|
|
|
// ...Next/Prev/Etc. here
|
2015-06-27 21:32:29 +00:00
|
|
|
}
|
2015-06-25 05:09:26 +00:00
|
|
|
};
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2015-09-04 06:02:28 +00:00
|
|
|
if(_.has(options, 'extraArgs.message')) {
|
2015-09-01 05:18:46 +00:00
|
|
|
this.setMessage(options.extraArgs.message);
|
|
|
|
}
|
2015-06-25 04:45:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-25 22:33:17 +00:00
|
|
|
require('util').inherits(FullScreenEditorModule, MenuModule);
|
2015-06-25 05:09:26 +00:00
|
|
|
|
2015-06-25 22:33:17 +00:00
|
|
|
FullScreenEditorModule.prototype.enter = function(client) {
|
|
|
|
FullScreenEditorModule.super_.prototype.enter.call(this, client);
|
2015-06-25 05:09:26 +00:00
|
|
|
};
|
|
|
|
|
2015-09-06 21:58:58 +00:00
|
|
|
FullScreenEditorModule.prototype.mciReady = function(mciData, cb) {
|
|
|
|
this.mciReadyHandler(mciData, cb);
|
2015-08-14 20:49:06 +00:00
|
|
|
//this['mciReadyHandler' + _.capitalize(this.editorType)](mciData);
|
2015-06-26 04:34:33 +00:00
|
|
|
};
|
|
|
|
|
2015-08-20 04:10:18 +00:00
|
|
|
FullScreenEditorModule.prototype.validateToUserName = function(un, cb) {
|
|
|
|
cb(null); // note: to be implemented by sub classes
|
|
|
|
};
|