* Progress on FSE class/integration

* Use "proxy" for submit
* More key support... probably just missed it from other box, will merge later
This commit is contained in:
Bryan Ashby 2015-08-13 22:30:55 -06:00
parent 6d49e5e55f
commit 6257208c5e
4 changed files with 150 additions and 90 deletions

View File

@ -24,13 +24,14 @@ function FullScreenEditor(options) {
var self = this;
//
// options.callingMenu : menu that created us
// options.client
// options.art{} : name -> artAsset
// options.font : optional
// options.editorMode (view|edit|quote) | (editMenu|)
//
// options.editorType : email | area
this.callingMenu = options.callingMenu;
this.client = options.client;
this.art = options.art;
this.font = options.font;
@ -59,6 +60,10 @@ function FullScreenEditor(options) {
}[name];
};
this.isViewMode = function() {
return 'view' === this.editorMode;
};
this.redrawFooter = function(options, cb) {
async.waterfall(
[
@ -152,65 +157,9 @@ function FullScreenEditor(options) {
);
};
/*
this.createViewsForEmail = function() {
var menuLoadOpts = { callingMenu : self };
async.series(
[
function header(callback) {
menuLoadOpts.formId = self.getFormId('header');
menuLoadOpts.mciMap = self.mciData.header.mciMap;
self.addViewController(
'header',
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
).loadFromMenuConfig(menuLoadOpts, function headerReady(err) {
callback(err);
});
},
function body(callback) {
menuLoadOpts.formId = self.getFormId('body');
menuLoadOpts.mciMap = self.mciData.body.mciMap;
self.addViewController(
'body',
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
).loadFromMenuConfig(menuLoadOpts, function bodyReady(err) {
callback(err);
});
},
function footer(callback) {
var footerName = self.getFooterName();
menuLoadOpts.formId = self.getFormId(footerName);
menuLoadOpts.mciMap = self.mciData[footerName].mciMap;
self.addViewController(
footerName,
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
callback(err);
});
}
],
function complete(err) {
var bodyView = self.viewControllers.body.getView(1);
//self.updateTextEditMode(bodyView.getTextEditMode());
//self.updateEditModePosition(bodyView.getEditPosition());
//self.viewControllers.body.setFocus(false);
//self.viewControllers.header.switchFocus(1);
cb(err);
}
);
};
*/
this.createInitialViews = function(cb) {
var menuLoadOpts = { callingMenu : self };
var menuLoadOpts = { callingMenu : self.callingMenu };
async.series(
[
@ -269,19 +218,34 @@ function FullScreenEditor(options) {
);
};
this.initObservers = function() {
// :TODO: Should probably still allow key mapping/etc. to come from module for this stuff
this.switchFooter = function(cb) {
var footerName = self.getFooterName();
this.viewControllers.header.on('submit', function headerSubmit(formData, extraArgs) {
// :TODO: we need to validate the "to" here
self.viewControllers.header.setFocus(false);
self.viewControllers.body.switchFocus(1);
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])) {
console.log(artData)
var menuLoadOpts = {
callingMenu : self.callingMenu,
formId : formId,
mciMap : artData.mciMap
};
self.addViewController(
footerName,
new ViewController( { client : self.client, formId : formId } )
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
cb(err);
});
this.viewControllers.body.on('submit', function bodySubmit(formData, extraArgs) {
if(formData.key && 'escape' === formData.key.name) {
console.log('toggle menu depending on mode...')
} else {
self.viewControllers[footerName].redrawAll();
cb(null);
}
});
};
@ -306,14 +270,12 @@ FullScreenEditor.prototype.enter = function() {
callback(err);
});
},
function prepObservers(callback) {
self.initObservers();
callback(null);
}
],
function complete(err) {
if(err) {
self.emit('error', err);
}
}
);
};
@ -321,4 +283,43 @@ FullScreenEditor.prototype.leave = function() {
};
FullScreenEditor.prototype.submitHandler = function(formData, extraArgs) {
var self = this;
// :TODO: Use key map from config for this stuff
if(formData.id === self.getFormId('header')) {
// :TODO: we need to validate the "to" here
self.viewControllers.header.setFocus(false);
self.viewControllers.body.switchFocus(1);
} else if(formData.id === self.getFormId('body') && formData.key && 'escape' === formData.key.name) {
if(!self.isViewMode()) {
self.editorMode = 'edit' === self.editorMode ? 'editMenu' : 'edit';
self.switchFooter(function next(err) {
if(err) {
// :TODO:... what now?
console.log(err)
} else {
switch(self.editorMode) {
case 'edit' :
if(!_.isUndefined(self.viewControllers.footerEditMenu)) {
self.viewControllers.footerEditMenu.setFocus(false);
}
self.viewControllers.body.switchFocus(1);
self.observeEditEvents();
break;
case 'editMenu' :
self.viewControllers.body.setFocus(false);
self.viewControllers.footerEditMenu.switchFocus(1);
break;
default : throw new Error('Unexpected mode');
}
}
});
}
}
};

