Skip to content

Commit ad95e13

Browse files
committed
Updated logic used to set up tabs in the update() method in the Horizon app
1 parent 7af0e28 commit ad95e13

File tree

1 file changed

+76
-20
lines changed

1 file changed

+76
-20
lines changed

ui/javascript/app/Horizon.js

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ javaxt.express.app.Horizon = function(parent, config) {
186186
//Set global configuration variables
187187
if (!config.fx) config.fx = new javaxt.dhtml.Effects();
188188

189-
if (!config.waitmask) config.waitmask = new javaxt.express.WaitMask(document.body);
189+
if (!config.waitmask || !config.waitmask.el.parentNode)
190+
config.waitmask = new javaxt.express.WaitMask(document.body);
190191
waitmask = config.waitmask;
191192

192193

@@ -244,21 +245,8 @@ javaxt.express.app.Horizon = function(parent, config) {
244245
document.title = config.name;
245246

246247

247-
//Add tabs
248-
if (tabs){
249-
if (isArray(tabs)){
250-
tabs.forEach((tab)=>{
251-
addTab(tab.name, tab.cls);
252-
});
253-
}
254-
else{
255-
for (var key in tabs) {
256-
if (tabs.hasOwnProperty(key)){
257-
addTab(key, tabs[key]);
258-
}
259-
}
260-
}
261-
}
248+
//Update tabs
249+
updateTabs(tabs);
262250

263251

264252
//Update user
@@ -449,7 +437,7 @@ javaxt.express.app.Horizon = function(parent, config) {
449437
var tab = tabs[key];
450438
if (tab.isVisible()){
451439
if (tab.className==="active"){
452-
currTab = tab;
440+
currTab = key;
453441
}
454442
if (key.toLowerCase()===t){
455443
requestedTab = tab;
@@ -489,7 +477,8 @@ javaxt.express.app.Horizon = function(parent, config) {
489477
tabs[currTab].click();
490478
}
491479
else{
492-
Object.values(tabs)[0].click();
480+
var tab = Object.values(tabs)[0];
481+
if (tab) tab.click();
493482
}
494483
}
495484

@@ -531,6 +520,7 @@ javaxt.express.app.Horizon = function(parent, config) {
531520
}
532521
else{
533522
confirm({
523+
width: 515,
534524
title: "Update Available",
535525
text: "An update is available for this application. " +
536526
"Would you like to update now?",
@@ -590,9 +580,75 @@ javaxt.express.app.Horizon = function(parent, config) {
590580

591581

592582
//**************************************************************************
593-
//** addTab
583+
//** updateTabs
584+
//**************************************************************************
585+
var updateTabs = function(obj){
586+
587+
//Generate a list of tabs to render in the tabbar
588+
var newTabs = {};
589+
if (obj){
590+
if (isArray(obj)){
591+
obj.forEach((tab)=>{
592+
newTabs[tab.name] = tab.cls;
593+
});
594+
}
595+
else{
596+
newTabs = obj;
597+
}
598+
}
599+
600+
601+
//Remove any existing tabs from the tabbar
602+
var activeTab;
603+
for (var key in tabs) {
604+
if (tabs.hasOwnProperty(key)){
605+
var tab = tabs[key];
606+
if (tab.parentNode) tabbar.removeChild(tab);
607+
if (tab.className==="active"){
608+
activeTab = key;
609+
}
610+
}
611+
}
612+
613+
614+
//Update tabbar
615+
for (var key in newTabs) {
616+
if (newTabs.hasOwnProperty(key)){
617+
if (tabs[key]){
618+
var tab = tabs[key];
619+
tabbar.appendChild(tab);
620+
tab.show();
621+
}
622+
else{
623+
createTab(key, newTabs[key]);
624+
}
625+
}
626+
}
627+
628+
629+
630+
//Raise previously active tab
631+
if (activeTab){
632+
if (newTabs[activeTab]){
633+
tabs[activeTab].className="active";
634+
var panel = panels[activeTab];
635+
if (panel) panel.show();
636+
}
637+
else{
638+
tabs[activeTab].className="";
639+
var panel = panels[activeTab];
640+
if (panel) panel.hide();
641+
}
642+
}
643+
};
644+
645+
646+
//**************************************************************************
647+
//** createTab
594648
//**************************************************************************
595-
var addTab = function(label, className){
649+
var createTab = function(label, className){
650+
if (tabs[label]) return;
651+
596652
var tab = createElement("div", tabbar);
597653
tab.innerText = label;
598654

0 commit comments

Comments
 (0)