'use strict'; debugger; /* jshint eqnull: true, shadow: false, quotmark: single, eqeqeq: true, undef: true, unused: true, strict: true, curly: false, funcscope: true, globalstrict: true */ /* global __METHOD__, __LINE__, AppStaticLib, StaticLib, LoadingScreen, window, jQuery, document, window */ /* developer code start */ /* global assertgroup */ /* developer code end */ /* debugger; var matcher = window.matchMedia('(prefers-color-scheme: dark)'); matcher.addListener(onUpdate); onUpdate(); function onUpdate(e) { //if (matcher.media === '(prefers-color-scheme: dark') { if (matcher.media.indexOf('dark') !== -1 { //if (matcher.matches) { //lightSchemeIcon.remove(); //document.head.append(darkSchemeIcon); //alert('dark mode ' + matcher.media); debugger; } else { debugger; //document.head.append(lightSchemeIcon); //darkSchemeIcon.remove(); //alert('light mode [' + matcher.media + ']'); } } */ window.__handleConnectionError = function(e, status, errorText, majorError, wipeDom, fromApp) { debugger; if (typeof(status) !== 'number') throw new Error('window.__handleConnectionError reports that the status is not a number'); if (status === 218) throw new Error('You cannot throw a 218, they occur within the ErrorHandler itself.'); if (status === 200) return; if ((status >= 500) && (status < 600)) majorError = true; if ((status === 0) && (majorError === true)) majorError = false; if (wipeDom !== true) wipeDom = false; if (typeof(fromApp) === 'undefined') fromApp = null; /* developer code start */ if ((typeof(window.Framework.prop) === 'object') && (window.Framework.prop.developer === true) && (majorError === true) && (((status >= 500) && (status < 600)) === false)) majorError = false; /* developer code end */ if (majorError !== true) { majorError = false; //wipeDom = true; } else { wipeDom = true; } var __FullScreenElementOnTop = function(el, wipeDom, pos) { if (wipeDom !== true) wipeDom = false; var __Hovered = jQuery(el)[0]; var w = window.document.body; //if (wipeDom === true) w.innerHTML = ''; w.appendChild(__Hovered); var myPos = {left: '0px', top: '0px', width: '100vw', height: '100vh'}; if (typeof(pos) !== 'undefined') { if (typeof(pos.left) !== 'undefined') myPos.left = pos.left; if (typeof(pos.top) !== 'undefined') myPos.top = pos.top; if (typeof(pos.width) !== 'undefined') myPos.width = pos.width; if (typeof(pos.height) !== 'undefined') myPos.height = pos.height; } //__Hovered.id = 'hovered'; __Hovered.style.position = 'absolute'; __Hovered.style.left = myPos.left; __Hovered.style.top = myPos.top; __Hovered.style.width = myPos.width; __Hovered.style.height = myPos.height; //__Hovered.style.background = 'white'; //__Hovered.style.color = 'black'; __Hovered.style.zIndex = 99999; }; var messageList = { 0: 'Internet connection lost', 218: 'This is fine', 400: 'Bad Request', 401: 'Authorization Required', 402: 'Payment Required', 403: 'Access from this machine forbidden', 404: 'File not found', 416: 'Range Not Satisfiable', 417: 'Client Framework Error', 418: 'You are Logged Out', 500: 'Internal Server Error', 511: 'Must Fully Reauthenticate' }; var intmessage = messageList[status]; if (status === -1) intmessage = 'Internal Error'; var message = 'Connection Error: ' + intmessage + '
status=' + status + '
errorText=' + errorText + '
'; var className = ''; var Container = null; var Icon = null; var title = ''; var appdetails = null; var refreshCode = 'if ((typeof(window.Framework) === \'object\') && (typeof(window.Framework.prop) === \'object\')) {window.Framework.prop.forceRefresh = true;} window.location.reload();'; var refreshCode2 = function() { if ((typeof(window.Framework) === 'object') && (typeof(window.Framework.prop) === 'object')) window.Framework.prop.forceRefresh = true; window.location.reload(); }; var fullscreen = null; var style = null; var fatalErrMessage = null; var fatalErrType = null; var originalStatus = status; try { if (((e instanceof ReferenceError) === true) || ((e instanceof SyntaxError) === true) || ((e instanceof RangeError) === true) || ((e instanceof TypeError) === true) || ((e instanceof Error) === true)) { message = '

' + errorText + '

'; var ErrType = e.constructor.name; if (typeof(ErrType) === 'undefined') ErrType = 'Error'; var showType = 'User'; if ((typeof(window.Framework.V5) !== 'undefined') && (window.Framework.V5 !== null)) { if (window.Framework.V5.Developer.Enabled === true) { showType = 'Developer'; } } else { if (window.Framework.prop.developer === true) showType = 'Developer'; } debugger; if (typeof(window.Framework.ErrTypes[showType][ErrType.toLowerCase()]) !== 'undefined') message = window.Framework.ErrTypes[showType][ErrType.toLowerCase()]; var stack = ''; var body = 'Ooopsie, a ' + e.constructor.name + ' just occurred, what happened?'; var height = 175; var width = 400; title = (fromApp !== null) ? fromApp.AppDetails.GetAppPath() + '()' : 'Internal Error'; if (showType === 'Developer') { var lines = e.stack.split('\n'); var regex = null; var m = null; var method = ''; var line = ''; var pos = ''; height = 400; width = 600; stack = ''; var stacklines = ''; var temp = ''; var mainErrLine = 0, mainErrPos = 0, count = 1, mainErrMethod = ''; var file = (fromApp !== null) ? fromApp.AppDetails.GetAppPath() : 'N/A'; for (var i = 0; i < lines.length; i++) { try { if (i === 0) { regex = /^(\w+)+:\s*(.*)*/; if ((m = regex.exec(lines[i])) !== null) { if (fromApp !== null) { body = m[2].replace('App.', fromApp.AppDetails.GetAppPath()); } else { body = m[2]; } } continue; } else if (i === 1) { //regex = /^\s*at\s([\w\.]+)+\s*(?:[\w\.\s\(\'\)])*(?=\s*\(\w+\s*at\s*)\(eval\s*at\s*([<\(\>\)\w]+)\s*\(\w+\s+at\s*.*\)\),\s\2:(\d*):(\d*)/; //regex = /\s*at\s*([\w\.]+)\s\(.*,\s([<\(\>\)\w]+):(\d*):(\d*)\)$/; //regex = /\s*at\s*\b((?:[\w\.]+)*)\b\s*(\.<\w+>)\s\({1}.*:(\d+):(\d+)\){1}/; //regex = /\s*at\s*\b((?:[\w\.]+)*)\b\s*(\.<\w+>)?\s\({1}https?:\/\/.*:(\d+):(\d+)\){1}/; //regex = /\s*at\s*\b((?:[\w\.]+)*\b\s*(?:\.<\w+>)?)\s\({1}(eval\sat\s<\w+>\s\(eval\sat\s\w+\s\()?https?:\/\/.*:(\d+):(\d+)\){1}/; //regex = /\s*at\s*(((?:[\w\.\-_0-9]+)*)?\s*(?:\.<\w+>)?)\s+\((?:eval\sat\s<\w+>\s\(eval\sat\s\w+\s\()?https?:\/\/.*:(\d+):(\d+)\)/; if (lines[i].includes('(eval') === true) { regex = /\s*at\s*(((?:[\w\.\-_0-9]+)*)?\s*(?:\.<\w+>)?)\s+\((?:eval\sat\s<\w+>\s\()?eval\sat\s\w+\s\(https?:\/\/.*:(\d+):(\d+)\)/; } else { regex = /\s*at\s*((?:[\w\.\-_0-9<>]+)*)?\s+(\(eval\sat\s\w+\s)?\(https?:\/\/.*:(\d+):(\d+)\)/; } debugger; if ((m = regex.exec(lines[i])) !== null) { //if (regex.test(lines[i]) === true) { //m = regex.exec(lines[i]); mainErrMethod = m[1]; mainErrLine = m[3]; mainErrPos = m[4]; title = mainErrMethod + '(' + mainErrLine + ':' + mainErrPos + ')'; mainErrMethod = mainErrMethod.replace('App.', file + '.') + '()'; stacklines += ''; } count++; continue; } if (lines[i].includes('(eval') === true) { regex = /\s*at\s*(https?:\/\/.*\s*):(\d+):(\d+)/; } else { regex = /\s*at\s*((?:[\w\.\-_0-9<>]+)*)?\s+(\(eval\sat\s\w+\s)?\(https?:\/\/.*:(\d+):(\d+)\)/; } if ((m = regex.exec(lines[i])) !== null) { debugger; method = m[1]; line = m[3]; pos = m[4]; //if (method === 'Object.eval') continue; stacklines += ''; count++; continue; } //regex = /\s*at\s([\w\.]+)\s(?:\(.*\),\s)<\w+>:(\d+):(\d+)\)$/; regex = /^\s*at\s*((?:[\w\.<>]+)*)\s*(\[as\s\w+\])?(?:\.<\w+>)?\s/;//\(https?:\/\/(?!jquery)(?:[\w+\/]+)*.*:(\d+):(\d+)\){1}/; if ((m = regex.exec(lines[i])) !== null) { method = m[1]; line = 'N/A';//m[3]; pos = 'N/A';//m[4]; if (method === 'Object.eval') continue; stacklines += ''; count++; continue; } regex = /^\s*at\s*(((?:[\w\.\-_0-9]+)*)?\s*(?:\.<\w+>)?)\s+/;//\((?:eval\sat\s\w+\s\()?https?:\/\/.*:(\d+):(\d+)\)/; debugger; if ((m = regex.exec(lines[i])) !== null) { method = m[1]; line = 'N/A'; pos = 'N/A'; if (method === 'Object.eval') continue; stacklines += ''; count++; continue; } //regex = /\s?at\s([\w\.]+)+\s*\((?:[\w\s]*)+.*\)\),\s*.*:(\d*):(\d*)/; //regex = /^\s*at\s([\w\.]+)*(?=\s*\()|(?<=,\s*.*:)(\d*):(\d*)/g; //egex = /^\s*at\s([\w\.]+)*(?=\s*\().*(,\s[\<\(]+\w+[\>\)]+:)(\d*):(\d*)\)$/; /* regex = /\s*at\s([\w\.]+)\s(?:\(.*\),\s)\<\w+\>:(\d+):(\d+)\)$/; debugger; m = lines[i].match(regex); if ((m !== null) && (m.length === 2)) { method = m[0].trim(); temp = m[1]; temp = temp.split(':'); line = temp[0]; pos = temp[1]; stacklines += ''; count++; continue; } */ //regex = /^at\s*((?:[\w\.]+)*\s*\[.*\])\s/g; //regex = /^\s*at\s*((?:[\w\.]+)*\s*\[.*\])\s/; regex = /^\s*at\s*\b((?:[\w\.]+)*)\b\s*(?:\[){1}.*(?:\]){1}\s$/; debugger; //m = lines[i].match(regex); //if ((m !== null) && (m.length === 1)) { if ((m = regex.exec(lines[i])) !== null) { method = m[1].trim(); if (method === 'Object.eval') continue; stacklines += ''; count++; continue; } //regex = /\s?at\s((?:[\w\.]+)+\s*\[.*\])\s*\(.*/g; /* debugger; m = regex.exec(lines[i]); if ((m !== null) && (m.length === 2)) { method = m[1].trim(); if (method === 'Object.eval') continue; count++; stacklines += ''; continue; } */ regex = /\s?(at\s(?:[\w\.]+)*)\s*\(.*\)$/g; debugger; //m = regex.exec(lines[i]); //if ((m !== null) && (m.length === 1)) { if ((m = regex.exec(lines[i])) !== null) { method = m[1].trim(); if (method === 'Object.eval') continue; count++; stacklines += ''; continue; } } catch (err) { count++; stacklines += ''; continue; } stacklines += ''; } stack = stack + stacklines + '
#LinePosMethod
' + count + '' + mainErrLine + '' + mainErrPos + '' + StaticLib.EscapeHtml(mainErrMethod) + '
' + count + '' + line + '' + pos + '' + StaticLib.EscapeHtml(method) + '
' + count + '' + line + '' + pos + '' + StaticLib.EscapeHtml(method) + '
' + count + '' + line + '' + pos + '' + StaticLib.EscapeHtml(method) + '
' + count + '' + line + '' + pos + '' + StaticLib.EscapeHtml(method) + '
' + count + 'N/AN/A' + StaticLib.EscapeHtml(method) + '
' + count + 'N/A' + StaticLib.EscapeHtml(method) + '
' + count + 'N/A' + StaticLib.EscapeHtml(method) + '
' + count + '' + err + '' + StaticLib.EscapeHtml(lines[i]) + '
' + count + 'N/A' + StaticLib.EscapeHtml(lines[i]) + '
'; } if (showType !== 'Developer') showType = ''; message = message.replace('{:Title}', e.constructor.name).replace('{:' + showType + 'Message}', body).replace('{:Stack}', stack).replace('{:Line}', mainErrLine).replace('{:Pos}', mainErrPos).replace('{:File}', file).replace('{:Method}', mainErrMethod); //TypeError: Cannot read properties of undefined (reading 'checked') //regex = /^\s*at\s([\w\.]+)+\s*(?:[\w\.\s\('\)])*(?=\s*\(\w+\s*at\s*)\(eval\s*at\s*([\<\(\>\)\w]+)\s*\(\w+\s+at\s*.*\)\),\s\2:(\d*):(\d*)/; //at App.RedrawAffectedRegions (eval at (eval at i (https://code.jquery.com/jquery-3.6.0.min.js:2:88757)), :6097:109) //regex = /\s?at\s([\w\.]+)+\s*\([\w\s]*\(.*\),\s*.*:(\d*)*:(\d*)/; //at Object.eval (eval at i (https://code.jquery.com/jquery-3.6.0.min.js:2:88757), :4950:19) //at Object.i [as RedrawAffectedRegions] (https://code.jquery.com/jquery-3.6.0.min.js:2:88757) //regex = /\s?at\s([\w\.]+)+\s*\(.*\),\s*.*:(\d*)*:(\d*)/; //at Object.jQuery.proxy.RedrawAffectedRegions (eval at (eval at i (https://code.jquery.com/jquery-3.6.0.min.js:2:88757)), :5986:10) //at i (https://code.jquery.com/jquery-3.6.0.min.js:2:88757) if ((typeof(window.Framework.UI) === 'object') && (typeof(window.Framework.UI.MsgBox) === 'function') && (typeof(window.Framework.V5) === 'object') && (window.Framework.V5 !== null) && (window.Framework.V5.__setup === true) && (window.Framework.V5.Setup === true)) return window.Framework.UI.MsgBox({title: '' + e.constructor.name + ' - ' + title, message: message, height: height, width: width}); return; } } catch (fatalErr) { if (e === null) { e = fatalErr; fatalErrMessage = fatalErr.message; fatalErrType = fatalErr.constructor.name; } else { if (fromApp !== null) appdetails = fromApp.AppDetails.GetAppPath('/'); if (title === '') title = 'Unknown (' + appdetails + ')'; message = '

Original Title: ' + title + '

Original Error: ' + errorText + '

'; fatalErrMessage = fatalErr.message; fatalErrType = fatalErr.constructor.name; //message = '

' + errorText + '

Fatal Error

' + fatalErr.message + '

'; //message = errorText + '

' + errorText + '

Fatal Error

' + fatalErr.message + '

'; //if (typeof(e.target) !== 'undefined') { //var thisApp = AppStaticLib.GetThisApp(e.target); //if (thisApp !== null) appdetails = ' in ' + thisApp.AppDetails.GetAppPath('/'); //} } status = 218; } switch(status) { case 218: { //Blue Screen className = 'ROMBlueScreen'; Icon = 'fa fa-expand-triangle'; //title = '218 - Internal Framework Error'; //if ((e instanceof Error) && (AppStaticLib.GetThisApp(e.target) !== null)) appdetails = ' in ' + AppStaticLib.GetThisApp(e.target).AppDetails.GetAppPath('/'); fullscreen = (window.emulationMode !== 0/*APP*/); if ((typeof(window.Framework.V5) === 'object') && (window.Framework.V5 !== null)) fullscreen = (window.Framework.V5.AppPresentationMode !== window.Framework.V5.AppPresentationModes.APP); style = ''; Container = jQuery('
'); Container.html('

' + fatalErrType + '(' + status + '): ' + intmessage + '

Whilst processing the original Error that occured, we encountered a new error.

' + fatalErrMessage + '


Original Status: ' + ErrType + '(' + originalStatus + ')

' + message + '
Original Caller App Details:' + appdetails + '


' + style + ''); //Container = jQuery('



218 (' + intmessage + ')


While processing the following error, an internal error occured.

' + fatalErrMessage + '

' + message + '
Original Caller App Details:' + appdetails + '


' + style + '
'); Container.find('#CloseBtn').click(jQuery.proxy(function(){this.remove();}, Container)); __FullScreenElementOnTop(Container, false, {height:'50vh', width:'50vw', top:'25vh', left:'25vw'}); return; } case 511: { window.location.href = '/cache/locked.html'; return; } case 402: { if ((e instanceof Error) && (AppStaticLib.GetThisApp(e.target) !== null)) appdetails = ' in ' + AppStaticLib.GetThisApp(e.target).AppDetails.GetAppPath('/'); var NewApp = window.WindowStruct.create(); NewApp.servletGroup = 'finance'; NewApp.name = 'epayment'; NewApp.layout = 'terminal'; NewApp.argsIn = {AppDetails: appdetails}; new window.Framework.Methods.GetApp(NewApp).invoke(); return; } case 404: { /* jshint debug: true */debugger; /* jshint debug: false */ if (window.Online === false) break; className = 'ROMMissing'; Icon = 'fa fa-expand-triangle'; title = 'The page is missing'; message = errorText; if (typeof(e.ActionObj) !== 'undefined') { if ((AppStaticLib.IsAnApp(e.ActionObj.caller)) && (typeof(e.ActionObj.caller.On404) === 'function') && (e.ActionObj.caller.AmIRunning === true)) { if (e.ActionObj.caller.On404(e.ActionObj.LastCalledURL) !== false) return; } /* developer code start disabled */ message = e.ActionObj.LastCalledURL; /*URL;*/ /* developer code end disabled */ } appdetails = ''; if ((e instanceof Error) && (AppStaticLib.GetThisApp(e.target) !== null)) appdetails = ' in ' + AppStaticLib.GetThisApp(e.target).AppDetails.GetAppPath('/'); fullscreen = (window.emulationMode !== 0/*APP*/); if ((typeof(window.Framework.V5) === 'object') && (window.Framework.V5 !== null)) fullscreen = (window.Framework.V5.AppPresentationMode !== window.Framework.V5.AppPresentationModes.APP); //style = ''; Container = jQuery('



404



' + title + '


' + message + '' + appdetails + '
' + style + '
'); Container.find('#CloseBtn').click(jQuery.proxy(function(){this.remove();}, Container)); __FullScreenElementOnTop(Container, false, {height:'50vh', width:'50vw', top:'25vh', left:'25vw'}); return; } case 416: { /* jshint debug: true */debugger; /* jshint debug: false */ // System Violation className = 'ROMMissing'; Icon = 'fa fa-expand-triangle'; title = intmessage; message = errorText; appdetails = ''; if ((typeof(e.ActionObj) !== 'undefined') && (typeof(e.ActionObj.caller) !== undefined) && (e.ActionObj.caller !== null)) appdetails = ' in ' + e.ActionObj.caller.AppDetails.GetAppPath('/'); //if ((e instanceof Error) && (AppStaticLib.GetThisApp(e.target) !== null)) { //appdetails = ' in ' + AppStaticLib.GetThisApp(e.target).AppDetails.GetAppPath('/'); //} fullscreen = (window.emulationMode !== 0/*APP*/); if ((typeof(window.Framework.V5) === 'object') && (window.Framework.V5 !== null)) fullscreen = (window.Framework.V5.AppPresentationMode !== window.Framework.V5.AppPresentationModes.APP); style = ''; Container = jQuery('



416



' + title + '


' + message + '' + appdetails + '
' + style + '
'); Container.find('#CloseBtn').click(jQuery.proxy(function(){this.remove();}, Container)); __FullScreenElementOnTop(Container, false, {height:'50vh', width:'50vw', top:'25vh', left:'25vw'}); return; } case 417: { //Blue Screen className = 'ROMBlueScreen'; Container = jQuery('
'); Container.html('

System Error: ' + intmessage + '

' + errorText + '

'); __FullScreenElementOnTop(Container, wipeDom); return; } case 418: { //Blue Screen className = 'ROMLoggedOut'; Container = jQuery('
'); if (StaticLib.IsJSONString(errorText) === true) { errorText = JSON.parse(errorText); Container.html('

' + errorText.Title + '

' + errorText.Body + '

'); wipeDom = false; } else { Container.html('

' + intmessage + '

' + errorText + '

'); window.setTimeout(refreshCode2, 3000); } __FullScreenElementOnTop(Container, wipeDom); window.Framework.teapot = true; //window.Framework.prop.screenLocked = true; //debugger; // framework polling return; } case 0: { // not connected, or connection was dropped break; } case 504: { break; } case 500: /*falls through */ default: { if ((typeof(window.Framework.UI) === 'object') && (typeof(window.Framework.UI.MsgBox) === 'function') && (typeof(window.Framework.V5) === 'object') && (window.Framework.V5 !== null) && (window.Framework.V5.__setup === true) && (window.Framework.V5.Setup === true)) { return window.Framework.UI.MsgBox({title: 'Developer Error A48', message: message}); } //Blue Screen className = 'ROMBlueScreen'; Container = jQuery('
'); Container.html('

Connection Error: ' + intmessage + '

' + errorText + '

'); __FullScreenElementOnTop(Container, wipeDom); return; } } if (wipeDom === true) { if (window.Framework.V5.SocketServer().IsConnected === true) window.Framework.V5.SocketServer().Disconnect(); if (window.Online === true) window.Framework.prop.screenLocked = true; debugger; // framework polling if (window.Framework.polling === true) window.Framework.polling.pauseTime(); } }; if (typeof(window.CachedControls) !== 'object') window.CachedControls = {}; /* var AddControlToApp = function(thisApp, name) { if (AppStaticLib.IsAnApp(thisApp) !== true) throw new Error('AddControlToApp needs to be called with an App'); //var data = jQuery.proxy(function(name){return eval('(' + name + ')'); }, window.CachedControls)(name); var CallMe = jQuery.proxy(eval, window.CachedControls)('(function(){return ' + name + ';})'); var data = window.CachedControls[name]; if (typeof(data) === 'undefined') throw new Error('In AddControlToApp no control was found for: "' + name + '"'); var EvalInContextMaybe = function(data, name) { data = data + 'this.TEMPControls.' + name + '= ' + name + ';'; eval(data); }; jQuery.proxy(EvalInContextMaybe, thisApp)(data, name); };*/ if (typeof(window.Framework.Methods) === 'undefined') window.Framework.Methods = {}; window.Framework.Methods.LogDataSize = function(connection, data) { var size = (connection.getResponseHeader('Content-Length')); if (size === null) { try { size = ((encodeURI(data).split(/%..|./).length - 1) / 1024); } catch (e) { // falls through size = 0; } } else { size = (size / 1024); } window.DataSize += size; var d = document.getElementById('TotalDataUsage'); if (d === null) return; if (window.DataSize <= 1024) { d = document.getElementById('TotalDataUsage'); if (d === null) throw new Error('No stylesheet?'); d.innerHTML = StaticLib.Math.Round(window.DataSize, 4); d = document.getElementById('TotalDataUsage'); if (d === null) throw new Error('No stylesheet?'); d.innerHTML = StaticLib.Math.Round(window.DataSize, 4); } else { d = document.getElementById('DataMeasure'); if (d === null) throw new Error('No stylesheet?'); d.innerHTML = 'MB'; d = document.getElementById('TotalDataUsage'); if (d === null) throw new Error('No stylesheet?'); d.innerHTML = StaticLib.Math.Round((window.DataSize / 1024), 4); } }; StaticLib.DeepSeal(window.Framework.Methods.LogDataSize); StaticLib.DeepFreeze(window.Framework.Methods.LogDataSize); var DependencyLoader = function(dependencies, RunWhenDone, showLoading, loadAsControls) { var __ShowLoading = false; var __ShowSubLoading = false; var __LoadAsControls = false; var __LoadedArray = {}; var _WhenDone = function(){}; var _WhenPriorityDone = function(){}; var __LowerPriorityURLS = ''; var _Ctor = jQuery.proxy(function(dependencies, RunWhenDone, showLoading, loadAsControls) { window.FilesLoadedList = []; window.LoadedDependencyKeyList = []; if (typeof(RunWhenDone) !== 'function') throw new Error('DependencyLoader: Argument 2 (RunWhenDone) must be a function'); if (showLoading === true) __ShowLoading = true; if (loadAsControls === true) __LoadAsControls = true; _WhenDone = RunWhenDone; _WhenPriorityDone = RunWhenDone; var type = typeof(dependencies); var isString = (type === 'string'); var isNumeric = (type === 'number'); var isArray = StaticLib.IsArray(dependencies); if ((dependencies === null) || ((!isString) && (!isNumeric) && (!isArray))) throw new Error('DependencyLoader: Argument 1 (dependencies) must be a Dependency Key, or a list or URLs'); if ((isString === true) || (isNumeric === true)) { _LoadByKey(dependencies); if ((typeof(window.LoadingScreenTaskTypes) !== 'undefined') && (typeof(window.LoadingScreenTaskTypes.api) !== 'undefined')) { if (__ShowLoading === false) return; /* developer code start */ assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); /* developer code end */ var task = { Type: window.LoadingScreenTaskTypes.api, TaskID: 'dependencies', TaskDescription: 'Loading Dependencies', Priority: 0 }; if ((window.DependencyLoadingScreen === null) || (typeof(window.DependencyLoadingScreen) === 'undefined')) { window.DependencyLoadingScreen = new LoadingScreen({ TaskList:[task] }); } else { window.DependencyLoadingScreen.AddTask(task); } } } else { if ((dependencies === null) || (typeof(dependencies) === 'undefined') || (typeof(dependencies.length) !== 'number') || (dependencies.length === 0)) throw new Error('Dependency loader expects an array of URLs, or a dependency key (string or number)'); if (typeof(dependencies[0].priority) !== 'undefined') dependencies = _RecursiveArray(dependencies); _LoadByURLs(dependencies); } }, this); var _LoadByKey = jQuery.proxy(function(key) { // check if the key is already load before if not then go and get the list of the files if ((window.LoadedDependencyKeyList.indexOf(key)) === -1) { window.LoadedDependencyKeyList.push(key); var postData = {'key': key}; var stylesheet = document.getElementById('currentStyleSheet'); if (stylesheet !== null) { var themeName = stylesheet.href; if (themeName !== '') { var removeBefore = 'themes/'; var index = themeName.indexOf(removeBefore); if (index !== -1) { themeName = themeName.substring((index + removeBefore.length)); } var removeAfter = '/'; index = themeName.indexOf(removeAfter); if (index !== -1) { themeName = themeName.substring(0, index); } postData.theme = themeName; } } var api = new window.Framework.Methods.GetAPI('system', 'GetDependancyFiles', this, _Callback_ProcessDependencies, postData); api.servletGroup = 'platform'; api.showLoading = false; api.invoke(); } else { _DoneLoading(); } }, this); var _LoadByURLs = jQuery.proxy(function(urlList, tries) { if ((typeof(urlList) === 'undefined') || (urlList === null) || (urlList.length === 0)) return _DoneLoading(); if (typeof(tries) === 'undefined') tries = 0; var extension = ''; var url = ''; var callback = null; var AlreadyLoaded = jQuery('script[fromurl], style[fromurl]'); var length = AlreadyLoaded.length; var tag; var i; for (i = 0; i < length; i++) { tag = AlreadyLoaded[i]; __LoadedArray[tag.getAttribute('fromurl')] = true; } length = urlList.length; var type = ''; var loadDep = function() { new DependencyLoader(__LowerPriorityURLS, _WhenPriorityDone, __ShowSubLoading, __LoadAsControls); }; for (i = 0; i < length; i++) { url = urlList[i]; type = typeof(url); if (type === 'string') { if (__LoadedArray[url] === true) continue; __LoadedArray[url] = false; if (url.indexOf('?') > 0) { if (url.indexOf('.php?type=') === -1) { var res = url.split('?'); extension = res[0].slice(-3); } } if (extension === '') extension = url.slice(-3); if (extension === 'css') { callback = __Callback_ReceiveCSS; } else if (extension === '.js') { callback = _Callback_ReceiveJS; if (__LoadAsControls) { callback = _Callback_ReceiveControl; if (window.Framework.GlobalControls.indexOf(url) !== -1) callback = _Callback_ReceiveJS; } } else { throw new Error('DependencyLoader: [LoadByURLs] The only allowed dependencies are CSS files and JS files'); } extension = ''; jQuery.ajax({ 'url': url, 'method': 'GET', 'dataType': 'text', 'error': _Callback_TryAgain, 'success': callback }).ActionObj = {URL: url, OriginalContext: this, NumberOfTries: (tries + 1)}; } else { if (StaticLib.IsArray(url)) { __LowerPriorityURLS = url; _WhenDone = jQuery.proxy(loadDep, this); } if (__ShowLoading === true) { __ShowLoading = false; __ShowSubLoading = true; } } } var filesToCheck = Object.keys(__LoadedArray); length = filesToCheck.length; var urlToCheck = ''; for (i = 0; i < length; i++) { urlToCheck = filesToCheck[i]; if (__LoadedArray[urlToCheck]) continue; return; } _DoneLoading(); }, this); var _Callback_ProcessDependencies = jQuery.proxy(function(msg) { //if (connection.status !== 200) return window.__handleConnectionError(connection, connection.status, connection.statusText, false); var primary_DependencyFile = []; //if (StaticLib.IsJSONString(msg)) msg = JSON.parse(msg); primary_DependencyFile = _RecursiveArray(msg); window.FilesLoadedList = window.FilesLoadedList.concat(primary_DependencyFile); _LoadByURLs(primary_DependencyFile); }, this); var _RecursiveArray = jQuery.proxy(function(data) { if (data == []) return data; if ((typeof(data) === 'undefined') || (data === null) || (data.length === 0)) { /* developer code start */ if ((typeof(window.Framework) !== 'undefined') && (window.Framework.prop.developer)) window.Framework.UI.MsgBox({title: 'Developer Notice', message: 'DependencyLoader.RecursiveArray() reports data from server is ""'}); /* developer code end */ return; } var priority = data[0].priority; var i; for (i = 0; i < data.length; i++) { if (data[i].Global === 1) window.Framework.GlobalControls.push(data[i].file); if (priority > data[i].priority) priority = data[i].priority; } var primaryArray = []; var secondaryArray = []; for (i = 0; i < data.length; i++) { if (data[i].NeverCache === 1) data[i].file += '?' + parseInt(StaticLib.GetRandom(0, 100000)); // if the file already load then no need to add to array collection if (window.FilesLoadedList.indexOf(data[i].file) !== -1) { data.splice(i, 1); i--; if (i < 0) continue; priority = data[0].priority; for (var j = 0; j < data.length; j++) if (priority > data[j].priority) priority = data[j].priority; continue; } if (__ShowLoading === true) { /* developer code start */ assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); /* developer code end */ var task = { Type: window.LoadingScreenTaskTypes.api, TaskID: data[i].file, TaskDescription: 'Loading Files...', Priority: (10 - data[i].priority) }; if (typeof(data[i].message) !== 'undefined') task.TaskDescription = data[i].message; if ((window.DependencyLoadingScreen === null) || (typeof(window.DependencyLoadingScreen) === 'undefined')) { window.DependencyLoadingScreen = new LoadingScreen({ TaskList:[task] }); } else { window.DependencyLoadingScreen.AddTask(task); } } if (priority === data[i].priority) { primaryArray.push(data[i].file); } else { if ((typeof(data[i].file) !== 'undefined') && (!StaticLib.Empty(data[i].file))) secondaryArray.push(data[i]); } } if (secondaryArray.length > 0) { var sortedSecondaryArray = _RecursiveArray (secondaryArray); primaryArray.push(sortedSecondaryArray); } return primaryArray; }, this); var __Callback_ReceiveCSS = jQuery.proxy(function(data, status, connection) { var ct = connection.getResponseHeader('content-type') || ''; if (ct.indexOf('text/css') === -1) throw new Error('Invalid data received'); window.Framework.Methods.LogDataSize(connection, data); if (connection.status !== 200) window.__handleConnectionError(connection, connection.status, connection.statusText, false); var depLoad = connection.ActionObj.OriginalContext; if ((depLoad === null) || (typeof(connection.ActionObj.URL) !== 'string') || (connection.ActionObj.URL.length === 0)) return; var newStyle = document.createElement('STYLE'); newStyle.innerHTML = data; newStyle.setAttribute('fromurl', connection.ActionObj.URL); /* developer code start */ assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); /* developer code end */ document.head.appendChild(newStyle); __LoadedArray[connection.ActionObj.URL] = true; if (((window.DependencyLoadingScreen !== null) || (typeof(window.DependencyLoadingScreen) !== 'undefined')) && (window.DependencyLoadingScreen.HasTask(connection.ActionObj.URL))) window.DependencyLoadingScreen.CompleteTask(connection.ActionObj.URL); var filesToCheck = Object.keys(__LoadedArray); var length = filesToCheck.length; var urlToCheck = null; for (var i = 0; i < length; i++) { urlToCheck = filesToCheck[i]; if (__LoadedArray[urlToCheck]) continue; return; } _DoneLoading(); }, this); var _Callback_ReceiveControl = jQuery.proxy(function(data, status, connection) { window.Framework.Methods.LogDataSize(connection, data); if (connection.status !== 200) window.__handleConnectionError(connection, connection.status, connection.statusText, false); var ct = connection.getResponseHeader('content-type') || ''; if (ct.indexOf('application/javascript') > -1) { /* developer code start */ } else if (ct.indexOf('html') > -1) { /* jshint debug: true */debugger; /* jshint debug: false */ //do something if (StaticLib.IsJSONString(data)) { if ((typeof(window.Framework) !== 'undefined') && (typeof(window.Framework.prop) !== 'undefined') && (window.Framework.prop.developer)) window.Framework.UI.MsgBox({title: '_Callback_ReceiveControl Error', message: 'Data returned is not HTML but instead JSON, please specify your content-type header before returning your data', modal: false, width: 400, height: 300}); data = JSON.parse(data); } } else if (ct.indexOf('json') > -1) { // handle json here /* jshint debug: true */debugger; /* jshint debug: false */ if (StaticLib.IsJSONString(data) === false) throw new Error('Not a valid JSON string'); data = JSON.parse(data); /* developer code end */ } else { throw new Error('Unknown content type'); } var depLoad = connection.ActionObj.OriginalContext; if ((depLoad === null) || (typeof(connection.ActionObj.URL) !== 'string') || (connection.ActionObj.URL.length === 0)) return; if (((window.DependencyLoadingScreen !== null) || (typeof(window.DependencyLoadingScreen) !== 'undefined')) && (window.DependencyLoadingScreen.HasTask(connection.ActionObj.URL))) window.DependencyLoadingScreen.CompleteTask(connection.ActionObj.URL); //var controlName = window.Framework.ControlLookup[connection.ActionObj.URL].ClassName; //window.CachedControls[controlName] = data; var filename = connection.ActionObj.URL; if (filename.indexOf('?') !== -1) filename = filename.substr(0, filename.indexOf('?')); window.CachedControls[filename] = data; __LoadedArray[connection.ActionObj.URL] = true; var filesToCheck = Object.keys(__LoadedArray); var length = filesToCheck.length; var urlToCheck = ''; for (var i = 0; i < length; i++) { urlToCheck = filesToCheck[i]; if (__LoadedArray[urlToCheck] === true) continue; return; } _DoneLoading(); _WhenDone = function(){}; }, this); var _Callback_ReceiveJS = jQuery.proxy(function(data, status, connection) { window.Framework.Methods.LogDataSize(connection, data); if (connection.status !== 200) window.__handleConnectionError(connection, connection.status, connection.statusText, false); var ct = connection.getResponseHeader('content-type') || ''; if (ct.indexOf('application/javascript') > -1) { /* developer code start */ } else if (ct.indexOf('html') > -1) { //do something /* jshint debug: true */debugger; /* jshint debug: false */ if (StaticLib.IsJSONString(data)) { /* developer code start */ if ((typeof(window.Framework) !== 'undefined') && (typeof(window.Framework.prop) !== 'undefined') && (window.Framework.prop.developer)) window.Framework.UI.MsgBox({title: '_Callback_ReceiveJS Error', message: 'Data returned is not HTML but instead JSON, please specify your content-type header before returning your data', modal: false, width: 400, height: 300}); /* developer code end */ data = JSON.parse(data); } } else if (ct.indexOf('json') > -1) { // handle json here /* jshint debug: true */debugger; /* jshint debug: false */ if (StaticLib.IsJSONString(data) === false) throw new Error('Not a valid JSON string'); data = JSON.parse(data); /* developer code end */ } else { throw new Error('Unknown content type'); } var depLoad = connection.ActionObj.OriginalContext; if ((depLoad === null) || (typeof(connection.ActionObj.URL) !== 'string') || (connection.ActionObj.URL.length === 0)) return; if (((window.DependencyLoadingScreen !== null) || (typeof(window.DependencyLoadingScreen) !== 'undefined')) && (window.DependencyLoadingScreen.HasTask(connection.ActionObj.URL))) window.DependencyLoadingScreen.CompleteTask(connection.ActionObj.URL); var newStyle = document.createElement('SCRIPT'); try { jQuery.proxy(eval, window)(data); } catch (e) { return window.__handleConnectionError(null, 500, 'Could not compile the framework, please quote the following code: ' + /*window.btoa(*/connection.ActionObj.URL + ': ' + e.message/*)*/, true); } newStyle.setAttribute('fromurl', connection.ActionObj.URL); document.head.appendChild(newStyle); __LoadedArray[connection.ActionObj.URL] = true; var filesToCheck = Object.keys(__LoadedArray); var length = filesToCheck.length; var urlToCheck = ''; for (var i = 0; i < length; i++) { urlToCheck = filesToCheck[i]; if (__LoadedArray[urlToCheck]) continue; return; } _DoneLoading(); _WhenDone = function(){}; }, this); var _Callback_TryAgain = jQuery.proxy(function(connection/*, status, errorText*/) { if (connection.status !== 200) return window.__handleConnectionError(connection, connection.status, connection.statusText, false); var TryThis = [connection.ActionObj.URL]; var timesTried = connection.ActionObj.NumberOfTries; var depLoad = connection.ActionObj.OriginalContext; if ((depLoad === null) || (typeof(connection.ActionObj.URL) !== 'string') || (connection.ActionObj.URL.length === 0)) return; if (timesTried < 5) jQuery.proxy(_LoadByURLs, depLoad)(TryThis, timesTried); }, this); var _DoneLoading = jQuery.proxy(function() { if (__ShowLoading === true) window.DependencyLoadingScreen.CompleteTask('dependencies'); _WhenDone(); }, this); _Ctor(dependencies, RunWhenDone, showLoading, loadAsControls); return this; }; StaticLib.DeepSeal(DependencyLoader); StaticLib.DeepFreeze(DependencyLoader);