* Much better flow for mciReady in relation to pausing, etc. using callbacks
This commit is contained in:
parent
44a0f87a24
commit
a15067fc21
|
@ -97,8 +97,19 @@ function MenuModule(options) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function afterArtDisplayed(callback) {
|
function afterArtDisplayed(callback) {
|
||||||
self.mciReady(mciData);
|
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);
|
callback(null);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
function complete(err) {
|
function complete(err) {
|
||||||
|
@ -108,25 +119,13 @@ function MenuModule(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.finishedLoading();
|
self.finishedLoading();
|
||||||
|
self.nextAction();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.shouldPause = function() {
|
this.shouldPause = function() {
|
||||||
return 'end' === self.menuConfig.pause || true === self.menuConfig.pause;
|
return 'end' === self.menuConfig.options.pause || true === self.menuConfig.options.pause;
|
||||||
};
|
|
||||||
|
|
||||||
this.allViewsReady = function() {
|
|
||||||
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() {
|
|
||||||
self.nextAction();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
self.nextAction();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.nextAction = function() {
|
this.nextAction = function() {
|
||||||
|
@ -170,10 +169,12 @@ MenuModule.prototype.beforeArt = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MenuModule.prototype.mciReady = function(mciData) {
|
MenuModule.prototype.mciReady = function(mciData, cb) {
|
||||||
|
// Reserved for sub classes
|
||||||
|
cb(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
MenuModule.prototype.standardMCIReadyHandler = function(mciData) {
|
MenuModule.prototype.standardMCIReadyHandler = function(mciData, cb) {
|
||||||
//
|
//
|
||||||
// A quick rundown:
|
// A quick rundown:
|
||||||
// * We may have mciData.menu, mciData.prompt, or both.
|
// * We may have mciData.menu, mciData.prompt, or both.
|
||||||
|
@ -181,29 +182,17 @@ MenuModule.prototype.standardMCIReadyHandler = function(mciData) {
|
||||||
// * Standard/prefdefined MCI entries must load both (e.g. %BN is expected to resolve)
|
// * Standard/prefdefined MCI entries must load both (e.g. %BN is expected to resolve)
|
||||||
//
|
//
|
||||||
var self = this;
|
var self = this;
|
||||||
var vcCount = 0;
|
|
||||||
var vcReady = 0;
|
|
||||||
|
|
||||||
|
async.series(
|
||||||
|
[
|
||||||
|
function addViewControllers(callback) {
|
||||||
_.forEach(mciData, function entry(mciMap, name) {
|
_.forEach(mciData, function entry(mciMap, name) {
|
||||||
assert('menu' === name || 'prompt' === name);
|
assert('menu' === name || 'prompt' === name);
|
||||||
++vcCount;
|
|
||||||
self.addViewController(name, new ViewController( { client : self.client } ));
|
self.addViewController(name, new ViewController( { client : self.client } ));
|
||||||
});
|
});
|
||||||
|
callback(null);
|
||||||
var viewsReady = function(err) {
|
},
|
||||||
// :TODO: what should really happen here?
|
function createMenu(callback) {
|
||||||
if(err) {
|
|
||||||
self.client.log.warn(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
++vcReady;
|
|
||||||
if(vcReady === vcCount) {
|
|
||||||
self.allViewsReady();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
if(self.viewControllers.menu) {
|
if(self.viewControllers.menu) {
|
||||||
var menuLoadOpts = {
|
var menuLoadOpts = {
|
||||||
mciMap : mciData.menu,
|
mciMap : mciData.menu,
|
||||||
|
@ -211,17 +200,32 @@ MenuModule.prototype.standardMCIReadyHandler = function(mciData) {
|
||||||
withoutForm : _.isObject(mciData.prompt),
|
withoutForm : _.isObject(mciData.prompt),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.viewControllers.menu.loadFromMenuConfig(menuLoadOpts, viewsReady);
|
self.viewControllers.menu.loadFromMenuConfig(menuLoadOpts, function menuLoaded(err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(null);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
function createPrompt(callback) {
|
||||||
if(self.viewControllers.prompt) {
|
if(self.viewControllers.prompt) {
|
||||||
var promptLoadOpts = {
|
var promptLoadOpts = {
|
||||||
callingMenu : self,
|
callingMenu : self,
|
||||||
mciMap : mciData.prompt,
|
mciMap : mciData.prompt,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.viewControllers.prompt.loadFromPromptConfig(promptLoadOpts, viewsReady);
|
self.viewControllers.prompt.loadFromPromptConfig(promptLoadOpts, function promptLoaded(err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
function complete(err) {
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
MenuModule.prototype.finishedLoading = function() {
|
MenuModule.prototype.finishedLoading = function() {
|
||||||
|
@ -234,26 +238,5 @@ MenuModule.prototype.finishedLoading = function() {
|
||||||
setTimeout(function nextTimeout() {
|
setTimeout(function nextTimeout() {
|
||||||
self.client.gotoMenuModule( { name : self.menuConfig.next } );
|
self.client.gotoMenuModule( { name : self.menuConfig.next } );
|
||||||
}, this.menuConfig.options.nextTimeout);
|
}, this.menuConfig.options.nextTimeout);
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
var nextAction = function() {
|
|
||||||
if(!_.isObject(self.menuConfig.form) && !_.isString(self.menuConfig.prompt) &&
|
|
||||||
_.isString(self.menuConfig.action))
|
|
||||||
{
|
|
||||||
menuUtil.handleAction(self.client, null, self.menuConfig);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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() {
|
|
||||||
nextAction();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
nextAction();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -26,9 +26,15 @@ StandardMenuModule.prototype.beforeArt = function() {
|
||||||
StandardMenuModule.super_.prototype.beforeArt.call(this);
|
StandardMenuModule.super_.prototype.beforeArt.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
StandardMenuModule.prototype.mciReady = function(mciData) {
|
StandardMenuModule.prototype.mciReady = function(mciData, cb) {
|
||||||
StandardMenuModule.super_.prototype.mciReady.call(this, mciData);
|
var self = this;
|
||||||
|
|
||||||
|
StandardMenuModule.super_.prototype.mciReady.call(this, mciData, function mciReadyComplete(err) {
|
||||||
|
if(err) {
|
||||||
|
cb(err);
|
||||||
|
} else {
|
||||||
// we do this so other modules can be both customized and still perform standard tasks
|
// we do this so other modules can be both customized and still perform standard tasks
|
||||||
StandardMenuModule.super_.prototype.standardMCIReadyHandler.call(this, mciData);
|
StandardMenuModule.super_.prototype.standardMCIReadyHandler.call(self, mciData, cb);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,15 +55,18 @@ LastCallersModule.prototype.enter = function(client) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LastCallersModule.prototype.mciReady = function(mciData) {
|
LastCallersModule.prototype.mciReady = function(mciData, cb) {
|
||||||
LastCallersModule.super_.prototype.mciReady.call(this, mciData);
|
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var vc = self.viewControllers.lastCallers = new ViewController( { client : self.client } );
|
var vc = self.viewControllers.lastCallers = new ViewController( { client : self.client } );
|
||||||
var loginHistory;
|
var loginHistory;
|
||||||
|
|
||||||
async.series(
|
async.series(
|
||||||
[
|
[
|
||||||
|
function callParentMciReady(callback) {
|
||||||
|
LastCallersModule.super_.prototype.mciReady.call(this, mciData, function parentMciReady(err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
function loadFromConfig(callback) {
|
function loadFromConfig(callback) {
|
||||||
var loadOpts = {
|
var loadOpts = {
|
||||||
callingMenu : self,
|
callingMenu : self,
|
||||||
|
@ -155,10 +158,15 @@ LastCallersModule.prototype.mciReady = function(mciData) {
|
||||||
|
|
||||||
row++;
|
row++;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
callback(null);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
function complete(err) {
|
function complete(err) {
|
||||||
|
if(err) {
|
||||||
self.client.log.error(err);
|
self.client.log.error(err);
|
||||||
}
|
}
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
"menus" : {
|
"menus" : {
|
||||||
"art" : "CONNECT",
|
|
||||||
"connected" : {
|
"connected" : {
|
||||||
|
"art" : "CONNECT",
|
||||||
"next" : "matrix",
|
"next" : "matrix",
|
||||||
"options" : {
|
"options" : {
|
||||||
"cls" : true,
|
"cls" : true,
|
||||||
|
@ -191,24 +191,18 @@
|
||||||
},
|
},
|
||||||
"newUserActive" : {
|
"newUserActive" : {
|
||||||
"art" : "SO-CC1.ANS",
|
"art" : "SO-CC1.ANS",
|
||||||
"options" : { "cls" : true },
|
"options" : { "cls" : true, "pause" : true },
|
||||||
"action" : "@menu:currentUserStats",
|
"action" : "@menu:currentUserStats"
|
||||||
"pause" : "end"
|
|
||||||
},
|
},
|
||||||
"currentUserStats" : {
|
"currentUserStats" : {
|
||||||
"art" : "userstats",
|
"art" : "userstats",
|
||||||
//"prompt" : "pause",
|
"options" : { "cls" : true, "pause" : true },
|
||||||
"options" : {
|
|
||||||
// :TODO: implement MCI codes for this
|
|
||||||
"cls" : true
|
|
||||||
},
|
|
||||||
"pause" : true,
|
|
||||||
"action" : "@menu:lastCallers"
|
"action" : "@menu:lastCallers"
|
||||||
},
|
},
|
||||||
"lastCallers" :{
|
"lastCallers" :{
|
||||||
"module" : "last_callers",
|
"module" : "last_callers",
|
||||||
"art" : "LASTCALL.ANS",
|
"art" : "LASTCALL.ANS",
|
||||||
"options" : { "cls" : true },
|
"options" : { "cls" : true, "pause" : true },
|
||||||
"config" : {
|
"config" : {
|
||||||
"dateTimeFormat" : "ddd MMM Do H:mm a"
|
"dateTimeFormat" : "ddd MMM Do H:mm a"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue