* Pass 'key' object to actions & submit form events

This commit is contained in:
Bryan Ashby 2015-08-13 16:05:17 -06:00
parent 08bebb560d
commit 6d49e5e55f
5 changed files with 56 additions and 14 deletions

View File

@ -270,10 +270,18 @@ function FullScreenEditor(options) {
};
this.initObservers = function() {
// :TODO: Should probably still allow key mapping/etc. to come from module for this stuff
this.viewControllers.header.on('submit', function headerSubmit(formData, extraArgs) {
if(formData.id === self.getFormId('header')) {
self.viewControllers.header.setFocus(false);
self.viewControllers.body.switchFocus(1);
// :TODO: we need to validate the "to" here
self.viewControllers.header.setFocus(false);
self.viewControllers.body.switchFocus(1);
});
this.viewControllers.body.on('submit', function bodySubmit(formData, extraArgs) {
if(formData.key && 'escape' === formData.key.name) {
console.log('toggle menu depending on mode...')
}
});
};

View File

@ -108,7 +108,7 @@ function MultiLineEditTextView(options) {
//
this.tabWidth = _.isNumber(options.tabWidth) ? options.tabWidth : 4;
this.textLines = [];
this.textLines = [ ];
this.topVisibleIndex = 0;
this.mode = options.mode || 'edit'; // edit | preview | read-only
@ -1013,6 +1013,8 @@ function MultiLineEditTextView(options) {
self.overtypeMode = !self.overtypeMode;
self.emit('text edit mode', self.getTextEditMode());
};
this.insertRawText(''); // init to blank/empty
}
require('util').inherits(MultiLineEditTextView, View);

View File

@ -254,9 +254,9 @@ View.prototype.onKeyPress = function(ch, key) {
assert(this.specialKeyMap, 'No special key map defined');
if(this.isKeyMapped('accept', key.name)) {
this.emit('action', 'accept');
this.emit('action', 'accept', key);
} else if(this.isKeyMapped('next', key.name)) {
this.emit('action', 'next');
this.emit('action', 'next', key);
}
}

View File

@ -50,7 +50,7 @@ function ViewController(options) {
// Key works on behalf of a view -- switch focus & submit
//
self.switchFocus(actionForKey);
self.submitForm();
self.submitForm(key);
} else if(_.isString(actionForKey)) {
// :TODO: Populate formData here?
// :TODO: Populate actionBlock here -- that is, the actionKey entry... or
@ -67,16 +67,16 @@ function ViewController(options) {
}
};
this.viewActionListener = function(action) {
this.viewActionListener = function(action, key) {
switch(action) {
case 'next' :
self.emit('action', { view : this, action : action });
self.emit('action', { view : this, action : action, key : key } );
self.nextFocus();
break;
case 'accept' :
if(self.focusedView && self.focusedView.submit) {
self.submitForm();
self.submitForm(key);
} else {
self.nextFocus();
}
@ -84,8 +84,8 @@ function ViewController(options) {
}
};
this.submitForm = function() {
self.emit('submit', this.getFormData());
this.submitForm = function(key) {
self.emit('submit', this.getFormData(key));
};
this.getLogFriendlyFormData = function(formData) {
@ -716,12 +716,13 @@ ViewController.prototype.formatMCIString = function(format) {
});
};
ViewController.prototype.getFormData = function() {
ViewController.prototype.getFormData = function(key) {
/*
Example form data:
{
id : 0,
submitId : 1,
key : { ... }, // optional key that triggered submit
value : {
"1" : "hurp",
"2" : [ 'a', 'b', ... ],
@ -737,6 +738,10 @@ ViewController.prototype.getFormData = function() {
value : {},
};
if(_.isObject(key)) {
formData.key = key;
}
var viewData;
var view;
for(var id in this.views) {
@ -756,7 +761,7 @@ ViewController.prototype.getFormData = function() {
}
return formData;
}
};
/*
ViewController.prototype.formatMenuArgs = function(args) {

View File

@ -309,6 +309,33 @@
]
}*/
}
},
"1" : {
"MT" : {
"mci" : {
"MT1" : {
"width" : 79,
"height" : 17,
//"text" : "", // :TODO: should not be req.
"argName" : "message"
}
},/*,
"submit" : {
"*" : [
{
"value" : "message",
"action" : "@method:editModeEscPressed"
}
]
},
*/
"actionKeys" : [
{
"keys" : [ "escape" ],
"viewId" : 1
}
]
}
}
}
},