* 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

@ -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) {