2014-10-23 22:40:52 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2017-02-08 03:14:56 +00:00
|
|
|
const TextView = require('./text_view.js').TextView;
|
|
|
|
const miscUtil = require('./misc_util.js');
|
|
|
|
const util = require('util');
|
2014-10-23 22:40:52 +00:00
|
|
|
|
2014-10-24 04:18:38 +00:00
|
|
|
exports.ButtonView = ButtonView;
|
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
function ButtonView(options) {
|
2014-11-03 23:49:15 +00:00
|
|
|
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
|
|
|
|
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
|
|
|
|
options.justify = miscUtil.valueWithDefault(options.justify, 'center');
|
2015-04-09 04:54:13 +00:00
|
|
|
options.cursor = miscUtil.valueWithDefault(options.cursor, 'hide');
|
2014-10-23 22:40:52 +00:00
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
TextView.call(this, options);
|
2014-10-23 22:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(ButtonView, TextView);
|
|
|
|
|
2017-02-27 04:28:05 +00:00
|
|
|
ButtonView.prototype.onKeyPress = function(ch, key) {
|
|
|
|
if(this.isKeyMapped('accept', key.name) || ' ' === ch) {
|
|
|
|
this.submitData = 'accept';
|
|
|
|
this.emit('action', 'accept');
|
2018-01-15 19:22:11 +00:00
|
|
|
delete this.submitData;
|
2017-02-27 04:28:05 +00:00
|
|
|
} else {
|
|
|
|
ButtonView.super_.prototype.onKeyPress.call(this, ch, key);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
/*
|
2015-06-06 06:33:59 +00:00
|
|
|
ButtonView.prototype.onKeyPress = function(ch, key) {
|
2017-02-08 03:14:56 +00:00
|
|
|
// allow space = submit
|
2017-02-27 04:28:05 +00:00
|
|
|
if(' ' === ch) {
|
2014-10-24 04:18:38 +00:00
|
|
|
this.emit('action', 'accept');
|
|
|
|
}
|
2015-06-06 06:33:59 +00:00
|
|
|
|
|
|
|
ButtonView.super_.prototype.onKeyPress.call(this, ch, key);
|
2015-03-31 03:29:06 +00:00
|
|
|
};
|
2017-02-27 04:28:05 +00:00
|
|
|
*/
|
2015-03-31 03:29:06 +00:00
|
|
|
|
2015-04-17 04:29:53 +00:00
|
|
|
ButtonView.prototype.getData = function() {
|
2017-02-27 04:28:05 +00:00
|
|
|
return this.submitData || null;
|
2015-03-31 03:29:06 +00:00
|
|
|
};
|