* Pass 'key' object to actions & submit form events
This commit is contained in:
parent
08bebb560d
commit
6d49e5e55f
|
@ -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...')
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue