* 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) { function prevConf(callingMenu) {
const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client); 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) => { messageArea.changeMessageConference(callingMenu.client, confs[currIndex - 1].confTag, err => {
if (e.confTag === callingMenu.client.user.properties.message_conf_tag) { if(err) {
return true; return; // logged within changeMessageConference()
} }
return false;
reloadMenu(callingMenu);
}); });
if (curr_idx === 0) {
curr_idx = confs.length;
}
messageArea.changeMessageConference(callingMenu.client, confs[curr_idx - 1].confTag, err => {
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
} }
function nextConf(callingMenu) { function nextConf(callingMenu) {
const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client); 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(currIndex === confs.length - 1) {
if (e.confTag === callingMenu.client.user.properties.message_conf_tag) { currIndex = -1;
return true;
} }
return false;
});
if (curr_idx === confs.length - 1) { messageArea.changeMessageConference(callingMenu.client, confs[currIndex + 1].confTag, err => {
curr_idx = -1; if(err) {
return; // logged within changeMessageConference()
} }
messageArea.changeMessageConference(callingMenu.client, confs[curr_idx + 1].confTag, err => {
if (err) { reloadMenu(callingMenu);
//...
}
return;
}); });
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
} }
function prevArea(callingMenu) { function prevArea(callingMenu) {
const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag); 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) => { messageArea.changeMessageArea(callingMenu.client, areas[currIndex - 1].areaTag, err => {
if (e.areaTag === callingMenu.client.user.properties.message_area_tag) { if(err) {
return true; return; // logged within changeMessageArea()
} }
return false;
reloadMenu(callingMenu);
}); });
if (curr_idx === 0) {
curr_idx = areas.length;
}
messageArea.changeMessageArea(callingMenu.client, areas[curr_idx - 1].areaTag, err => {
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
} }
function nextArea(callingMenu) { function nextArea(callingMenu) {
const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag); 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(currIndex === areas.length - 1) {
if (e.areaTag === callingMenu.client.user.properties.message_area_tag) { currIndex = -1;
return true;
} }
return false;
messageArea.changeMessageArea(callingMenu.client, areas[currIndex + 1].areaTag, err => {
if(err) {
return; // logged within changeMessageArea()
}
reloadMenu(callingMenu);
}); });
if (curr_idx === areas.length - 1) {
curr_idx = -1;
}
messageArea.changeMessageArea(callingMenu.client, areas[curr_idx + 1].areaTag, err => {
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
} }