* DRY menu pop/goto into reloadMenu() (temp hack until we can find a good solution for simple redraw)

* Only reloadMenu() if we actually change areas
* Code style cleanup
This commit is contained in:
Bryan Ashby 2016-07-12 23:38:40 -06:00
parent 34b72d5040
commit c94f663947
1 changed files with 45 additions and 77 deletions

View File

@ -78,101 +78,69 @@ function nextMenu(callingMenu) {
});
}
// :TODO: prev/nextConf, prev/nextArea should use a NYI MenuModule.redraw() or such -- avoid pop/goto() hack!
function reloadMenu(menu) {
const prevMenu = menu.client.menuStack.pop();
prevMenu.instance.leave();
menu.client.menuStack.goto(prevMenu.name);
}
function prevConf(callingMenu) {
const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client);
const currIndex = confs.findIndex( e => e.confTag === callingMenu.client.user.properties.message_conf_tag) || confs.length;
let curr_idx = confs.findIndex((e) => {
if (e.confTag === callingMenu.client.user.properties.message_conf_tag) {
return true;
}
return false;
});
if (curr_idx === 0) {
curr_idx = confs.length;
}
messageArea.changeMessageConference(callingMenu.client, confs[curr_idx - 1].confTag, err => {
messageArea.changeMessageConference(callingMenu.client, confs[currIndex - 1].confTag, err => {
if(err) {
//...
return; // logged within changeMessageConference()
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
reloadMenu(callingMenu);
});
}
function nextConf(callingMenu) {
const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client);
let currIndex = confs.findIndex( e => e.confTag === callingMenu.client.user.properties.message_conf_tag);
let curr_idx = confs.findIndex((e) => {
if (e.confTag === callingMenu.client.user.properties.message_conf_tag) {
return true;
if(currIndex === confs.length - 1) {
currIndex = -1;
}
return false;
});
if (curr_idx === confs.length - 1) {
curr_idx = -1;
}
messageArea.changeMessageConference(callingMenu.client, confs[curr_idx + 1].confTag, err => {
messageArea.changeMessageConference(callingMenu.client, confs[currIndex + 1].confTag, err => {
if(err) {
//...
return; // logged within changeMessageConference()
}
return;
reloadMenu(callingMenu);
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
}
function prevArea(callingMenu) {
const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag);
const currIndex = areas.findIndex( e => e.areaTag === callingMenu.client.user.properties.message_area_tag) || areas.length;
let curr_idx = areas.findIndex((e) => {
if (e.areaTag === callingMenu.client.user.properties.message_area_tag) {
return true;
}
return false;
});
if (curr_idx === 0) {
curr_idx = areas.length;
}
messageArea.changeMessageArea(callingMenu.client, areas[curr_idx - 1].areaTag, err => {
messageArea.changeMessageArea(callingMenu.client, areas[currIndex - 1].areaTag, err => {
if(err) {
//...
return; // logged within changeMessageArea()
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
reloadMenu(callingMenu);
});
}
function nextArea(callingMenu) {
const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag);
let currIndex = areas.findIndex( e => e.areaTag === callingMenu.client.user.properties.message_area_tag);
let curr_idx = areas.findIndex((e) => {
if (e.areaTag === callingMenu.client.user.properties.message_area_tag) {
return true;
if(currIndex === areas.length - 1) {
currIndex = -1;
}
return false;
});
if (curr_idx === areas.length - 1) {
curr_idx = -1;
}
messageArea.changeMessageArea(callingMenu.client, areas[curr_idx + 1].areaTag, err => {
messageArea.changeMessageArea(callingMenu.client, areas[currIndex + 1].areaTag, err => {
if(err) {
//...
return; // logged within changeMessageArea()
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
reloadMenu(callingMenu);
});
}