View File

@ -55,7 +55,7 @@ function ViewController(options) {
// :TODO: Populate formData here?
// :TODO: Populate actionBlock here -- that is, the actionKey entry... or
// really we just need |extraArgs| to be present, if any
menuUtil.handleAction(self.client, { }, { action : actionForKey } );
menuUtil.handleAction(self.client, { key : key }, { action : actionForKey } );
}
return;
@ -722,7 +722,6 @@ ViewController.prototype.getFormData = function(key) {
{
id : 0,
submitId : 1,
key : { ... }, // optional key that triggered submit
value : {
"1" : "hurp",
"2" : [ 'a', 'b', ... ],
@ -738,7 +737,7 @@ ViewController.prototype.getFormData = function(key) {
value : {},
};
if(_.isObject(key)) {
if(key) {
formData.key = key;
}
@ -761,7 +760,7 @@ ViewController.prototype.getFormData = function(key) {
}
return formData;
};
}
/*
ViewController.prototype.formatMenuArgs = function(args) {

View File

@ -299,7 +299,7 @@
"width" : 19,
"textOverflow" : "..."
}
}/*
},
"submit" : {
"3" : [
{
@ -307,7 +307,7 @@
"action" : "@method:fseSubmitProxy"
}
]
}*/
}
}
},
"1" : {
@ -316,19 +316,17 @@
"MT1" : {
"width" : 79,
"height" : 17,
//"text" : "", // :TODO: should not be req.
"argName" : "message"
}
},/*,
},
"submit" : {
"*" : [
{
"value" : "message",
"action" : "@method:editModeEscPressed"
"action" : "@method:fseSubmitProxy"
}
]
},
*/
"actionKeys" : [
{
"keys" : [ "escape" ],
@ -336,6 +334,65 @@
}
]
}
},
"2" : {
"TLTL" : {
"mci" : {
"TL1" : {
"width" : 5
},
"TL2" : {
"width" : 4
}
}
}
},
"3" : {
"HM" : {
"mci" : {
"HM1" : {
// :TODO: Continue, Save, Discard, Clear, Quote, Help
"items" : [ "Save", "Discard", "Quote", "Help" ]
}
},
"submit" : {
"*" : [
{
"value" : { "1" : 0 },
"action" : "@method:fseSubmitProxy"
},
{
"value" : { "1" : 1 },
"action" : "@menu:messageArea"
},
{
"value" : { "1" : 2 },
"action" : "@method:fseSubmitProxy"
},
{
"value" : { "1" : 3 },
"action" : "@method:fseSubmitProxy"
},
{
"value" : 1,
"action" : "@method:fseSubmitProxy"
}
]
},
"actionKeys" : [ // :TODO: Need better name
{
"keys" : [ "escape" ],
"action" : "@method:fseSubmitProxy"
}
]
// :TODO: something like the following for overriding keymap
// this should only override specified entries. others will default
/*
"keyMap" : {
"accept" : [ "return" ]
}
*/
}
}
}
},

View File

@ -24,24 +24,27 @@ function MessageAreaPostModule(options) {
this.initSequence = function() {
var fse = new FullScreenEditor( {
self.fse = new FullScreenEditor( {
callingMenu : this,
client : this.client,
// :TODO: should pass in full config? want access to keymap/etc. as well
art : this.menuConfig.config.fseArt,
font : this.menuConfig.font,
editorType : 'area',
editorMode : 'edit',
});
fse.on('error', function fseError(err) {
self.fse.on('error', function fseError(err) {
console.log('fse error: ' + err)
});
fse.enter();
self.fse.enter();
};
this.menuMethods = {
// :TODO: is there a cleaner way to achieve this?
fseSubmitProxy : function(formData, extraArgs) {
console.log(formData)
self.fse.submitHandler(formData, extraArgs);
}
};
}