'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) { /* jshint debug: true */ debugger; /* jshint debug: false */ /* * Normalise arguments. */ if (typeof status !== 'number') { status = parseInt(status, 10); if (isNaN(status)) { 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 (typeof errorText !== 'string') { if ( e !== null && typeof e === 'object' && typeof e.statusText === 'string' && e.statusText !== '' ) { errorText = e.statusText; } else { errorText = ''; } } if (typeof fromApp === 'undefined') fromApp = null; if (wipeDom !== true) wipeDom = false; if (majorError !== true) majorError = false; /* * HTTP 5xx errors are major errors. */ if (status >= 500 && status < 600) { majorError = true; } /* * A status of 0 usually means: * * - the internet connection was lost; * - the server could not be reached; * - the request was aborted; * - a CORS or TLS error prevented an HTTP response. * * It should not wipe the entire framework DOM. */ if (status === 0) { majorError = false; wipeDom = false; } /* developer code start */ if ( typeof window.Framework === 'object' && window.Framework !== null && typeof window.Framework.prop === 'object' && window.Framework.prop !== null && window.Framework.prop.developer === true && majorError === true && !(status >= 500 && status < 600) ) { majorError = false; } /* developer code end */ if (majorError === true) { wipeDom = true; } else { majorError = false; } var messageList = { 0: 'Internet connection lost', 218: 'Internal error handler failure', 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', 504: 'Gateway Timeout', 511: 'Must Fully Reauthenticate' }; var originalStatus = status; var intmessage = messageList[status]; if (status === -1) { intmessage = 'Internal Error'; } if (typeof intmessage === 'undefined') { intmessage = 'Unknown connection error'; } if (errorText === '') { errorText = intmessage; } var className = ''; var Container = null; var Icon = null; var title = ''; var appdetails = ''; var style = ''; var fatalErrMessage = ''; var fatalErrType = ''; var refreshTimer = null; var refreshCode = 'if ((typeof(window.Framework) === "object") && ' + '(window.Framework !== null) && ' + '(typeof(window.Framework.prop) === "object")) {' + 'window.Framework.prop.forceRefresh = true;' + '}' + 'window.location.reload();'; var refreshCode2 = function() { if ( typeof window.Framework === 'object' && window.Framework !== null && typeof window.Framework.prop === 'object' && window.Framework.prop !== null ) { window.Framework.prop.forceRefresh = true; } window.location.reload(); }; var escapeHtml = function(value) { value = String(value); if ( typeof StaticLib === 'object' && StaticLib !== null && typeof StaticLib.EscapeHtml === 'function' ) { return StaticLib.EscapeHtml(value); } return value .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); }; var getAppDetails = function() { try { if ( fromApp !== null && typeof fromApp === 'object' && fromApp.AppDetails && typeof fromApp.AppDetails.GetAppPath === 'function' ) { return fromApp.AppDetails.GetAppPath('/'); } } catch (ignored) { // Do not allow app detail lookup to break the error handler. } return ''; }; var canUseMsgBox = function() { return ( typeof window.Framework === 'object' && window.Framework !== null && typeof window.Framework.UI === 'object' && window.Framework.UI !== null && typeof window.Framework.UI.MsgBox === 'function' ); }; var frameworkIsSetup = function() { return ( typeof window.Framework === 'object' && window.Framework !== null && typeof window.Framework.V5 === 'object' && window.Framework.V5 !== null && window.Framework.V5.__setup === true && window.Framework.V5.Setup === true ); }; var removeExistingError = function(id) { var existing = document.getElementById(id); if ( existing !== null && existing.parentNode !== null ) { existing.parentNode.removeChild(existing); } }; var FullScreenElementOnTop = function(el, shouldWipeDom, pos) { if (shouldWipeDom !== true) shouldWipeDom = false; var hovered = jQuery(el)[0]; var body = window.document.body; if (!hovered || !body) return; if (shouldWipeDom === true) { while (body.firstChild) { body.removeChild(body.firstChild); } } body.appendChild(hovered); var myPos = { left: '0px', top: '0px', width: '100vw', height: '100vh' }; if (typeof pos === 'object' && pos !== null) { 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.style.position = 'fixed'; hovered.style.left = myPos.left; hovered.style.top = myPos.top; hovered.style.width = myPos.width; hovered.style.height = myPos.height; hovered.style.zIndex = '2147483647'; }; var createCloseableDialog = function(options) { removeExistingError(options.id); var dialog = jQuery( '
' ); dialog.html( '' + '

' + options.icon + escapeHtml(options.title) + '

' + '
' + options.message + '
' + options.details + '
' + ' ' + options.extraButtons + '
' ); dialog.find('.CloseBtn').on('click', function() { if (refreshTimer !== null) { window.clearTimeout(refreshTimer); refreshTimer = null; } dialog.remove(); }); return dialog; }; var stopFrameworkActivity = function() { if (wipeDom !== true) return; try { if ( typeof window.Framework === 'object' && window.Framework !== null && typeof window.Framework.V5 === 'object' && window.Framework.V5 !== null && typeof window.Framework.V5.SocketServer === 'function' ) { var socketServer = window.Framework.V5.SocketServer(); if ( socketServer && socketServer.IsConnected === true && typeof socketServer.Disconnect === 'function' ) { socketServer.Disconnect(); } } } catch (ignoredSocketError) { // The error handler must continue even if socket cleanup fails. } try { if ( window.Online === true && typeof window.Framework === 'object' && window.Framework !== null && typeof window.Framework.prop === 'object' && window.Framework.prop !== null ) { window.Framework.prop.screenLocked = true; } } catch (ignoredScreenLockError) { // Ignore cleanup errors. } try { if ( typeof window.Framework === 'object' && window.Framework !== null && window.Framework.polling === true && window.Framework.polling && typeof window.Framework.polling.pauseTime === 'function' ) { window.Framework.polling.pauseTime(); } } catch (ignoredPollingError) { // Ignore cleanup errors. } }; var isJavascriptError = e instanceof Error || e instanceof ReferenceError || e instanceof SyntaxError || e instanceof RangeError || e instanceof TypeError; /* * Handle JavaScript exceptions separately. */ if (isJavascriptError === true) { try { var errorType = e.constructor && e.constructor.name ? e.constructor.name : 'Error'; var errorMessage = typeof e.message === 'string' && e.message !== '' ? e.message : errorText; var stack = ''; if (typeof e.stack === 'string' && e.stack !== '') { stack = '
' +
						escapeHtml(e.stack) +
					'
'; } title = getAppDetails(); if (title === '') { title = 'Internal Error'; } var exceptionMessage = '' + '

' + escapeHtml(errorMessage) + '

' + stack; if (canUseMsgBox() && frameworkIsSetup()) { return window.Framework.UI.MsgBox({ title: errorType + ' - ' + title, message: exceptionMessage, height: 400, width: 600 }); } Container = createCloseableDialog({ id: 'ROMJavascriptError', className: 'ROMBlueScreen', title: errorType + ' - ' + title, icon: ' ', message: exceptionMessage, details: '', extraButtons: '' }); Container.find('.ReloadBtn').on('click', refreshCode2); FullScreenElementOnTop( Container, false, { height: '70vh', width: '70vw', top: '15vh', left: '15vw' } ); return; } catch (fatalErr) { fatalErrMessage = fatalErr && fatalErr.message ? fatalErr.message : String(fatalErr); fatalErrType = fatalErr && fatalErr.constructor && fatalErr.constructor.name ? fatalErr.constructor.name : 'Error'; status = 218; intmessage = messageList[218]; } } var safeErrorText = escapeHtml(errorText); var safeMessage = escapeHtml(intmessage); var message = '' + 'Connection Error: ' + safeMessage + '
' + 'status=' + status + '
' + 'errorText=' + safeErrorText + '
'; switch (status) { case 218: className = 'ROMBlueScreen'; appdetails = getAppDetails(); if (fatalErrType === '') { fatalErrType = 'Error'; } if (fatalErrMessage === '') { fatalErrMessage = 'The error handler encountered an additional error.'; } Container = createCloseableDialog({ id: className, className: className, title: fatalErrType + ' (' + status + '): ' + intmessage, icon: ' ', message: '

' + 'Whilst processing the original error, another error occurred.' + '

' + '

' + escapeHtml(fatalErrMessage) + '

', details: '
' + 'Original status: ' + escapeHtml(originalStatus) + '
' + 'Original error: ' + escapeHtml(errorText) + '
' + 'Caller app: ' + escapeHtml(appdetails || 'Unknown') + '
', extraButtons: '' }); Container.css({ background: 'blue', color: 'white', textAlign: 'center' }); Container.find('.ReloadBtn').on('click', refreshCode2); FullScreenElementOnTop( Container, false, { height: '50vh', width: '50vw', top: '25vh', left: '25vw' } ); return; case 511: window.location.href = '/cache/locked.html'; return; case 402: try { appdetails = getAppDetails(); 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; } catch (paymentError) { errorText = paymentError.message || String(paymentError); status = 500; intmessage = messageList[500]; } break; case 404: if (window.Online === false) { status = 0; intmessage = messageList[0]; errorText = 'The requested resource could not be loaded while offline.'; break; } title = 'The page is missing'; appdetails = getAppDetails(); try { if ( e !== null && typeof e === 'object' && e.ActionObj && e.ActionObj.caller && typeof AppStaticLib === 'object' && typeof AppStaticLib.IsAnApp === 'function' && 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; } } if ( e !== null && typeof e === 'object' && e.ActionObj && typeof e.ActionObj.LastCalledURL === 'string' ) { errorText = e.ActionObj.LastCalledURL; } } catch (ignored404Error) { // Continue showing the normal 404 message. } Container = createCloseableDialog({ id: 'ROMMissing', className: 'ROMMissing', title: '404 - ' + title, icon: ' ', message: '

' + escapeHtml(errorText) + '

' + ( appdetails !== '' ? '

' + escapeHtml(appdetails) + '

' : '' ), details: '', extraButtons: '' }); FullScreenElementOnTop( Container, false, { height: '50vh', width: '50vw', top: '25vh', left: '25vw' } ); return; case 416: title = intmessage; appdetails = getAppDetails(); Container = createCloseableDialog({ id: 'ROMRangeError', className: 'ROMMissing', title: '416 - ' + title, icon: ' ', message: '

' + escapeHtml(errorText) + '

' + ( appdetails !== '' ? '

' + escapeHtml(appdetails) + '

' : '' ), details: '', extraButtons: '' }); FullScreenElementOnTop( Container, false, { height: '50vh', width: '50vw', top: '25vh', left: '25vw' } ); return; case 417: Container = createCloseableDialog({ id: 'ROMClientFrameworkError', className: 'ROMBlueScreen', title: 'System Error: ' + intmessage, icon: ' ', message: '

' + escapeHtml(errorText) + '

', details: '', extraButtons: '' }); Container.css({ background: 'blue', color: 'white', textAlign: 'center' }); Container.find('.ReloadBtn').on('click', refreshCode2); FullScreenElementOnTop(Container, wipeDom); stopFrameworkActivity(); return; case 418: Container = createCloseableDialog({ id: 'ROMLoggedOut', className: 'ROMLoggedOut', title: intmessage, icon: ' ', message: '

' + escapeHtml(errorText) + '

', details: '', extraButtons: '' }); Container.css({ background: 'white', color: 'black', textAlign: 'center' }); if ( typeof StaticLib === 'object' && StaticLib !== null && typeof StaticLib.IsJSONString === 'function' && StaticLib.IsJSONString(errorText) === true ) { try { var loggedOutMessage = JSON.parse(errorText); Container.find('h1').text( loggedOutMessage.Title || intmessage ); Container.find('.ConnectionErrorMessage').html( '

' + escapeHtml( loggedOutMessage.Body || errorText ) + '

' ); } catch (ignoredJsonError) { // Use the original text if parsing fails. } } else { refreshTimer = window.setTimeout(refreshCode2, 3000); } Container.find('.ReloadBtn').on('click', refreshCode2); FullScreenElementOnTop(Container, wipeDom); if ( typeof window.Framework === 'object' && window.Framework !== null ) { window.Framework.teapot = true; } stopFrameworkActivity(); return; case 0: /* * FIX: * * The old function only used `break`, so nothing was ever * rendered for status 0. */ title = 'Connection Lost'; if ( errorText === '' || errorText === 'error' || errorText === 'abort' ) { errorText = 'The server could not be reached. Check your internet ' + 'connection and try again.'; } message = '

' + 'Internet connection lost.' + '

';// + //'

' + // escapeHtml(errorText) + //'

'; /* * Use the framework message box when it is available. */ if (canUseMsgBox() && frameworkIsSetup()) { return window.Framework.UI.MsgBox({ title: title, message: message, modal: false, width: 450, height: 240 }); } /* * Framework UI is not ready, so render a standalone message. */ Container = createCloseableDialog({ id: 'ROMConnectionLost', className: 'ROMConnectionLost', title: title, icon: ' ', message: message, details: '
' + 'Status: 0' + '
', extraButtons: '' }); Container.css({ background: '#ffffff', color: '#222222', textAlign: 'center', border: '1px solid #cccccc' }); Container.find('.RetryBtn').on('click', refreshCode2); FullScreenElementOnTop( Container, false, { height: '300px', width: '500px', top: 'calc(50vh - 150px)', left: 'calc(50vw - 250px)' } ); return; case 504: title = 'Server Timeout'; message = '

' + 'The server took too long to respond.' + '

' + '

' + escapeHtml(errorText) + '

'; if (canUseMsgBox() && frameworkIsSetup()) { return window.Framework.UI.MsgBox({ title: title, message: message, modal: false, width: 450, height: 240 }); } Container = createCloseableDialog({ id: 'ROMGatewayTimeout', className: 'ROMGatewayTimeout', title: title, icon: ' ', message: message, details: '
' + 'Status: 504' + '
', extraButtons: '' }); Container.find('.RetryBtn').on('click', refreshCode2); FullScreenElementOnTop( Container, false, { height: '300px', width: '500px', top: 'calc(50vh - 150px)', left: 'calc(50vw - 250px)' } ); return; case 500: default: message = '' + 'Connection Error: ' + escapeHtml(intmessage) + '
' + 'status=' + escapeHtml(status) + '
' + 'errorText=' + escapeHtml(errorText) + '
'; if (canUseMsgBox() && frameworkIsSetup()) { return window.Framework.UI.MsgBox({ title: 'Developer Error A48', message: message }); } Container = createCloseableDialog({ id: 'ROMBlueScreen', className: 'ROMBlueScreen', title: 'Connection Error: ' + intmessage, icon: ' ', message: '

' + escapeHtml(errorText) + '

', details: '
' + 'Status: ' + escapeHtml(status) + '
', extraButtons: '' }); Container.css({ background: 'blue', color: 'white', textAlign: 'center' }); Container.find('.ReloadBtn').on('click', refreshCode2); FullScreenElementOnTop(Container, wipeDom); stopFrameworkActivity(); return; } /* * This is reached when another status was converted into a 500. */ if (status === 500) { return window.__handleConnectionError( e, 500, errorText, true, wipeDom, fromApp ); } stopFrameworkActivity(); }; 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) { } 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); } 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);