* 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() { 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) { this.viewControllers.header.on('submit', function headerSubmit(formData, extraArgs) {
if(formData.id === self.getFormId('header')) { // :TODO: we need to validate the "to" here
self.viewControllers.header.setFocus(false); self.viewControllers.header.setFocus(false);
self.viewControllers.body.switchFocus(1); 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

@ -1013,6 +1013,8 @@ function MultiLineEditTextView(options) {
self.overtypeMode = !self.overtypeMode; self.overtypeMode = !self.overtypeMode;
self.emit('text edit mode', self.getTextEditMode()); self.emit('text edit mode', self.getTextEditMode());
}; };
this.insertRawText(''); // init to blank/empty
} }
require('util').inherits(MultiLineEditTextView, View); 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'); assert(this.specialKeyMap, 'No special key map defined');
if(this.isKeyMapped('accept', key.name)) { if(this.isKeyMapped('accept', key.name)) {
this.emit('action', 'accept'); this.emit('action', 'accept', key);
} else if(this.isKeyMapped('next', key.name)) { } 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 // Key works on behalf of a view -- switch focus & submit
// //
self.switchFocus(actionForKey); self.switchFocus(actionForKey);
self.submitForm(); self.submitForm(key);
} else if(_.isString(actionForKey)) { } else if(_.isString(actionForKey)) {
// :TODO: Populate formData here? // :TODO: Populate formData here?
// :TODO: Populate actionBlock here -- that is, the actionKey entry... or // :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) { switch(action) {
case 'next' : case 'next' :
self.emit('action', { view : this, action : action }); self.emit('action', { view : this, action : action, key : key } );
self.nextFocus(); self.nextFocus();
break; break;
case 'accept' : case 'accept' :
if(self.focusedView && self.focusedView.submit) { if(self.focusedView && self.focusedView.submit) {
self.submitForm(); self.submitForm(key);
} else { } else {
self.nextFocus(); self.nextFocus();
} }
@ -84,8 +84,8 @@ function ViewController(options) {
} }
}; };
this.submitForm = function() { this.submitForm = function(key) {
self.emit('submit', this.getFormData()); self.emit('submit', this.getFormData(key));
}; };
this.getLogFriendlyFormData = function(formData) { 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: Example form data:
{ {
id : 0, id : 0,
submitId : 1, submitId : 1,
key : { ... }, // optional key that triggered submit
value : { value : {
"1" : "hurp", "1" : "hurp",
"2" : [ 'a', 'b', ... ], "2" : [ 'a', 'b', ... ],
@ -737,6 +738,10 @@ ViewController.prototype.getFormData = function() {
value : {}, value : {},
}; };
if(_.isObject(key)) {
formData.key = key;
}
var viewData; var viewData;
var view; var view;
for(var id in this.views) { for(var id in this.views) {
@ -756,7 +761,7 @@ ViewController.prototype.getFormData = function() {
} }
return formData; return formData;
} };
/* /*
ViewController.prototype.formatMenuArgs = function(args) { 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
}
]
}
} }
} }
}, },