mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-08-04 17:01:33 +02:00
* Add rumorz mod
* ANSI/pipe working properly in VerticalMenuView * Fix bug in renderStringLength() * Make initSequence() part of prototype chain for inheritance * Use proper 'desc' field vs 'status' for menus when setting client/user status * Move pipeToAnsi() to setItems/setFocusItems vs every render * Add %RR random rumor MCI * Predefined MCI's can be init @ startup - RR uses random as a test bed * Add some StatLog functionality for ordering, keep forever, etc. * Fix TextView redraw issue * Better VerticalMenuView drawItem() logic * Add 'key press' emit for View * Enable formats for BBS list - works with MCI * Remove old system_property.js
This commit is contained in:
parent
2b68201f7d
commit
30ba609fb4
13 changed files with 492 additions and 241 deletions
|
@ -40,110 +40,6 @@ function MenuModule(options) {
|
|||
|
||||
this.initViewControllers();
|
||||
|
||||
this.initSequence = function() {
|
||||
var mciData = { };
|
||||
|
||||
async.series(
|
||||
[
|
||||
function beforeDisplayArt(callback) {
|
||||
self.beforeArt(callback);
|
||||
},
|
||||
function displayMenuArt(callback) {
|
||||
if(_.isString(self.menuConfig.art)) {
|
||||
theme.displayThemedAsset(
|
||||
self.menuConfig.art,
|
||||
self.client,
|
||||
self.menuConfig.options, // can include .font, .trailingLF, etc.
|
||||
function displayed(err, artData) {
|
||||
if(err) {
|
||||
self.client.log.trace( { art : self.menuConfig.art, error : err.message }, 'Could not display art');
|
||||
} else {
|
||||
mciData.menu = artData.mciMap;
|
||||
}
|
||||
callback(null); // non-fatal
|
||||
}
|
||||
);
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
function moveToPromptLocation(callback) {
|
||||
if(self.menuConfig.prompt) {
|
||||
// :TODO: fetch and move cursor to prompt location, if supplied. See notes/etc. on placements
|
||||
}
|
||||
|
||||
callback(null);
|
||||
},
|
||||
function displayPromptArt(callback) {
|
||||
if(_.isString(self.menuConfig.prompt)) {
|
||||
// If a prompt is specified, we need the configuration
|
||||
if(!_.isObject(self.menuConfig.promptConfig)) {
|
||||
callback(new Error('Prompt specified but configuraiton not found!'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Prompts *must* have art. If it's missing it's an error
|
||||
// :TODO: allow inline prompts in the future, e.g. @inline:memberName -> { "memberName" : { "text" : "stuff", ... } }
|
||||
var promptConfig = self.menuConfig.promptConfig;
|
||||
theme.displayThemedAsset(
|
||||
promptConfig.art,
|
||||
self.client,
|
||||
self.menuConfig.options, // can include .font, .trailingLF, etc.
|
||||
function displayed(err, artData) {
|
||||
if(!err) {
|
||||
mciData.prompt = artData.mciMap;
|
||||
}
|
||||
callback(err);
|
||||
});
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
function recordCursorPosition(callback) {
|
||||
if(self.shouldPause()) {
|
||||
self.client.once('cursor position report', function cpr(pos) {
|
||||
self.afterArtPos = pos;
|
||||
self.client.log.trace( { position : pos }, 'After art position recorded');
|
||||
callback(null);
|
||||
});
|
||||
self.client.term.write(ansi.queryPos());
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
function afterArtDisplayed(callback) {
|
||||
self.mciReady(mciData, callback);
|
||||
},
|
||||
function displayPauseIfRequested(callback) {
|
||||
if(self.shouldPause()) {
|
||||
self.client.term.write(ansi.goto(self.afterArtPos[0], 1));
|
||||
|
||||
// :TODO: really need a client.term.pause() that uses the correct art/etc.
|
||||
theme.displayThemedPause( { client : self.client }, function keyPressed() {
|
||||
callback(null);
|
||||
});
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
function finishAndNext(callback) {
|
||||
self.finishedLoading();
|
||||
|
||||
self.autoNextMenu(callback);
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
if(err) {
|
||||
console.log(err)
|
||||
// :TODO: what to do exactly?????
|
||||
return self.prevMenu( () => {
|
||||
// dummy
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
this.shouldPause = function() {
|
||||
return 'end' === self.menuConfig.options.pause || true === self.menuConfig.options.pause;
|
||||
};
|
||||
|
@ -199,8 +95,8 @@ require('./mod_mixins.js').ViewControllerManagement.call(MenuModule.prototype);
|
|||
|
||||
|
||||
MenuModule.prototype.enter = function() {
|
||||
if(_.isString(this.menuConfig.status)) {
|
||||
this.client.currentStatus = this.menuConfig.status;
|
||||
if(_.isString(this.menuConfig.desc)) {
|
||||
this.client.currentStatus = this.menuConfig.desc;
|
||||
} else {
|
||||
this.client.currentStatus = 'Browsing menus';
|
||||
}
|
||||
|
@ -208,6 +104,111 @@ MenuModule.prototype.enter = function() {
|
|||
this.initSequence();
|
||||
};
|
||||
|
||||
MenuModule.prototype.initSequence = function() {
|
||||
var mciData = { };
|
||||
const self = this;
|
||||
|
||||
async.series(
|
||||
[
|
||||
function beforeDisplayArt(callback) {
|
||||
self.beforeArt(callback);
|
||||
},
|
||||
function displayMenuArt(callback) {
|
||||
if(_.isString(self.menuConfig.art)) {
|
||||
theme.displayThemedAsset(
|
||||
self.menuConfig.art,
|
||||
self.client,
|
||||
self.menuConfig.options, // can include .font, .trailingLF, etc.
|
||||
function displayed(err, artData) {
|
||||
if(err) {
|
||||
self.client.log.trace( { art : self.menuConfig.art, error : err.message }, 'Could not display art');
|
||||
} else {
|
||||
mciData.menu = artData.mciMap;
|
||||
}
|
||||
callback(null); // non-fatal
|
||||
}
|
||||
);
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
function moveToPromptLocation(callback) {
|
||||
if(self.menuConfig.prompt) {
|
||||
// :TODO: fetch and move cursor to prompt location, if supplied. See notes/etc. on placements
|
||||
}
|
||||
|
||||
callback(null);
|
||||
},
|
||||
function displayPromptArt(callback) {
|
||||
if(_.isString(self.menuConfig.prompt)) {
|
||||
// If a prompt is specified, we need the configuration
|
||||
if(!_.isObject(self.menuConfig.promptConfig)) {
|
||||
callback(new Error('Prompt specified but configuraiton not found!'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Prompts *must* have art. If it's missing it's an error
|
||||
// :TODO: allow inline prompts in the future, e.g. @inline:memberName -> { "memberName" : { "text" : "stuff", ... } }
|
||||
var promptConfig = self.menuConfig.promptConfig;
|
||||
theme.displayThemedAsset(
|
||||
promptConfig.art,
|
||||
self.client,
|
||||
self.menuConfig.options, // can include .font, .trailingLF, etc.
|
||||
function displayed(err, artData) {
|
||||
if(!err) {
|
||||
mciData.prompt = artData.mciMap;
|
||||
}
|
||||
callback(err);
|
||||
});
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
function recordCursorPosition(callback) {
|
||||
if(self.shouldPause()) {
|
||||
self.client.once('cursor position report', function cpr(pos) {
|
||||
self.afterArtPos = pos;
|
||||
self.client.log.trace( { position : pos }, 'After art position recorded');
|
||||
callback(null);
|
||||
});
|
||||
self.client.term.write(ansi.queryPos());
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
function afterArtDisplayed(callback) {
|
||||
self.mciReady(mciData, callback);
|
||||
},
|
||||
function displayPauseIfRequested(callback) {
|
||||
if(self.shouldPause()) {
|
||||
self.client.term.write(ansi.goto(self.afterArtPos[0], 1));
|
||||
|
||||
// :TODO: really need a client.term.pause() that uses the correct art/etc.
|
||||
theme.displayThemedPause( { client : self.client }, function keyPressed() {
|
||||
callback(null);
|
||||
});
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
function finishAndNext(callback) {
|
||||
self.finishedLoading();
|
||||
|
||||
self.autoNextMenu(callback);
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
if(err) {
|
||||
console.log(err)
|
||||
// :TODO: what to do exactly?????
|
||||
return self.prevMenu( () => {
|
||||
// dummy
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
MenuModule.prototype.getSaveState = function() {
|
||||
// nothing in base
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
// ENiGMA½
|
||||
const View = require('./view.js').View;
|
||||
const miscUtil = require('./misc_util.js');
|
||||
const pipeToAnsi = require('./color_codes.js').pipeToAnsi;
|
||||
|
||||
// deps
|
||||
const util = require('util');
|
||||
|
@ -15,9 +16,11 @@ exports.MenuView = MenuView;
|
|||
function MenuView(options) {
|
||||
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
|
||||
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
|
||||
|
||||
|
||||
View.call(this, options);
|
||||
|
||||
this.disablePipe = options.disablePipe || false;
|
||||
|
||||
const self = this;
|
||||
|
||||
if(options.items) {
|
||||
|
@ -60,10 +63,16 @@ function MenuView(options) {
|
|||
util.inherits(MenuView, View);
|
||||
|
||||
MenuView.prototype.setItems = function(items) {
|
||||
const self = this;
|
||||
|
||||
if(items) {
|
||||
this.items = [];
|
||||
items.forEach( itemText => {
|
||||
this.items.push( { text : itemText } );
|
||||
this.items.push(
|
||||
{
|
||||
text : self.disablePipe ? itemText : pipeToAnsi(itemText, self.client)
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -110,10 +119,16 @@ MenuView.prototype.onKeyPress = function(ch, key) {
|
|||
};
|
||||
|
||||
MenuView.prototype.setFocusItems = function(items) {
|
||||
const self = this;
|
||||
|
||||
if(items) {
|
||||
this.focusItems = [];
|
||||
items.forEach( itemText => {
|
||||
this.focusItems.push( { text : itemText } );
|
||||
this.focusItems.push(
|
||||
{
|
||||
text : self.disablePipe ? itemText : pipeToAnsi(itemText, self.client)
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -16,6 +16,24 @@ const _ = require('lodash');
|
|||
const moment = require('moment');
|
||||
|
||||
exports.getPredefinedMCIValue = getPredefinedMCIValue;
|
||||
exports.init = init;
|
||||
|
||||
function init(cb) {
|
||||
setNextRandomRumor(cb);
|
||||
}
|
||||
|
||||
function setNextRandomRumor(cb) {
|
||||
StatLog.getSystemLogEntries('system_rumorz', StatLog.Order.Random, 1, (err, entry) => {
|
||||
if(entry) {
|
||||
entry = entry[0];
|
||||
}
|
||||
const randRumor = entry && entry.log_value ? entry.log_value : '';
|
||||
StatLog.setNonPeristentSystemStat('random_rumor', randRumor);
|
||||
if(cb) {
|
||||
return cb(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getPredefinedMCIValue(client, code) {
|
||||
|
||||
|
@ -138,6 +156,13 @@ function getPredefinedMCIValue(client, code) {
|
|||
|
||||
TC : function totalCalls() { return StatLog.getSystemStat('login_count').toString(); },
|
||||
|
||||
RR : function randomRumor() {
|
||||
// start the process of picking another random one
|
||||
setNextRandomRumor();
|
||||
|
||||
return StatLog.getSystemStat('random_rumor');
|
||||
},
|
||||
|
||||
//
|
||||
// Special handling for XY
|
||||
//
|
||||
|
|
|
@ -44,6 +44,21 @@ class StatLog {
|
|||
);
|
||||
}
|
||||
|
||||
get KeepDays() {
|
||||
return {
|
||||
Forever : -1,
|
||||
};
|
||||
}
|
||||
|
||||
get Order() {
|
||||
return {
|
||||
Timestamp : 'timestamp_asc',
|
||||
TimestampAsc : 'timestamp_asc',
|
||||
TimestampDesc : 'timestamp_desc',
|
||||
Random : 'random',
|
||||
};
|
||||
}
|
||||
|
||||
setNonPeristentSystemStat(statName, statValue) {
|
||||
this.systemStats[statName] = statValue;
|
||||
}
|
||||
|
@ -123,6 +138,13 @@ class StatLog {
|
|||
//
|
||||
// Handle keepDays
|
||||
//
|
||||
if(-1 === keepDays) {
|
||||
if(cb) {
|
||||
return cb(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sysDb.run(
|
||||
`DELETE FROM system_event_log
|
||||
WHERE log_name = ? AND timestamp <= DATETIME("now", "-${keepDays} day");`,
|
||||
|
@ -145,9 +167,17 @@ class StatLog {
|
|||
WHERE log_name = ?`;
|
||||
|
||||
switch(order) {
|
||||
case 'timestamp' :
|
||||
case 'timestamp_desc' :
|
||||
sql += ' ORDER BY timestamp DESC';
|
||||
case 'timestamp' :
|
||||
case 'timestamp_asc' :
|
||||
sql += ' ORDER BY timestamp ASC';
|
||||
break;
|
||||
|
||||
case 'timestamp_desc' :
|
||||
sql += ' ORDER BY timestamp DESC';
|
||||
break;
|
||||
|
||||
case 'random' :
|
||||
sql += ' ORDER BY RANDOM()';
|
||||
}
|
||||
|
||||
if(!cb && _.isFunction(limit)) {
|
||||
|
@ -177,6 +207,13 @@ class StatLog {
|
|||
//
|
||||
// Handle keepDays
|
||||
//
|
||||
if(-1 === keepDays) {
|
||||
if(cb) {
|
||||
return cb(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sysDb.run(
|
||||
`DELETE FROM user_event_log
|
||||
WHERE user_id = ? AND log_name = ? AND timestamp <= DATETIME("now", "-${keepDays} day");`,
|
||||
|
|
|
@ -236,7 +236,8 @@ exports.stringFormatExtensions = stringFormatExtensions;
|
|||
|
||||
// :TODO: Add other codes from ansi_escape_parser
|
||||
const ANSI_REGEXP = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
|
||||
const ANSI_OR_PIPE_REGEXP = new RegExp(ANSI_REGEXP.source + '\\|[A-Z\d]{2}', 'g');
|
||||
const PIPE_REGEXP = /\|[A-Z\d]{2}/g;
|
||||
const ANSI_OR_PIPE_REGEXP = new RegExp(ANSI_REGEXP.source + '|' + PIPE_REGEXP.source, 'g');
|
||||
|
||||
//
|
||||
// Similar to substr() but works with ANSI/Pipe code strings
|
||||
|
@ -279,10 +280,8 @@ function renderSubstr(str, start, length) {
|
|||
// Pipe and ANSI color codes. Note that currently ANSI *movement*
|
||||
// codes are not considred!
|
||||
//
|
||||
// :TODO: consolidate ANSI code RegExp's and such
|
||||
const PIPE_AND_ANSI_RE = ANSI_OR_PIPE_REGEXP;// /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\|[A-Z\d]{2}/g
|
||||
function renderStringLength(str) {
|
||||
return str.replace(PIPE_AND_ANSI_RE, '').length;
|
||||
return str.replace(ANSI_OR_PIPE_REGEXP, '').length;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var sysDb = require('./database.js').dbs.system;
|
||||
|
||||
exports.loadSystemProperties = loadSystemProperties;
|
||||
exports.persistSystemProperty = persistSystemProperty;
|
||||
exports.getSystemProperty = getSystemProperty;
|
||||
|
||||
var systemProperties = {};
|
||||
exports.systemProperties = systemProperties;
|
||||
|
||||
function loadSystemProperties(cb) {
|
||||
sysDb.each(
|
||||
'SELECT prop_name, prop_value ' +
|
||||
'FROM system_property;',
|
||||
function rowResult(err, row) {
|
||||
systemProperties[row.prop_name] = row.prop_value;
|
||||
},
|
||||
cb
|
||||
);
|
||||
}
|
||||
|
||||
function persistSystemProperty(propName, propValue, cb) {
|
||||
// update live
|
||||
systemProperties[propName] = propValue;
|
||||
|
||||
sysDb.run(
|
||||
'REPLACE INTO system_property ' +
|
||||
'VALUES (?, ?);',
|
||||
[ propName, propValue ],
|
||||
cb
|
||||
);
|
||||
}
|
||||
|
||||
function getSystemProperty(propName) {
|
||||
return systemProperties[propName];
|
||||
}
|
|
@ -34,7 +34,6 @@ function TextView(options) {
|
|||
this.justify = options.justify || 'right';
|
||||
this.resizable = miscUtil.valueWithDefault(options.resizable, true);
|
||||
this.horizScroll = miscUtil.valueWithDefault(options.horizScroll, true);
|
||||
this.text = options.text || '';
|
||||
|
||||
if(_.isString(options.textOverflow)) {
|
||||
this.textOverflow = options.textOverflow;
|
||||
|
@ -136,8 +135,7 @@ function TextView(options) {
|
|||
return this.position.col + offset;
|
||||
};
|
||||
|
||||
// :TODO: Whatever needs init here should be done separately from setText() since it redraws/etc.
|
||||
// this.setText(options.text || '');
|
||||
this.setText(options.text || '', false); // false=do not redraw now
|
||||
}
|
||||
|
||||
util.inherits(TextView, View);
|
||||
|
@ -175,7 +173,9 @@ TextView.prototype.getData = function() {
|
|||
return this.text;
|
||||
};
|
||||
|
||||
TextView.prototype.setText = function(text) {
|
||||
TextView.prototype.setText = function(text, redraw) {
|
||||
redraw = _.isBoolean(redraw) ? redraw : true;
|
||||
|
||||
if(!_.isString(text)) {
|
||||
text = text.toString();
|
||||
}
|
||||
|
@ -201,7 +201,9 @@ TextView.prototype.setText = function(text) {
|
|||
this.dimens.width = this.text.length + widthDelta;
|
||||
}
|
||||
|
||||
this.redraw();
|
||||
if(redraw) {
|
||||
this.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -15,7 +15,7 @@ exports.VerticalMenuView = VerticalMenuView;
|
|||
function VerticalMenuView(options) {
|
||||
options.cursor = options.cursor || 'hide';
|
||||
options.justify = options.justify || 'right'; // :TODO: default to center
|
||||
|
||||
|
||||
MenuView.call(this, options);
|
||||
|
||||
const self = this;
|
||||
|
@ -48,60 +48,33 @@ function VerticalMenuView(options) {
|
|||
};
|
||||
};
|
||||
|
||||
/*
|
||||
this.drawItem = function(index) {
|
||||
var item = self.items[index];
|
||||
if(!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = strUtil.stylizeString(item.text, item.focused ? self.focusTextStyle : self.textStyle);
|
||||
self.client.term.write(
|
||||
ansi.goto(item.row, self.position.col) +
|
||||
(index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR()) +
|
||||
strUtil.pad(text, this.dimens.width, this.fillChar, this.justify)
|
||||
);
|
||||
};
|
||||
*/
|
||||
|
||||
this.drawItem = function(index) {
|
||||
const item = self.items[index];
|
||||
|
||||
if(!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
let focusItem;
|
||||
let text;
|
||||
|
||||
if(self.hasFocusItems()) {
|
||||
focusItem = self.focusItems[index];
|
||||
}
|
||||
|
||||
if(focusItem) {
|
||||
if(item.focused) {
|
||||
text = strUtil.stylizeString(focusItem.text, self.focusTextStyle);
|
||||
} else {
|
||||
text = strUtil.stylizeString(item.text, self.textStyle);
|
||||
}
|
||||
|
||||
// :TODO: Need to support pad()
|
||||
// :TODO: shoudl we detect if pipe codes are used?
|
||||
self.client.term.write(
|
||||
ansi.goto(item.row, self.position.col) +
|
||||
colorCodes.pipeToAnsi(text, self.client)
|
||||
);
|
||||
|
||||
let sgr;
|
||||
if(item.focused && self.hasFocusItems()) {
|
||||
const focusItem = self.focusItems[index];
|
||||
text = strUtil.stylizeString(
|
||||
focusItem ? focusItem.text : item.text,
|
||||
self.textStyle
|
||||
);
|
||||
sgr = '';
|
||||
} else {
|
||||
text = strUtil.stylizeString(item.text, item.focused ? self.focusTextStyle : self.textStyle);
|
||||
|
||||
self.client.term.write(
|
||||
ansi.goto(item.row, self.position.col) +
|
||||
(index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR()) +
|
||||
strUtil.pad(text, this.dimens.width, this.fillChar, this.justify)
|
||||
);
|
||||
text = strUtil.stylizeString(item.text, self.textStyle);
|
||||
sgr = (index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR());
|
||||
}
|
||||
|
||||
text += self.getSGR();
|
||||
|
||||
self.client.term.write(
|
||||
ansi.goto(item.row, self.position.col) +
|
||||
sgr +
|
||||
strUtil.pad(text, this.dimens.width, this.fillChar, this.justify)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -174,7 +147,7 @@ VerticalMenuView.prototype.setFocusItemIndex = function(index) {
|
|||
this.positionCacheExpired = false; // skip standard behavior
|
||||
this.performAutoScale();
|
||||
}
|
||||
|
||||
|
||||
this.redraw();
|
||||
};
|
||||
|
||||
|
|
|
@ -254,7 +254,7 @@ View.prototype.setFocus = function(focused) {
|
|||
|
||||
View.prototype.onKeyPress = function(ch, key) {
|
||||
if(false === this.hasFocus) {
|
||||
console.log('doh!');
|
||||
console.log('doh!'); // :TODO: fix me -- assert here?
|
||||
}
|
||||
assert(this.hasFocus, 'View does not have focus');
|
||||
assert(this.acceptsInput, 'View does not accept input');
|
||||
|
@ -272,6 +272,8 @@ View.prototype.onKeyPress = function(ch, key) {
|
|||
if(ch) {
|
||||
assert(1 === ch.length);
|
||||
}
|
||||
|
||||
this.emit('key press', ch, key);
|
||||
};
|
||||
|
||||
View.prototype.getData = function() {
|
||||
|
|
|
@ -23,7 +23,6 @@ function ViewController(options) {
|
|||
assert(_.isObject(options));
|
||||
assert(_.isObject(options.client));
|
||||
|
||||
|
||||
events.EventEmitter.call(this);
|
||||
|
||||
var self = this;
|
||||
|
@ -83,28 +82,28 @@ function ViewController(options) {
|
|||
|
||||
this.viewActionListener = function(action, key) {
|
||||
switch(action) {
|
||||
case 'next' :
|
||||
self.emit('action', { view : this, action : action, key : key });
|
||||
self.nextFocus();
|
||||
break;
|
||||
|
||||
case 'accept' :
|
||||
if(self.focusedView && self.focusedView.submit) {
|
||||
// :TODO: need to do validation here!!!
|
||||
var focusedView = self.focusedView;
|
||||
self.validateView(focusedView, function validated(err, newFocusedViewId) {
|
||||
if(err) {
|
||||
var newFocusedView = self.getView(newFocusedViewId) || focusedView;
|
||||
self.setViewFocusWithEvents(newFocusedView, true);
|
||||
} else {
|
||||
self.submitForm(key);
|
||||
}
|
||||
});
|
||||
//self.submitForm(key);
|
||||
} else {
|
||||
case 'next' :
|
||||
self.emit('action', { view : this, action : action, key : key });
|
||||
self.nextFocus();
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'accept' :
|
||||
if(self.focusedView && self.focusedView.submit) {
|
||||
// :TODO: need to do validation here!!!
|
||||
var focusedView = self.focusedView;
|
||||
self.validateView(focusedView, function validated(err, newFocusedViewId) {
|
||||
if(err) {
|
||||
var newFocusedView = self.getView(newFocusedViewId) || focusedView;
|
||||
self.setViewFocusWithEvents(newFocusedView, true);
|
||||
} else {
|
||||
self.submitForm(key);
|
||||
}
|
||||
});
|
||||
//self.submitForm(key);
|
||||
} else {
|
||||
self.nextFocus();
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue