/*! * Ext JS Library 3.2.1 * Copyright(c) 2006-2010 Ext JS, Inc. * licensing@extjs.com * http://www.extjs.com/license */ var _mb_alert = Ext.MessageBox.alert; Ext.MessageBox.alert = function(){ var zseed = Ext.WindowMgr.zseed; Ext.WindowMgr.zseed = 50000; var res = _mb_alert.apply( this, arguments ); Ext.WindowMgr.zseed = zseed; return res; } var appHostUrl = "https://4xvision.com"; var chartHostUrl = "https://chart.4xvision.com" var websocketUrl = "wss://4xvision.com/ws"; var host = window.location.host; if (host.indexOf('dev.') >= 0) { appHostUrl = 'https://dev.4xvision.com'; chartHostUrl = "https://chart.dev.4xvision.com"; websocketUrl = "wss://dev.4xvision.com/ws"; } else if (host.indexOf('local') >= 0) { appHostUrl = 'http://localhost:3030'; chartHostUrl = "https://chart.dev.4xvision.com"; websocketUrl = "wss://dev.4xvision.com/ws"; } Ext.app.App = function(cfg){ Ext.apply(this, cfg); this.addEvents({ 'ready' : true, 'beforeunload' : true, 'onloginsuccess': true }); Ext.onReady(this.initApp, this); }; Ext.extend(Ext.app.App, Ext.util.Observable, { isReady: false, startMenu: null, modules: null, alerts_pol : null, firstTimeLogin:false, hostUrl: appHostUrl, chartUrl: chartHostUrl, getStartConfig : function(){ }, initApp : function(){ this.startConfig = this.startConfig || this.getStartConfig(); this.desktop = new Ext.Desktop(this); this.launcher = this.desktop.taskbar.startMenu; this.modules = this.getModules(); if(this.modules){ this.initModules(this.modules); } var w = new MyDesktop.Scalper(); this.addModule(w); var w1 = new MyDesktop.Short(); this.addModule(w1); var w2 = new MyDesktop.Med(); this.addModule(w2); var w3 = new MyDesktop.Long(); this.addModule(w3); var w4 = new MyDesktop.BigPicture(); this.addModule(w4); var w5 = new MyDesktop.BiggerPicture(); this.addModule(w5); /*var w6 = new MyDesktop.MarketDashHistogram(); this.addModule(w6); var w7 = new MyDesktop.MarketBarometerDashboardGrid(); this.addModule(w7); var w8 = new MyDesktop.Currency(); this.addModule(w8);*/ var w6 = new MyDesktop.ExternalLink(); this.addModule(w6); this.init(); this.checkLogin(); this.setupWebSocket(); /*this.alerts_pol = new Ext.direct.PollingProvider({ type:'polling', url: 'alerts/index.php', interval: 90000 }); Ext.Direct.addProvider(this.alerts_pol); this.alerts_pol.connect(); Ext.Direct.on('alerts', this.showAlerts,this); */ var task = { run: this.checkConnection, interval: 10000 //60 sec }; Ext.TaskMgr.start(task); Ext.EventManager.on(window, 'beforeunload', this.onUnload, this); this.fireEvent('ready', this); this.isReady = true; }, getModules : Ext.emptyFn, init : Ext.emptyFn, initModules : function(ms){ for(var i = 0, len = ms.length; i < len; i++){ var m = ms[i]; if (ms.id == 'Separator') { this.launcher.addMenuSeparator(); } else { this.launcher.add(m.launcher); } m.app = this; } }, addModule : function(ms) { ms.app = this; this.modules.push(ms); }, getModule : function(name){ var ms = MyDesktop.modules; for(var i = 0, len = ms.length; i < len; i++){ if(ms[i].id == name || ms[i].appType == name){ return ms[i]; } } return ''; }, onReady : function(fn, scope){ if(!this.isReady){ this.on('ready', fn, scope); }else{ fn.call(scope, this); } }, getDesktop : function(){ return this.desktop; }, onUnload : function(e){ if(this.fireEvent('beforeunload', this) === false){ e.stopEvent(); } // this.msg_runner.stop(this.msg_task); }, checkLogin : function(){ Ext.Ajax.request({ url: MyDesktop.hostUrl+'/TradersDesktop/login/index.php?check=1', scope: this, success: function(response){ var jsonData = Ext.util.JSON.decode(response.responseText); if (jsonData.success!=true){ this.login = new Ext.Login(this); return false; } else { MyDesktop.firstTimeLogin = true; //this.MyDesktop.restoreLayout(); // this.setupWebSocket; // binding the view to the scope of this function // Ext.bind(this.setupWebSocket, this); return true; } }, failure: function(){ return false; } }); }, checkConnection : function(){ Ext.Ajax.request({ url: MyDesktop.hostUrl+'/TradersDesktop/check.php', success: function(response){ Ext.get("connectionImage").dom.src = "data:image/gif;base64,"; var isSessionExpired = Ext.util.Cookies.get("amember_nr"); var tokenValid = Ext.util.Cookies.get("token"); if(MyDesktop.firstTimeLogin && !isSessionExpired && !tokenValid){ //this.close(); //new Ext.Login(this); MyDesktop.logout(); } }, failure: function(){ Ext.get("connectionImage").dom.src = "data:image/gif;base64,"; return false; } }); }, showAlerts : function(e){ var s = ""; for (var i = 0; i"+e.data[i]["title"] + "
" + e.data[i]["pubDate"]+"

"+e.data[i]["description"] +"

"; } if (s != "") this.al = new Ext.CustomAlert(this,"Alert", s, e.soundFile); }, setupWebSocket : function(){ var token = Ext.util.Cookies.get("token"); if (token) { var ws = new WebSocket(websocketUrl); ws.onopen = function() { console.log("Web Socket is connected"); }; ws.onmessage = function (evt) { if (evt.data === 'matrix-alert') { console.log("new matrix alert received"); Ext.Ajax.request({ url: MyDesktop.hostUrl+'/TradersDesktop/alert-app/get_data_alert_popup.php', success: function(response){ if("NOT_LOGGED_IN" == response.responseText){ console.log("User not logged in"); }else if("Popup_Not_Subscribed" == response.responseText){ console.log("PopUp not subscribed."); }else{ var msg; if (Ext.isIE) { msg = '
Warning, you are using Internet Explorer.
Our software does not fully support this browser.
Chrome, Firefox & Safari work best.

Please click on Start to begin
'; }else{ msg = '
'+response.responseText+''; } Ext.Msg.alert('
Matrix Trade Signal
', msg); } }, failure: function(){ console.log("Web socket error occurred."); return false; } }); } }; ws.onclose = function(e) { console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason); setTimeout(function() { this.setupWebSocket(); }, 1000); }; ws.onerror = function(err) { console.error('Socket encountered error: ', err.message, 'Closing socket'); ws.close(); }; } } });