2015-06-25 04:45:21 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2015-06-26 04:34:33 +00:00
|
|
|
var MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
var ViewController = require('../core/view_controller.js').ViewController;
|
2015-07-06 01:05:55 +00:00
|
|
|
var ansi = require('../core/ansi_term.js');
|
2015-06-25 04:45:21 +00:00
|
|
|
|
2015-06-26 04:34:33 +00:00
|
|
|
var async = require('async');
|
|
|
|
var assert = require('assert');
|
|
|
|
var _ = require('lodash');
|
2015-06-25 05:09:26 +00:00
|
|
|
|
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-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;
|
|
|
|
this.menuConfig = options.menuConfig;
|
|
|
|
this.editorType = this.menuConfig.config.editorType;
|
2015-07-04 18:02:37 +00:00
|
|
|
this.artNames = [ 'header', 'body', 'footerEdit', 'footerEditMenu', 'footerView' ];
|
|
|
|
this.editorMode = 'edit'; // :TODO: This needs to be passed in via args
|
2015-06-25 05:09:26 +00:00
|
|
|
|
2015-07-06 01:05:55 +00:00
|
|
|
this.getFooterName = function(menu) {
|
|
|
|
return true === menu ?
|
|
|
|
'footerEditMenu' : {
|
|
|
|
edit : 'footerEdit',
|
|
|
|
view : 'footerView',
|
|
|
|
}[self.editorMode];
|
|
|
|
};
|
|
|
|
|
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-04 18:02:37 +00:00
|
|
|
function displayArtHeaderAndBody(callback) {
|
|
|
|
assert(_.isString(art.header));
|
|
|
|
assert(_.isString(art.body));
|
|
|
|
|
|
|
|
async.eachSeries( [ 'header', 'body' ], function dispArt(n, next) {
|
|
|
|
self.displayArtAsset(art[n], function artDisplayed(err, artData) {
|
|
|
|
mciData[n] = artData;
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
}, function complete(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
2015-07-06 01:05:55 +00:00
|
|
|
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
|
|
|
|
//
|
|
|
|
// :TODO: don't hard code this -- allow footer to be themed/etc.
|
|
|
|
self.client.term.rawWrite(ansi.goto(23, 1));
|
2015-07-04 18:02:37 +00:00
|
|
|
callback(null);
|
|
|
|
},
|
2015-07-06 01:05:55 +00:00
|
|
|
function displayArtFooter(callback) {
|
|
|
|
var footerName = self.getFooterName(false);
|
|
|
|
|
|
|
|
self.displayArtAsset(art[footerName], function artDisplayed(err, artData) {
|
|
|
|
mciData[footerName] = artData;
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
2015-06-26 04:34:33 +00:00
|
|
|
function afterArtDisplayed(callback) {
|
|
|
|
self.mciReady(mciData);
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-07-04 18:02:37 +00:00
|
|
|
this.mciReadyHandlerNetMail = function(mciData) {
|
|
|
|
|
|
|
|
var menuLoadOpts = { callingMenu : self };
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function header(callback) {
|
|
|
|
menuLoadOpts.formId = 0;
|
|
|
|
menuLoadOpts.mciMap = mciData.header.mciMap;
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
'header',
|
2015-07-06 01:05:55 +00:00
|
|
|
new ViewController( { client : self.client, formId : 0 } )
|
2015-07-04 18:02:37 +00:00
|
|
|
).loadFromMenuConfig(menuLoadOpts, function headerReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function body(callback) {
|
|
|
|
menuLoadOpts.formId = 1;
|
|
|
|
menuLoadOpts.mciMap = mciData.body.mciMap;
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
'body',
|
2015-07-06 01:05:55 +00:00
|
|
|
new ViewController( { client : self.client, formId : 1 } )
|
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) {
|
|
|
|
var footerName = self.getFooterName(false);
|
|
|
|
|
|
|
|
menuLoadOpts.formId = 2;
|
|
|
|
menuLoadOpts.mciMap = mciData[footerName].mciMap;
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
footerName,
|
|
|
|
new ViewController( { client : self.client, formId : 2 } )
|
|
|
|
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
2015-07-04 18:02:37 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
2015-07-06 05:16:22 +00:00
|
|
|
var bodyView = self.getBodyView();
|
|
|
|
self.updateTextEditMode(bodyView.getTextEditMode());
|
|
|
|
self.updateEditModePosition(bodyView.getEditPosition());
|
|
|
|
|
2015-07-04 18:02:37 +00:00
|
|
|
self.viewControllers.body.removeFocus(); // :TODO: Change vc to allow *not* setting focus @ create
|
|
|
|
self.viewControllers.header.switchFocus(1);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-07-06 01:05:55 +00:00
|
|
|
this.getBodyView = function() {
|
|
|
|
return self.viewControllers.body.getView(1);
|
2015-06-27 21:32:29 +00:00
|
|
|
};
|
2015-07-06 01:05:55 +00:00
|
|
|
|
|
|
|
this.updateEditModePosition = function(pos) {
|
|
|
|
if('edit' === this.editorMode) {
|
|
|
|
var posView = self.viewControllers[self.getFooterName(false)].getView(1);
|
|
|
|
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) {
|
|
|
|
if('edit' === this.editorMode) {
|
|
|
|
var modeView = self.viewControllers[self.getFooterName(false)].getView(2);
|
|
|
|
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-06-25 05:12:03 +00:00
|
|
|
|
2015-06-27 21:32:29 +00:00
|
|
|
this.menuMethods = {
|
2015-07-04 18:02:37 +00:00
|
|
|
headerSubmit : function(formData, extraArgs) {
|
2015-07-06 01:05:55 +00:00
|
|
|
// console.log('submit header:\n' + JSON.stringify(self.viewControllers.header.getFormData()))
|
|
|
|
self.viewControllers.header.removeFocus();
|
2015-07-04 18:02:37 +00:00
|
|
|
self.viewControllers.body.switchFocus(1);
|
2015-07-06 01:05:55 +00:00
|
|
|
|
2015-07-07 05:26:16 +00:00
|
|
|
self.getBodyView().on('edit position', function cursorPosUpdate(pos) {
|
2015-07-06 01:05:55 +00:00
|
|
|
self.updateEditModePosition(pos);
|
|
|
|
});
|
2015-07-06 05:16:22 +00:00
|
|
|
|
|
|
|
self.getBodyView().on('text edit mode', function textEditMode(mode) {
|
|
|
|
self.updateTextEditMode(mode);
|
|
|
|
});
|
2015-07-04 18:02:37 +00:00
|
|
|
},
|
2015-06-27 21:32:29 +00:00
|
|
|
editorEscPressed : function(formData, extraArgs) {
|
2015-06-29 04:31:12 +00:00
|
|
|
|
2015-06-27 21:32:29 +00:00
|
|
|
}
|
2015-06-25 05:09:26 +00:00
|
|
|
};
|
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-06-26 04:34:33 +00:00
|
|
|
FullScreenEditorModule.prototype.mciReady = function(mciData) {
|
|
|
|
this['mciReadyHandler' + _.capitalize(this.editorType)](mciData);
|
|
|
|
};
|
|
|
|
|