Skip to content

Commit a6afc09

Browse files
committed
Replaced timeout alert with custom dialog in the Horizon app
1 parent ea6b57d commit a6afc09

File tree

1 file changed

+78
-13
lines changed

1 file changed

+78
-13
lines changed

ui/javascript/app/Horizon.js

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,18 @@ javaxt.express.app.Horizon = function(parent, config) {
7979

8080
/** Style for the communication error popup that is rendered when the
8181
* connection to the server is lost. The popup consists of an icon,
82-
* title, message, and a close button. The CSS class should include
83-
* definitions for "icon", "title", "message", and "close".
82+
* title, message, and a close button. Note that the nested style
83+
* properties can be replaced with a string representing a CSS class,
84+
* provided that the class includes definitions for "icon", "title",
85+
* "message", and "close".
8486
*/
85-
communicationError: "communication-error center"
87+
communicationError: {
88+
div: "communication-error center",
89+
icon: "communication-error-icon",
90+
title: "title",
91+
message: "message",
92+
closeButton: "close"
93+
}
8694

8795
},
8896

@@ -145,6 +153,7 @@ javaxt.express.app.Horizon = function(parent, config) {
145153
var ws; //web socket listener
146154
var connected = false;
147155
var communicationError;
156+
var timeoutWarning;
148157

149158

150159
//Header components
@@ -319,8 +328,9 @@ javaxt.express.app.Horizon = function(parent, config) {
319328
}
320329
},
321330
onTimeout: function(){
322-
if (communicationError) communicationError.hide();
323-
alert(config.messages.connectionTimeout);
331+
if (communicationError) communicationError.hide(true);
332+
if (!timeoutWarning) createTimeoutWarning();
333+
timeoutWarning.show();
324334
}
325335
});
326336
};
@@ -500,6 +510,7 @@ javaxt.express.app.Horizon = function(parent, config) {
500510
if (currUser){
501511
if (op==="connect"){
502512
if (communicationError) communicationError.hide();
513+
if (timeoutWarning) timeoutWarning.close();
503514
menuButton.hideMessage();
504515
}
505516
else{
@@ -826,6 +837,7 @@ javaxt.express.app.Horizon = function(parent, config) {
826837
/** Used to create a communications error message
827838
*/
828839
var createErrorMessage = function(){
840+
//if (communicationError) return;
829841

830842
//Create main div
831843
var div = createElement("div", parent, {
@@ -848,9 +860,10 @@ javaxt.express.app.Horizon = function(parent, config) {
848860
isVisible = true;
849861
fx.fadeIn(div, transitionEffect, duration);
850862
};
851-
div.hide = function(){
863+
div.hide = function(nodelay){
852864
if (!isVisible) return;
853865
isVisible = false;
866+
if (nodelay===true) div.style.display = "none";
854867
fx.fadeOut(div, transitionEffect, duration/2);
855868
};
856869
div.isVisible = function(){
@@ -859,14 +872,15 @@ javaxt.express.app.Horizon = function(parent, config) {
859872

860873

861874
//Add content
862-
var error = createElement("div", div, config.style.communicationError);
863-
createElement("div", error, "icon");
864-
createElement("div", error, "title").innerText = "Connection Lost";
865-
createElement("div", error, "message").innerText = config.messages.connectionLost;
866-
var closeButton = createElement("div", error, "close");
875+
var style = config.style.communicationError;
876+
var useClass = isString(style);
877+
var error = createElement("div", div, useClass ? style : style.div);
878+
createElement("div", error, useClass ? "icon" : style.icon);
879+
createElement("div", error, useClass ? "title" : style.title).innerText = "Connection Lost";
880+
createElement("div", error, useClass ? "message" : style.message).innerText = config.messages.connectionLost;
881+
var closeButton = createElement("div", error, useClass ? "close" : style.closeButton);
867882
closeButton.onclick = function(){
868-
div.style.display = "none";
869-
div.hide();
883+
div.hide(true);
870884
setTimeout(()=>{
871885
menuButton.showMessage("Offline");
872886
}, 500);
@@ -879,6 +893,56 @@ javaxt.express.app.Horizon = function(parent, config) {
879893
};
880894

881895

896+
//**************************************************************************
897+
//** createTimeoutWarning
898+
//**************************************************************************
899+
var createTimeoutWarning = function(){
900+
//if (timeoutWarning) return;
901+
902+
//Create window
903+
timeoutWarning = new javaxt.dhtml.Window(document.body, {
904+
width: 470,
905+
valign: "top",
906+
modal: true,
907+
title: "Warning",
908+
style: config.style.javaxt.window,
909+
buttons: [
910+
{
911+
name: "OK",
912+
onclick: function(){
913+
timeoutWarning.close();
914+
}
915+
}
916+
]
917+
});
918+
919+
920+
//Add window to the windows array so it closes automatically on logoff
921+
config.windows.push(timeoutWarning);
922+
923+
924+
//Populate the body
925+
var table = createTable(timeoutWarning.getBody());
926+
table.style.height = "";
927+
var tr = table.addRow();
928+
var d = createElement("div", tr.addColumn({verticalAlign: "top"}), {
929+
padding: "3px 10px"
930+
});
931+
createElement("div", d, config.style.communicationError.icon);
932+
tr.addColumn({ width: "100%" }).innerText =
933+
config.messages.connectionTimeout;
934+
935+
936+
//Watch for open/close events
937+
timeoutWarning.onClose = function(){
938+
menuButton.showMessage("Offline");
939+
};
940+
timeoutWarning.onOpen = function(){
941+
if (communicationError) communicationError.hide();
942+
};
943+
};
944+
945+
882946
//**************************************************************************
883947
//** hideWindows
884948
//**************************************************************************
@@ -1003,6 +1067,7 @@ javaxt.express.app.Horizon = function(parent, config) {
10031067
var getParameter = javaxt.dhtml.utils.getParameter;
10041068
var createTable = javaxt.dhtml.utils.createTable;
10051069
var addShowHide = javaxt.dhtml.utils.addShowHide;
1070+
var isString = javaxt.dhtml.utils.isString;
10061071
var isArray = javaxt.dhtml.utils.isArray;
10071072
var destroy = javaxt.dhtml.utils.destroy;
10081073
var merge = javaxt.dhtml.utils.merge;

0 commit comments

Comments
 (0)