'use strict'; /* jshint undef: true, unused: false, strict: true, curly: false, funcscope: true, globalstrict: true, proto: true, shadow: false, quotmark: single, eqnull: true, eqeqeq: true */ /* global __METHOD__, AppBase, WindowLib, setTimeout, AppStaticLib, window, console, document, navigator, jQuery, unescape, alert, Element, __LINE__ */ /*AppStaticLib START*/ if (typeof(String.getHash) === 'undefined') { Object.defineProperty(String.prototype, 'hashCode', { value: function() { return this.split('').reduce(function(a,b) { a=((a<<5)-a)+b.charCodeAt(0); return a&a; }, 0); } }); } if (!Number.isInteger) { Number.isInteger = function(value) { return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; }; } // Production steps of ECMA-262, Edition 6, 22.1.2.1 if (!Array.from) { Array.from = (function () { var symbolIterator; try { symbolIterator = window.Symbol.iterator ? window.Symbol.iterator : 'Symbol(Symbol.iterator)'; } catch (e) { symbolIterator = 'Symbol(Symbol.iterator)'; } var toStr = Object.prototype.toString; var isCallable = function (fn) { return ( typeof fn === 'function' || toStr.call(fn) === '[object Function]' ); }; var toInteger = function (value) { var number = Number(value); if (isNaN(number)) return 0; if (number === 0 || !isFinite(number)) return number; return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); }; var maxSafeInteger = Math.pow(2, 53) - 1; var toLength = function (value) { var len = toInteger(value); return Math.min(Math.max(len, 0), maxSafeInteger); }; var setGetItemHandler = function setGetItemHandler(isIterator, items) { var iterator = isIterator && items[symbolIterator](); return function getItem(k) { return isIterator ? iterator.next() : items[k]; }; }; var getArray = function getArray( T, A, len, getItem, isIterator, mapFn ) { // 16. Let k be 0. var k = 0; // 17. Repeat, while k < len… or while iterator is done (also steps a - h) while (k < len || isIterator) { var item = getItem(k); var kValue = isIterator ? item.value : item; if (isIterator && item.done) { return A; } else { if (mapFn) { A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k); } else { A[k] = kValue; } } k += 1; } if (isIterator) { throw new TypeError( 'Array.from: provided arrayLike or iterator has length more then 2 ** 52 - 1' ); } else { A.length = len; } return A; }; // The length property of the from method is 1. return function from(arrayLikeOrIterator /*, mapFn, thisArg */) { // 1. Let C be the this value. var C = this; // 2. Let items be ToObject(arrayLikeOrIterator). var items = Object(arrayLikeOrIterator); var isIterator = isCallable(items[symbolIterator]); // 3. ReturnIfAbrupt(items). if (arrayLikeOrIterator == null && !isIterator) { throw new TypeError( 'Array.from requires an array-like object or iterator - not null or undefined' ); } // 4. If mapfn is undefined, then let mapping be false. var mapFn = arguments.length > 1 ? arguments[1] : void undefined; var T; if (typeof mapFn !== 'undefined') { // 5. else // 5. a If IsCallable(mapfn) is false, throw a TypeError exception. if (!isCallable(mapFn)) { throw new TypeError( 'Array.from: when provided, the second argument must be a function' ); } // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined. if (arguments.length > 2) { T = arguments[2]; } } // 10. Let lenValue be Get(items, "length"). // 11. Let len be ToLength(lenValue). var len = toLength(items.length); // 13. If IsConstructor(C) is true, then // 13. a. Let A be the result of calling the [[Construct]] internal method // of C with an argument list containing the single item len. // 14. a. Else, Let A be ArrayCreate(len). var A = isCallable(C) ? Object(new C(len)) : new Array(len); return getArray( T, A, len, setGetItemHandler(isIterator, items), isIterator, mapFn ); }; })(); } /* developer code start */ window.opencount = 0; /* developer code end */ window.emulationMode = 0; if (true) { window.AppStaticLib = { StrictifyAppCode: function(code, url, controls) { var whereToStore = function() { var App=1; window.Framework.prop.ClassCollection[1] = App; }; var stringLocation = whereToStore.toString(); var insertIndex = stringLocation.indexOf('=1;') + 3; stringLocation = stringLocation.substring(0, (stringLocation.length - 1)); stringLocation = stringLocation.substring(insertIndex); insertIndex = (stringLocation.indexOf('[1]') + 1); var finalResult = stringLocation.substring(0, insertIndex) + '\'' + url + '\'' + stringLocation.substring(insertIndex + 1); var othercontrols = ''; if (Array.isArray(controls) === true) { var name = ''; var enddot = -1; var endslash = -1; var bit = null; for (var i = 0; i < controls.length; i++) { name = controls[i]; enddot = -1; endslash = -1; bit = null; //var str = 'platform/system/js/calculator.js'; for (var j = (name.length - 1); j >= 0; j--) { bit = name[j]; if ((bit === '.')){// && (enddot === -1)) { enddot = j; continue; } if ((bit === '/') && (endslash === -1)) { endslash = j; break; } } name = name.substr((endslash + 1), (enddot - endslash - 1)); assertgroup('appbubble', 'This is where we should fill the local variables from hidden global memory pool'); //othercontrols += 'var ' + name + ';\n'; } } return '\'use strict\';\n' + othercontrols + code + finalResult; }, //Private - Passed a Row-record and a Display-key-string, it uses the string to figure out how you want the row displayed to the user, filling that skeleton with actual data _DisplayRecord: function(record, display) { if ((typeof(record) === 'undefined') || (record === null)) return; if (typeof(record) !== 'object') return record; if (window.Framework.prop.developer) { console.log(record); } var currentString = display; var returnString = ''; //var closeIndex = -1; var start = display.indexOf('{'); //var index = 0; var value = ''; var end = null; var colName = null; //If it's just a string, assume it refers to a single column if (start === -1) { //So wrap it the way column names normally are currentString = '{' + display + '}'; start = 0; } while (start > -1) { //Get everything from the start to the first tag (ignoring the tag's contents) returnString += currentString.substr(0, start); end = currentString.indexOf('}'); //get colName (the tag's content is the Column name) colName = currentString.substr((start + 1), (end - start - 1)); //Strip out the part we have processed so far currentString = currentString.substr((end + 1)); value = record[colName]; if ((typeof(value) === 'undefined') || (value === null)) { value = ''; } //Add the value of the Column returnString += value; //Then check if there are remaining column-names to replace start = currentString.indexOf('{'); } //Recombine the processed part and the remainder, then return it return returnString + currentString; }, clone: function(item) { if (!item) { return item; } // null, undefined values check var types = [ Number, String, Boolean ]; var result; // normalizing primitives if someone did new String('aaa'), or new Number('444'); types.forEach(function(type) { if (typeof(type) === 'undefined') throw new Error(__METHOD__ + ' reports that the type was not found on line ' + __LINE__); if (item instanceof type) { result = type( item ); } }); if (typeof(result) === 'undefined') { if (Object.prototype.toString.call(item) === '[object Array]') { result = []; item.forEach(function(child, index) { result[index] = AppStaticLib.clone(child); }); } else if (typeof(item) === 'object') { if (AppStaticLib.IsAnApp(item) ) { return item; } else if ((item.nodeType) && (typeof(item.cloneNode) === 'function')) { // testing that this is DOM result = item.cloneNode( true ); } else if (!item.prototype) { // check that this is a literal if (item instanceof Date) { result = new Date(item); } else { // it is an object literal result = {}; for (var i in item) { result[i] = AppStaticLib.clone(item[i]); } } } else { // depending what you would like here, // just keep the reference, or create new object if (item.constructor) { // would not advice to do that, reason? Read below result = new item.constructor(); } else { result = item; } } } else { result = item; } } return result; }, Hyphenate: function(str, len) { var res = ''; for (var i = 0; i < str.length; i += len) { if (res !== '') res += '-'; res += str.substr(i, len); } return res; }, IsFileCall: function(str) { var type = typeof(str); if (str === null) return false; if (type === 'string') { var parts = str.split('\''); if (parts.length < 3) return false; if (parts[0] !== Object.keys({url:0})[0] + ':(' ) return false; if (parts[parts.length - 1] !== ');' ) return false; return true; } else if (type === 'object') { if (typeof(str.url) === 'string') return true; return false; } return false; }, IsAppCall: function(str) { var type = typeof(str); if (str === null) return false; if (type === 'string') { var parts = str.split('(')[0]; if (parts !== (Object.keys({app:0}) + ':')) { return false; } return true; } else if (type === 'object') { if (typeof(str.app) === 'object') return true; return false; } return false; }, ExplodeAppCall: function(str) { //if (StaticLib.Empty(str) && typeof(str) === 'object') return; var type = typeof(str); if (str === null) return; if (type === 'string') { var raw_api = str.split('app:(')[1]; var api = '{' +raw_api.split(');')[0]+ '}'; try { return JSON.parse(api); } catch(e) { throw new Error('Can\'t Explode App Call API because incorrect Syntax of JSON String. Example use \' instead of \' '); } } else if (type === 'object') { if ((typeof(str.app) === 'object') && (str.app !== null)) return str.app; return; } return; }, ExplodeUrl: function(str) { var type = typeof(str); if (str === null) return null; if (type === 'string') { var parts = str.split('\''); if (!AppStaticLib.IsFileCall(str)) return null; var newStr = ''; for (var i = 1; i < (parts.length - 1); i++) { if (newStr !== '') newStr += '\''; newStr += parts[i]; } return newStr; } else if (type === 'object') { if (typeof(str.url) === 'string') return str.url; return null; } return null; }, Layer5: function(encode, searchText) { var openTagText = ''; var optionalTagText = '\' title=\''; var closeTagText = ''; //Argument(encode) is expected in order to inform behaviour, and is therefore required if (typeof(encode) !== 'boolean') throw new Error('AppStaticLib.Layer5: Argument 1 is expected to be a boolean (used to determine logic, whether to encode/decode the searchText [Arg 2])'); // if (StaticLib.Empty(searchText)) return searchText; if (typeof(searchText) !== 'string') throw new Error('AppStaticLib.Layer5: Argument 2 is expected to be a String variable, with a value we will encode/decode based on the boolean 1st argument)'); if (encode) { return AppStaticLib._DoLayer5(searchText, openTagText, openTagText2, openTagText3, closeTagText, optionalTagText); } else { return AppStaticLib._UndoLayer5(searchText, openTagText, openTagText2, openTagText3, closeTagText); } }, _UndoLayer5: function(searchText, openTagText, openTagText2, openTagText3, closeTagText) { var start = -1; var before = ''; var after = ''; var end = -1; //find the openTag start = searchText.search(openTagText); while (start > -1) { end = (start + openTagText.length); before = searchText.substr(0, start); after = searchText.substr(end); searchText = before+after; //find the closeTag start = searchText.indexOf(closeTagText); if (start > -1) { end = (start + closeTagText.length); before = searchText.substr(0, start); after = searchText.substr(end); searchText = before+after; } start = searchText.search(openTagText); } //alert(searchText); return searchText; }, _DoLayer5: function(searchText, openTagText, openTagText2, openTagText3, closeTagText, optionalTagText) { var emailPattern = /([\s'']|^)[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?(?=[.,\s''<]|$)/i; var emailPattern2 = /(?:[\s'']|^)(["]?[^&]+(?:(?:<(' ')?)|("\s)))([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?(?:>)?)(?=[.,\s''<]|$)/i; var start = -1; var before = ''; var after = ''; var end = -1; var count = 0; var currentEmail = ''; var untrimmedEmail = ''; var newText = ''; var modifier = 0; //find the openTag start = searchText.search(emailPattern); while (start > -1) { start++; untrimmedEmail = emailPattern.exec(searchText)[0];//.toString(); currentEmail = jQuery.trim(untrimmedEmail);//currentEmail.substr(1, currentEmail.length-2); end = (start + currentEmail.length); modifier = 0; if (currentEmail.length === untrimmedEmail.length) { modifier = -1; } before = searchText.substr(0, (start + modifier)); after = searchText.substr(end); //newText = newText + before+openTagText+currentEmail+closeTagText; newText = newText + before+openTagText+currentEmail+openTagText2+openTagText3+currentEmail+closeTagText; searchText = after; start = searchText.search(emailPattern); count++; } start = searchText.search(emailPattern2); searchText = newText+searchText; if (start > -1) { start = searchText.search(emailPattern2); while (start > -1) { untrimmedEmail = emailPattern2.exec(searchText)[0];//.toString(); currentEmail = jQuery.trim(untrimmedEmail);//"ludespatch@crossdocks.com.au" <ludespatch@crossdocks.com.au> end = (start + currentEmail.length); currentEmail= currentEmail.split(/(?:(?:<)|(?:"\s))/i); var emailAddress = currentEmail[1]; emailAddress = emailAddress.replace('<', ''); emailAddress = emailAddress.replace('>', ''); var emailContactName = currentEmail[0]; emailContactName = emailContactName.replace(/"/g, ''); modifier = 0; if (currentEmail.length === untrimmedEmail.length) { modifier = -1; } before = searchText.substr(0, (start + modifier)); after = searchText.substr(end); //newText = newText + before+openTagText+currentEmail+closeTagText; newText = newText + before+openTagText+emailAddress+openTagText2+optionalTagText+emailAddress+openTagText3+emailContactName+closeTagText; searchText = after; start = searchText.search(emailPattern2); count++; } searchText = newText+searchText; } return searchText; }, //! IsAnApp taking one argument and returns a boolean about whether the argument is an App. /*! \param dom element or jquery selected element (example this, jQuery('#thisId')). \return boolean */ IsAnApp: function(suspect) { if (typeof(AppBase) === 'undefined') return false; if (suspect instanceof(AppBase)) return true; if (suspect === null) return false; if (typeof suspect !== 'object') return false; if (typeof suspect.OnLoad !== 'function') return false; if (typeof suspect.FormObjects !== 'object') return false; if (typeof suspect.BindFormObjects !== 'function') return false; //suspect has been interrogated and SEEMS to probably be an App... return true; }, IsControl: function(suspect) { if (suspect === null) return false; if (typeof(suspect)!== 'object') return false; if (typeof(window.Framework) !== 'object') return false; if (typeof(window.FrameworkControls) !== 'object') return false; if (typeof(window.Framework.Controls.AppButtonControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.AppButtonControl)) return true; } if (typeof(window.Framework.Controls.AvailableSearch) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.AvailableSearch)) return true; } if (typeof(window.Framework.Controls.DateControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.DateControl)) return true; } if (typeof(window.Framework.Controls.EmailSelectControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.EmailSelectControl)) return true; } if (typeof(window.Framework.Controls.FileSystem) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.FileSystem)) return true; } if (typeof(window.Framework.Controls.FileUploadControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.FileUploadControl)) return true; } if (typeof(window.Framwork.Controls.GridControl) !== 'undefined') { if (suspect instanceof(window.Framwork.Controls.GridControl)) return true; } if (typeof(window.Framework.Controls.HTMLControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.HTMLControl)) return true; } if (typeof(IFrameControl) !== 'undefined') { //if (suspect instanceof(IFrameControl)) return true; throw new Error(__METHOD__ + ' reports that the IFrameControl can no longer be tested this way on line ' + __LINE__); } if (typeof(window.Framework.Controls.InvoiceEngine) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.InvoiceEngine)) return true; } if (typeof(window.Framework.Controls.SelectBoxControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.SelectBoxControl)) return true; } if (typeof(window.Framework.Controls.SelectBoxButtonControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.SelectBoxButtonControl)) return true; } if (typeof(window.Framework.Controls.ServletTreeView) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.ServletTreeView)) return true; } if (typeof(window.Framework.Controls.SmartGrid) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.SmartGrid)) return true; } if (typeof(window.Framework.Controls.SuggestiveSearchControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.SuggestiveSearchControl)) return true; } if (typeof(window.Framework.Controls.TabControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.TabControl)) return true; } /*if (typeof(TaskManagerControl) !== 'undefined') { if (suspect instanceof(TaskManagerControl)) return true; } if (typeof(TreeView) !== 'undefined') { if (suspect instanceof(TreeView)) return true; } if (typeof(Wsywig) !== 'undefined') { if (suspect instanceof(Wsywig)) return true; }*/ if (typeof(window.Framework.Controls.EmailControl) !== 'undefined') { if (suspect instanceof(window.Framework.Controls.EmailControl)) return true; } //suspect has been interrogated and doesn't SEEM to match current controls... return false; }, GetGridFromElement: function(element) { var isAGrid = function(subject) { if (typeof(subject) !== 'object') return false; if (typeof(subject.GetControlName) !== 'function') return false; return (subject.GetControlName() === 'GridControl'); }; if ((element === null) || (typeof(element) !== 'object')) throw new Error('AppStaticLib can\'t GetGridFromElement from a non-object'); //if (element instanceof GridControl) return element; if (isAGrid(element)) return element; if ((typeof(element.grid) !== 'undefined') && (isAGrid(element.grid))) return element.grid; if (typeof(element.StoredParent) !== 'undefined') element = element.StoredParent; var parentApp = AppStaticLib.GetThisApp(element); return parentApp._controls.Grids[jQuery(element).parents('.gridContainer').attr('id')]; }, GetThisAppAndIgnoreTheseThings: function(element) { var IgnoreIDs = ['selenium-ide-indicator', 'ROMMissing', 'LoadingScreen', 'ID', 'ROMDebugInfo', 'ClassName', 'LoadingScreen', 'desktop', 'hovered', 'dialog-extend-fixed-container', 'themeSelector', 'ROMBuild']; var IgnoreClasses = ['ClassName', 'ROMDebugInfo', 'ROMBlueScreen', 'cke', 'cke_panel_frame', 'CodeMirror-lint-tooltip', 'CodeMirror-hint', 'CodeMirror-hints', 'CodeMirror-lint-message-error', 'CodeMirror-lint-message-warning', 'ui-front', 'h1', 'notification', 'ui-widget-overlay']; var IgnoreMe = false; var count = 0; for (count = 0; ((count < IgnoreClasses.length) && (IgnoreMe === false)); count++) { if (jQuery(element).hasClass(IgnoreClasses[count])) { IgnoreMe = true; break; } } if (IgnoreMe !== true) { for (count = 0; ((count < IgnoreIDs.length) && (IgnoreMe === false)); count++) { if ((jQuery(element)[0].id === IgnoreIDs[count]) || (jQuery(element).parents('#' + IgnoreIDs[count]).length >= 1)) { IgnoreMe = true; break; } } } var parent = null; if (IgnoreMe !== true) { try { parent = AppStaticLib.GetThisAppOf(element); } catch (err) { parent = null; } } return parent; }, //! GetThisApp taking one argument and returns an object, either the argument itself if it is an App, or the App instance associated with it otherwise. /*! \param dom element or jquery selected element (example this, jQuery('#thisId')). \return App WindowStruct as an object */ GetThisApp: function(element) { //On the off chance the context is the Window... if (this.App) { if (AppStaticLib.IsAnApp(this.App)) return this.App; } //On the off chance we are already in context, check if (AppStaticLib.IsAnApp(element)) return element; //Otherwise find the App based on the element return AppStaticLib.GetThisAppOf(element); }, //! GetStructOf taking one argument and returns the App WindowStruct associated with that argument as an object. /*! \param dom element or jquery selected element (example this, jQuery('#thisId')). \return App WindowStruct as an object \sa Uses GetCollectionOf() to get all objects associated with that element, then returns just the WindowStruct */ GetStructOf: function(element) { //For the item we are sent, find the collection that includes the App instance var collection = AppStaticLib.GetCollectionOf(element); //If found... if (typeof collection === 'undefined') return null; //return the App instance return collection.struct; }, //! GetThisAppOf taking one argument and returns the App instance associated with that argument as an object. /*! \param dom element or jquery selected element (example this, jQuery('#thisId')). \return App WindowStruct as an object */ GetThisAppOf: function(element) { if (typeof(jQuery(element)[0]) === 'undefined') throw new Error('Invalid element'); if ((element.length === 0) || (typeof(jQuery(element)[0]) === 'undefined')) return null; if (jQuery(element)[0].tagName === 'BODY') return null; if ((element.type) && (element.target)) { element = element.target; } //For the item we are sent, find the collection that includes the App instance var collection = AppStaticLib.GetCollectionOf(element); //If found... if ((typeof(collection) === 'undefined') || (collection === null)) return null; //return the App instance return collection.instance; }, //! GetCollectionOf taking one argument and returns an object containing references (App instance, WindowStruct, Window id) associated with that argument. /*! \param dom element or jquery selected element (example this, jQuery('#thisId')). \return App WindowStruct as an object */ GetWindowOf: function(element) { var elementsWindow = ''; if ((typeof(element.length) === 'number') && (element.length > 0) && (typeof(element[0].nodeName) === 'string') && (typeof(element[0].nodeType) === 'number')) element = element[0]; if ((typeof(element.AppDetails) !== 'object') && (document.body.contains(jQuery(element)[0]) !== true)) { if (document.body.contains(jQuery(element)[0].StoredParent)) { element = element.StoredParent; } else { return null; } } if (element.parentElement === null) { return null; } if ( ((typeof(element.parentElement) !== 'undefined') && (element.parentElement !== null)) && ((element.id === 'AppTopMenu') || (element.id === 'AppBottomMenu') || (element.id === 'AppLeftMenu') || (element.id === 'AppRightMenu') || (element.parentElement.id === 'AppTopMenu') || (element.parentElement.parentElement.id === 'AppTopMenu') || (jQuery(element.parentElement).hasClass('ui-dialog')) || ((element.parentElement.id === 'AppBottomMenu') || (element.parentElement.parentElement.id === 'AppBottomMenu')) || ((element.parentElement.id === 'AppLeftMenu') || (element.parentElement.parentElement.id === 'AppLeftMenu')) || ((element.parentElement.id === 'AppRightMenu') || (element.parentElement.parentElement.id === 'AppRightMenu')) || /*(jQuery(element.parentElement).hasClass('ui-dialog-titlebar')) || (jQuery(element).hasClass('ui-dialog-titlebar')) || ((element.parentElement.parentElement !== null) && (jQuery(element.parentElement.parentElement).hasClass('ui-dialog-titlebar'))) || */ (jQuery(element).parents('.ui-dialog-titlebar').length === 1) || (jQuery(element).parents('.WindowPosition').length) || (jQuery(element).parents('#AppTopMenu').length) || (jQuery(element).parents('#AppBottomMenu').length) || (jQuery(element).parents('#AppLeftMenu').length) || (jQuery(element).parents('#AppRightMenu').length)) ) { var container = AppStaticLib.GetContainerOf(element); if (container.hasClass('containedapp')) return container; elementsWindow = container.children('.ui-dialog-content'); if (elementsWindow.length === 0) { elementsWindow = container.children('.ui-dialog-inner').children('[instance]'); } } else { if ((jQuery(element).hasClass('ui-dialog-maximized')) || (jQuery(element).hasClass('ui-dialog-normal')) || (jQuery(element).hasClass('containedapp'))) { elementsWindow = jQuery(element); } else { if (AppStaticLib.IsAnApp(element)) { //elementsWindow = jQuery(element.prop.handle); elementsWindow = jQuery(element.prop.popup); } else { if (jQuery(element).hasClass('ui-dialog')) { elementsWindow = jQuery(element).children('[instance]'); if (elementsWindow.length === 0) { elementsWindow = jQuery(element).children('.ui-dialog-inner').children('[instance]'); } } else { elementsWindow = jQuery(element).parents('.containedapp'); if (elementsWindow.length === 0) { elementsWindow = jQuery(element).parents('[instance]'); if (elementsWindow.length === 0) { elementsWindow = jQuery(element).children('.ui-dialog-inner').children('[instance]'); } } } } } } //Check that JQuery found atleast one object if (elementsWindow.length === 0) { if (StaticLib.Empty(element.id) === true) return null; /* jshint debug: true */debugger; /* developer code start */ var error = 'Developer Error A1: The argument provided is not associated with any App. for element ID [' + element.id + '] InnerText: [' + element.innerText + ']'; if (window.Framework.prop.developer) { debugger; window.Framework.UI.MsgBox({title:'Developer Notification', message: error, modal: true, width: 400, height: 300}); } /* developer code end */ return null; } return elementsWindow; }, GetContainerOf: function(element) { if ((element === null) || (typeof(element) === 'undefined')) return null; var elementsWindow = ''; if ((jQuery(element).hasClass('ui-dialog')) || (jQuery(element).hasClass('containedapp'))) { elementsWindow = jQuery(element); return (elementsWindow.length === 0) ? null : elementsWindow; } if (element !== jQuery(element)[0]) element = element[0]; if (AppStaticLib.IsAnApp(element)) { if (element.prop === null) return null; if (element.prop.handle === null) return null; elementsWindow = jQuery(element.prop.handle).parents('.ui-dialog'); return (elementsWindow.length === 0) ? null : elementsWindow; } //} else { elementsWindow = jQuery(element).parents('.ui-dialog'); if (elementsWindow.length === 0) { elementsWindow = jQuery(element).parents('.containedapp'); } var temp = null; if (elementsWindow.length === 0) { temp = jQuery(element)[0]; if (temp === null) { /* jshint debug: true */debugger; // we lost our app context? return null; } //if (jQuery(element)[0].id === 'AppTopMenu') elementsWindow = jQuery(element); //else elementsWindow = jQuery(element).parents('#AppTopMenu'); if (typeof(temp) === 'undefined') return null; if (temp.id === 'AppTopMenu') elementsWindow = temp; else elementsWindow = jQuery(temp).parents('#AppTopMenu'); if (elementsWindow.length !== 0) { //elementsWindow = jQuery(element).parents('#AppTopMenu').parent().children('.ui-dialog'); if (jQuery(element)[0].id === 'AppTopMenu') elementsWindow = jQuery(element); else elementsWindow = jQuery(element).parents('#AppTopMenu'); temp = elementsWindow.parent().children('.ui-dialog'); if (temp.length === 0) elementsWindow = elementsWindow.parent().children('.AppContainer').children('.containedapp'); else elementsWindow = temp; return (elementsWindow.length === 0) ? null : elementsWindow; } elementsWindow = jQuery(element).parents('#AppLeftMenu'); if (elementsWindow.length !== 0) { //elementsWindow = jQuery(element).parents('#AppLeftMenu').parent().children('.ui-dialog'); if (jQuery(element)[0].id === 'AppLeftMenu') elementsWindow = jQuery(element); else elementsWindow = jQuery(element).parents('#AppLeftMenu'); temp = elementsWindow.parent().children('.ui-dialog'); if (temp.length === 0) elementsWindow = elementsWindow.parent().parent().children('.containedapp'); else elementsWindow = temp; } if (elementsWindow.length === 0) { elementsWindow = jQuery(element).parents('#AppRightMenu'); if (elementsWindow.length !== 0) { //elementsWindow = jQuery(element).parents('#AppRightMenu').parent().children('.ui-dialog'); if (jQuery(element)[0].id === 'AppRightMenu') elementsWindow = jQuery(element); else elementsWindow = jQuery(element).parents('#AppRightMenu'); temp = elementsWindow.parent().parent().children('.ui-dialog'); if (temp.length === 0) elementsWindow = elementsWindow.parent().parent().children('.containedapp'); else elementsWindow = temp; } } if (elementsWindow.length === 0) { elementsWindow = jQuery(element).parents('#AppBottomMenu'); if (elementsWindow.length !== 0) { //elementsWindow = jQuery(element).parents('#AppBottomMenu').parent().children('.ui-dialog'); if (jQuery(element)[0].id === 'AppBottomMenu') elementsWindow = jQuery(element); else elementsWindow = jQuery(element).parents('#AppBottomMenu'); temp = elementsWindow.parent().children('.ui-dialog'); if (temp.length === 0) elementsWindow = elementsWindow.parent().children('.AppContainer').children('.containedapp'); else elementsWindow = temp; } } } return (elementsWindow.length === 0) ? null : elementsWindow; }, GetOuterWindowOf: function(element, getOutermost) { if (typeof(element) === 'undefined') { /* jshint debug: true */debugger; throw new Error(__METHOD__ + ' reports that the element is undefined on line ' + __LINE__); } if (window.Framework.prop.developer) console.log('' + __METHOD__); if (getOutermost !== true) getOutermost = false; var elementsWindow = ''; if (jQuery(element).hasClass('ui-dialog-titlebar-close')) { var container = WindowLib.GetContainerOf(element); elementsWindow = container.children('.ui-dialog-content'); } else{ if (jQuery(element).hasClass('ui-dialog-content')) { elementsWindow = jQuery(element); } else { if (AppStaticLib.IsAnApp(element)) { elementsWindow = jQuery(element.prop.handle); } else { elementsWindow = jQuery(element).parents('.containedapp'); if (elementsWindow.length === 0) elementsWindow = jQuery(element).parents('.ui-dialog-content'); if (getOutermost === true) { var depth = 0; var temp = jQuery(elementsWindow); while ((temp.length !== 0) && (depth < 15)) { depth++; temp = jQuery(elementsWindow).parents('.containedapp'); if (temp.length !== 0) elementsWindow = temp; } elementsWindow = elementsWindow.parents('.ui-dialog-content'); } } } } //Check that JQuery found atleast one object if (elementsWindow.length === 0) { if (window.Framework.prop.developer) { console.log('---WARNING: COULDN\'T FIND CONTEXT, RETURNING DOCUMENT--- for ' + element[0].id); } return jQuery('html'); } return elementsWindow; }, GetCollectionOf: function(element) { if (element.App) { if (AppStaticLib.IsAnApp(element.App)) element = element.App; } //For the item we are sent, find the object that contains it with a dialog window class... var elementsWindow = AppStaticLib.GetWindowOf(element); //Check that JQuery found atleast one object if (elementsWindow === null) { return null; } if ((elementsWindow.length === null) || (elementsWindow.length === 0)) return null; //from that dialog's ID, then use that to look up the list of stored instances for that window return window.Framework.prop.WindowCollection.items[elementsWindow.attr('id')]; }, SetupWhenReady: function(test, callThis, checkEvery) { var obj = { 'test':test, 'callThis':callThis, 'checkEvery': checkEvery, 'CheckIsReady': function() { if (this.test() === true) { this.callThis(); } else { setTimeout(jQuery.proxy(this.CheckIsReady, this), (this.checkEvery * 1000) ); } } }; obj.CheckIsReady(); } }; } /*AppStaticLib END */ var __EventRegister = []; function HasEvent(target, name, func) { var e = null; for (var i = 0; i < __EventRegister.length; i++) { e = __EventRegister[i]; if ((target.id === e.target.id) && (e.name === name) && (e.func === func)) return true; } return false; } function AddEvent(target, name, func, optionalArg, strict) { var expected = __METHOD__ + ' expects a HTML object, name of event and the function to call'; if (typeof(target) !== 'object') throw new Error(expected); if ((typeof(name) !== 'string') || (name.length === 0)) throw new Error(expected); if (typeof(func) !== 'function') throw new Error(expected); if (typeof(strict) !== 'boolean') strict = true; var e = null; for (var i = 0; i < __EventRegister.length; i++) { e = __EventRegister[i]; if ((target.id === e.target.id) && (e.name === name) && (e.func === func)) { if (strict === true) throw new Error(__METHOD__ + ' reports that the specified event [' + name + '] has already been registered for target [' + target.id + ']'); return; } } if ((typeof(optionalArg) !== 'undefined') && (optionalArg !== null)) { target.addEventListener(name, func, optionalArg); } else { target.addEventListener(name, func); } __EventRegister.push({target: target, name: name, func: func}); } function RemoveEvent(target, name, func) { var expected = __METHOD__ + ' expects a HTML object, name of event and the function to call'; if (typeof(target) !== 'object') throw new Error(expected); if ((typeof(name) !== 'string') || (name.length === 0)) throw new Error(expected); if (typeof(func) !== 'function') throw new Error(expected); var e = null; for (var i = 0; i < __EventRegister.length; i++) { e = __EventRegister[i]; if (!((target.id === e.target.id) && (e.name === name) && (e.func === func))) continue; target.removeEventListener(name, func); __EventRegister.splice(i, 1); return; } throw new Error(__METHOD__ + ' reports that the specified event [' + name + '] was not found for element [' + target.id + ']'); } /* developer code start */ (function() { Element.prototype._addEventListener = Element.prototype.addEventListener; Element.prototype.addEventListener = function(a,b,c) { if (c === undefined) c = false; this._addEventListener(a, b, c); if (!this.eventListenerList) this.eventListenerList = {}; if (!this.eventListenerList[a]) this.eventListenerList[a] = []; //this.removeEventListener(a,b,c); // TODO - handle duplicates.. this.eventListenerList[a].push({listener:b,useCapture:c}); }; Element.prototype.getEventListeners = function(a){ if (!this.eventListenerList) this.eventListenerList = {}; if (a === undefined) return this.eventListenerList; return this.eventListenerList[a]; }; Element.prototype.clearEventListeners = function(a){ if (!this.eventListenerList) this.eventListenerList = {}; if (a === undefined){ for(var x in (this.getEventListeners())) this.clearEventListeners(x); return; } var el = this.getEventListeners(a); if (el === undefined) return; for(var i = el.length - 1; i >= 0; --i) { var ev = el[i]; this.removeEventListener(a, ev.listener, ev.useCapture); } }; Element.prototype._removeEventListener = Element.prototype.removeEventListener; Element.prototype.removeEventListener = function(a,b,c) { if (c === undefined) c=false; this._removeEventListener(a,b,c); if (!this.eventListenerList) this.eventListenerList = {}; if (!this.eventListenerList[a]) this.eventListenerList[a] = []; // Find the event in the list for(var i=0;i.toString (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:188:10)" 5: " at window.AppBase.eval (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13), :751:54)" 6: " at window.AppBase.proxy [as OpenAppErrorWindow] (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13)" 7: " at window.AppBase.eval (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13), :732:10)" 8: " at App.proxy [as AddAppError] (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13)" 9: " at Object.processOne (https://bluesafe.mobylink.com/core/framework/js/WndPrcHandler.class.js:419:18)" 10: " at Object.process (https://bluesafe.mobylink.com/core/framework/js/WndPrcHandler.class.js:629:20)" */ // 1: 10: process -> 9: processOne -> 8: App.proxy(AddAppError) -> 7: window.AppBase.eval -> 6: window.AppBase.proxy(OpenAppErrorWindow) // 8 = Caller Function = re = /\s+at\sApp\.proxy\s\[as\s(\w+)\].*/g; // 7 = Line Number = re = /\s+at\swindow.AppBase\.eval\s.*:([0-9]+):[0-9]+$/g; // 6 = Error Function = re = /\s+at\swindow.AppBase\.proxy\s\[as (\w+)\].*$/; /* 0: "Error" 1: " at Object._GetFunctionDetails [as func] (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:86:10)" 2: " at Object.jQuery.proxy.func (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:229:15)" 3: " at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13)" 4: " at Object.window..toString (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:239:10)" 5: " at AddEvent (https://bluesafe.mobylink.com/core/framework/js/windowpopup.js:37:29)" 6: " at new window.WindowPopup (https://bluesafe.mobylink.com/core/framework/js/windowpopup.js:452:3)" 7: " at Object._CreateWindow (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13), :2696:16)" 8: " at GetApp.invoke (https://bluesafe.mobylink.com/core/framework/js/Action.class.js:364:17)" 9: " at App.Callback_GridSelect (eval at (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13)), :287:10)" 10: " at Object.eval (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13), :1400:19)" */ // 2: Grid RowA /* 0: "Error" 1: " at Object._GetFunctionDetails [as func] (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:86:10)" 2: " at Object.jQuery.proxy.func (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:229:15)" 3: " at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13)" 4: " at Object.window..toString (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:239:10)" 5: " at AddEvent (https://bluesafe.mobylink.com/core/framework/js/windowpopup.js:37:29)" 6: " at new window.WindowPopup (https://bluesafe.mobylink.com/core/framework/js/windowpopup.js:259:2)" 7: " at Object._CreateWindow (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13), :2696:16)" 8: " at GetApp.invoke (https://bluesafe.mobylink.com/core/framework/js/Action.class.js:364:17)" 9: " at window.SuggestiveSearchControl.Restore (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13), :458:12)" 10: " at window.SuggestiveSearchControl.ctor (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13), :237:8)" */ // 3: SuggestiveSearch /* 0: "Error" 1: " at Object._GetFunctionDetails [as func] (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:86:10)" 2: " at Object.jQuery.proxy.func (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:289:15)" 3: " at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13)" 4: " at Object.window..toString (https://bluesafe.mobylink.com/core/framework/js/StaticLib.class.js:299:10)" 5: " at window.GridControl.ProcessRowClick (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13), :7692:29)" 6: " at HTMLTableRowElement.eval (eval at proxy (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:10505:13), :7686:17)" 7: " at HTMLTableRowElement.dispatch (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:5240:27)" 8: " at HTMLTableRowElement.elemData.handle (https://bluesafe.mobylink.com/core/framework/js/thirdparty/jquery/jquery.v2.1.3.min.js:5047:28)" */ var re = null; /* var from = { process: false, processPos: -1, processOne: false, caller: false, callerFn: '', line: false, lineNumber: -1, proxy: false, proxyFn: '', APICall: { }, HTML: { location: false, }, }; var x = e.length; while (x--) { if (x === e.length) continue; if (typeof(e[x]) !== 'string') continue; if (from.process === true) continue; if (from.HTML.location === true) continue; if (x === (e.length - 1)) { if (e[x].includes('at HTMLTableRowElement') === true) { from.HTML = true; continue; } if (e[x].includes('at Object.process ') === true) { // API callback from server from.process = true; while (x--) { if (from.processOne === false) { if (e[x].includes('at Object.processOne') !== true) continue; from.processOne = true; continue; } if (from.caller === false) { */ //re = /\s+at\sApp\.proxy\s\[as\s(\w+)\].*/g; /* from.caller = true; from.callerFn = e[x].replace(re, '$1'); continue; } debugger; if (from.line === false) { re = /\s+at\swindow.AppBase\.eval\s.*:([0-9]+):[0-9]+\)$/g; from.line = true; from.lineNumber = e[x].replace(re, '$1'); continue; } if (from.proxy === false) { re = /\s+at\swindow.AppBase\.proxy\s\[as (\w+)\].*$/; from.proxy = true; from.proxyFn = e[x].replace(re, '$1'); continue; } debugger; // breakout the loop if ((from.processOne === true) && (from.caller === true) && (from.line === true) && (from.proxy === true)) x = e.length; continue; } // end while } // end else if continue; } } */ for (var i = 0; i < e.length; i++) { if (isSafari === false) { if (e[i].indexOf('at Object.window..toString (') === -1) continue; e = e[(i + 1)]; found = true; break; } else if (isSafari === true) { found = true; break; } } if (!found) e = e[2]; if (typeof(e) === 'undefined') return; /* jshint -W049: true */ re = /^\s+at\s+(\w+\.\w+)\s.*\:([0-9]+):([0-9]+).*/g; /* jshint +W049: false */ //var name = e.replace(re, '$1'); var temp = null; if (isSafari !== true) { //re = /(?<=\s*at \s*)(?:[\w\.])*/m; temp = e.replace(re, '$1'); //name = temp.substring((temp.indexOf('.') + 1)); result.name = temp.substring((temp.indexOf('.') + 1)); result.line = e.replace(re, '$2'); result.pos = e.replace(re, '$3'); result.all = e.replace(re, 'Function: $1 on line $2 at pos $3'); result.className = temp.substring(0, temp.indexOf('.')); result.method = result.className + '.' + result.name; result.stack = e; } else if (isSafari === true) { re = /^(\w+)@https:\/\/.*:([0-9]+):([0-9]+)$/g; result.name = e[1].replace(re, '$1'); result.line = e[1].replace(re, '$2'); result.pos = e[1].replace(re, '$3'); result.className = 'unknown'; result.method = 'Safari.' + result.name; result.stack = e; } return result; }; var _GetFunctionDetails = function(type) { if (typeof(Error) === 'undefined') return 'Not available'; var expected = '_GetFunctionDetails reports required \'type\' was not specified. Valid types are [1: name, 2: line, 3: pos, 4: all, 5: class, 6: method, 7: stack]'; if (typeof(type) === 'undefined') throw new Error(expected); if (typeof(type) === 'string') type = type.toLowerCase(); var e = new Error(); if (typeof(null) === 'undefined') return 'unknown'; var result = _ProcessStack(e); switch (type) { case 1: case 'name': { return result.name; } case 2: case 'line': { return result.line; } case 3: case 'pos': { return result.pos; } case 4: case 'all': { return result.all; } case 5: case 'class': { return result.className; } case 6: case 'method': { return result.method; } case 7: case 'stack': { return result.stack; } default: { throw new Error(expected); } } }; function macro(name, retFunc, funcArgs) { if ((typeof(name) !== 'string') || (name.length === 0)) throw new Error('macro expects the first argument to be the name of the macro you want to create'); if ((typeof(retFunc) !== 'function') || (name.length === 0)) throw new Error('macro expects the second argument to be a function you want the return value to be'); if (typeof(window[name]) !== 'undefined') throw new Error('Macro already exists for ' + name); if (typeof(funcArgs) === 'undefined') funcArgs = null; var z = jQuery.proxy(function(){ return this.func(this.arg); }, {func: retFunc, arg: funcArgs}); window[name] = {}; Object.defineProperty(window[name], 'name', { get: function() { return z(); } }); window[name].toString = function() { return z(); }; } macro('__FUNCTION__', _GetFunctionDetails, 1); macro('__LINE__', _GetFunctionDetails, 2); macro('__POS__', _GetFunctionDetails, 3); macro('__ALL__', _GetFunctionDetails, 4); macro('__CLASS__', _GetFunctionDetails, 5); macro('__METHOD__', _GetFunctionDetails, 6); macro('__STACK__', _GetFunctionDetails, 7); var StaticLib = { GetRandom: function(min, max) { return Math.random() * (max - min) + min; }, CompareVersions: function(versionStr1, versionStr2) { var errMsg = 'CompareVersions expects 2 string arguments, both of which are version-strings [0.0.0] for example'; if (typeof(versionStr1) !== 'string') throw new Error(errMsg); if (typeof(versionStr2) !== 'string') throw new Error(errMsg); versionStr1 = versionStr1.split('.'); versionStr2 = versionStr2.split('.'); if ((versionStr1.length !== 3) || (versionStr1.length !== 3)) throw new Error(errMsg); if (parseInt(versionStr1[0]) === parseInt(versionStr2[0])) { if (parseInt(versionStr1[1]) === parseInt(versionStr2[1])) { if (parseInt(versionStr1[2]) === parseInt(versionStr2[2])) return 0; if (parseInt(versionStr1[2]) < parseInt(versionStr2[2])) return -1; return 1; } else { if (parseInt(versionStr1[1]) < parseInt(versionStr2[1])) return -1; return 1; } } else { if (parseInt(versionStr1[0]) < parseInt(versionStr2[0])) return -1; return 1; } }, ClearSelection: function() { if (document.getSelection) { document.getSelection().removeAllRanges(); document.getSelection().addRange(document.createRange()); } else if (window.getSelection) { if (window.getSelection().removeAllRanges) { window.getSelection().removeAllRanges(); window.getSelection().addRange(document.createRange()); } else if (window.getSelection().empty) { window.getSelection().empty(); } } else if (document.selection) { document.selection.empty(); } }, GetSubPropertyNames: function(data, isSubProperty) { /** * Get Sub Property name from object * @function GetSubPropertyNames * @memberof StaticLib * @param {object} data data object * @param {Boolean} isSubProperty * @inner */ var keyValues = {}; var keys = null; if (StaticLib.IsPropBaseInstance(data)) { keys = data.GetPropList(); } else { keys = Object.keys(data); } for (var count = 0; count < keys.length; count++) { var val = keys[count]; if ((typeof(data[keys[count]]) === 'object') && (data[keys[count]] !== null)){ if (Array.isArray(data[keys[count]])) continue; if (keys[count] === '__OriginalState') continue; val = StaticLib.GetSubPropertyNames(data[keys[count]], true); var keys2 = null; keys2 = Object.keys(val); for (var count2 = 0; count2 < keys2.length; count2++) { val[(keys[count] + '.' + val[keys2[count2]])] = keys[count] + '.' + val[keys2[count2]]; keyValues[(keys[count] + '.' + val[keys2[count2]])] = keys[count] + '.' + val[keys2[count2]]; delete val[keys2[count2]]; } } if (typeof(data[keys[count]]) !== 'object') { keyValues[keys[count]] = val; } } //keyValues[''] = '{unbound}'; if (isSubProperty !== true) keyValues['{unbound}'] = ''; return keyValues; }, QuickObjCompare: function(obj1, obj2) { /** * Compare two objects * @function QuickObjCompare * @memberof StaticLib * @param {object} obj1 * @param {object} obj2 * @returns {Boolean} * @inner */ return StaticLib.DeepObjCompare(obj1, obj2, false); }, DeepObjCompare: function(obj1, obj2, doDeepComparison) { /** * Compare two objects in detail * @function DeepObjCompare * @memberof StaticLib * @param {object} obj1 * @param {object} obj2 * @param {boolean} doDeepComparison * @returns {Boolean} * @inner */ var type = typeof(obj1); if (type !== typeof(obj2)) return false; //SHOULDN'T have passed me a non-object, but it's not hard for me to handle for you I guess... if (type !== 'object') return (obj1 === obj2); var keys = Object.keys(obj1); for (var i = 0; i < keys.length; i++) { //Compare VALUES not Object references! if (typeof(obj1[keys[i]]) !== 'object') { if (obj1[keys[i]] !== obj2[keys[i]]) return false; } else if (doDeepComparison) { if (StaticLib.DeepObjCompare(obj1, obj2, true) !== true) return false; } } return true; }, IsGUID: function(value) { /** * Check if string is a valid GUID * @function IsGUID * @memberof StaticLib * @param {String} value * @returns {Boolean} * @inner */ if (typeof(value) !== 'string') return false; if (value.length !== 36) return false; var regex = /^([A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12})$/gm; return (regex.exec(value) !== null); }, Dev:{ setPrototypeOf: function(obj, newParent) { if (typeof(Object.setPrototypeOf) === 'function') { Object.setPrototypeOf(obj, newParent); } else { if (typeof(obj.__proto__) !== 'undefined') { assertian(); obj.__proto__ = newParent; } else if (typeof(obj.prototype) !== 'undefined') { obj.prototype = newParent; } } }, getPrototypeOf: function(obj) { if (typeof(Object.getPrototypeOf) === 'function') { return Object.getPrototypeOf(obj); } else { if (typeof(obj.__proto__) !== 'undefined') { assertian(); return obj.__proto__; } else if (typeof(obj.prototype) !== 'undefined') { return obj.prototype; } } } }, UI: { WhenClicked: function(event, doThis) { var element = jQuery(event.target); var context = {obj:element, func:doThis}; var _clickFunction = jQuery.proxy(StaticLib.UI._clickEvent, context); var _unclickFunction = jQuery.proxy(function(event){ this.obj.isLoading = false; this.obj.removeClass('disabled'); this.obj.find('i.progress-icon').remove(); this.obj.attr('disabled', false); }, context); context.undo = _unclickFunction; _clickFunction(); }, Click: function(element, doThis) { if (typeof(element) !== 'object') throw new Error('StaticLib.Click should not be called without an element argument'); element = jQuery(element); var context = {obj:element, func: jQuery.proxy(doThis, element)}; var _clickFunction = jQuery.proxy(StaticLib.UI._clickEvent, context); var _unclickFunction = jQuery.proxy(function(event){ this.obj.isLoading = false; this.obj.removeClass('disabled'); this.obj.find('i.progress-icon').remove(); this.obj.attr('disabled', false); }, context); context.undo = _unclickFunction; debugger; element.unbind('click'); element.bind('click', _clickFunction); }, _clickEvent: function(event){ if (this.obj.isLoading) return; this.obj.isLoading = true; this.obj.addClass('disabled'); this.obj.prepend(''); this.obj.attr('disabled', true); window.setTimeout(this.undo, 3500); this.func(event); }, GetContextOfDialog: function(item) { var handle = null; var subject = jQuery(item); if (subject.hasClass('.ui-dialog-normal')) { handle = subject; } else { handle = subject.parents('.ui-dialog-normal'); } if (handle.length === 0) return null; //return window.Framework.prop.WindowCollection.items[handle.attr('id')].instance; //For the item we are sent, find the object that contains it with a dialog window class... //fetch that dialog's ID, then use that to look up the list of stored instances for that window var obj = window.Framework.prop.WindowCollection.items[handle.attr('id')]; if ((typeof(obj) === 'undefined') || (obj === null)) return null; return window.Framework.prop.WindowCollection.items[handle.attr('id')].instance; }, SelectElementText: function(el) { StaticLib.UI.RemoveTextSelections(); var range; if (document.selection) { range = document.body.createTextRange(); range.moveToElementText(el); range.select(); } else if (window.getSelection) { range = document.createRange(); range.selectNode(el); window.getSelection().addRange(range); } }, // Deselects all text in the page. RemoveTextSelections: function() { if (document.selection) document.selection.empty(); else if (window.getSelection) window.getSelection().removeAllRanges(); }, isFullScreen: false, ToggleFullscreen: function() { /** * Launch/Exit full screen * @function ToggleFullscreen * @memberof StaticLib * @inner */ if (StaticLib.UI.isFullScreen) { StaticLib.UI.ExitFullscreen(); } else { StaticLib.UI.LaunchFullscreen(); } }, LaunchFullscreen: function() { /** * Launch full screen * @function LaunchFullscreen * @memberof StaticLib * @inner */ debugger; var element = document.documentElement; //if (document.fullscreenEnabled === true) { if (typeof(element.webkitRequestFullscreen) === 'function') { element.webkitRequestFullscreen(); } else if (typeof(element.requestFullscreen) === 'function') { element.requestFullscreen(); } else if (typeof(element.mozRequestFullScreen) === 'function') { element.mozRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT); } else if (typeof(element.msRequestFullscreen) === 'function') { element.msRequestFullscreen(); } //} }, ExitFullscreen: function() { /** * Exit full screen * @function ExitFullscreen * @memberof StaticLib * @inner */ //if ((document.fullscreenElement !== null) && (document.fullscreenEnabled === true)) { if (document.fullscreenElement !== null) { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitExitFullscreen) { document.webkitExitFullscreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } } } }, HasSameKeys: function(array1, array2) { /** * Compare two arrays if they have same keys * @function HasSameKeys * @memberof StaticLib * @param {array} array1 * @param {array} array2 * @returns {Boolean} * @inner */ var keys1 = Object.keys(array1); var keys2 = Object.keys(array2); keys1.sort(); keys2.sort(); var missing = []; var extra = []; var offset = 0; for (var count = 0; count < keys1.length; count++) { /*if (typeof(array2[keys1[count]]) === 'undefined') { missing.push(keys1[count]); continue; }*/ var index = keys2.indexOf(keys1[count]); if (index === -1) { missing.push(keys1[count]); offset++; } else if (index !== (count - offset)) { extra.push(keys1[count]); offset--; } } if ((missing.length === 0) && (extra.length === 0)) return true; return {missing:missing, extra:extra}; }, MergeVals: function(array1, array2) { /** * Merge array values between two array * @function MergeVals * @memberof StaticLib * @param {array1} array1 * @param {array2} array2 * @returns {array} * @inner */ if (typeof Object.assign !== 'function') { // Must be writable: true, enumerable: false, configurable: true Object.defineProperty(Object, 'assign', { value: function assign(target, varArgs) { // .length of function is 2 if (target === null) { // TypeError if undefined or null throw new TypeError('Cannot convert undefined or null to object'); } var to = Object(target); for (var index = 1; index < arguments.length; index++) { var nextSource = arguments[index]; if (nextSource !== null) { // Skip over if undefined or null for (var nextKey in nextSource) { // Avoid bugs when hasOwnProperty is shadowed if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { to[nextKey] = nextSource[nextKey]; } } } } return to; }, writable: true, configurable: true }); } return Object.assign(array1, array2); }, EscapeHtml: function(rawStr) { /** * Escape HTML from string * @function EscapeHtml * @memberof StaticLib * @param {string} rawStr * @returns {string} * @inner */ var type = typeof(rawStr); if (type === 'function') return ''; if (type !== 'string') return rawStr; return rawStr.replace(/[\u00A0-\u9999<>\&]/gim, function(i) { return '&#'+i.charCodeAt(0)+';'; }); }, EscapeAttribute: function(rawStr) { /** * Escape double quotes and slashes from string * @function EscapeAttribute * @memberof StaticLib * @param {string} rawStr * @returns {string} * @inner */ rawStr = StaticLib.EscapeHtml(rawStr); if ((typeof(rawStr) !== 'string') || (rawStr === '')) return rawStr; rawStr = rawStr.replace('"', '"'); rawStr = rawStr.replace('\'', '''); return rawStr; }, ImagifyHTMLorCSS: function(htmlOrCss) { debugger; return htmlOrCss; }, StripJS: function(content, silent) { /** * Remove JS Code from content * @function StripJS * @memberof StaticLib * @param {string} content * @param {boolean}|{function} silent can be a bool true | false or msgbox function * @returns {string} * @inner */ if (typeof(content) !== 'string') throw new Error('.StripJS expects a single string argument. ("' + typeof(content) + '" received instead)'); var onEvents = new RegExp('[\\s]on[a-zA-z]+[\\s]*=[\\s]*[\\"\\\']', 'i'); var equalsPos = -1; var seperator = ''; var errorCount = 0; var index = content.search(onEvents); while (index !== -1) { errorCount++; equalsPos = content.indexOf('=', index); seperator = content.substr((equalsPos+1), 1); content = StaticLib.StripBetween(content, index, (content.indexOf(seperator, (equalsPos + 2) ) + 1) ); index = content.search(onEvents); } var otherEvents = new RegExp('(animationend|animationiteration|animationstart|transitionend)[\\s]*=[\\s]*[\\"\\\']', 'i'); index = content.search(otherEvents); while (index !== -1) { errorCount++; equalsPos = content.indexOf('=', index); seperator = content.substr((equalsPos+1), 1); content = StaticLib.StripBetween(content, index, (content.indexOf(seperator, (equalsPos + 2) ) + 1) ); index = content.search(otherEvents); } index = content.search('
' + errorCount + ' instances were found and removed (this includes event attributes such as OnClick)

Please note that including JS in your HTML is a potential vulnerability, any functionality that can be produced by embedding code can be produced correctly by having it executed by the associated app.'; if (typeof(window.Framework) !== 'undefined') { if (errorCount > 0){ if (typeof(silent) === 'function') { silent({title: 'Developer Error A227', message: errMsg, modal: true}); } else { if ((window.Framework.prop.developer) && (silent !== true)) { window.Framework.UI.MsgBox({title: 'Developer Error A228', message: errMsg, modal: true}); } } } } return content; }, StripBetween: function(content, start, end) { /** * Strip string content between start and end positions * @function StripBetween * @param {integer} start * @param {integer} end * @memberof StaticLib * @returns {string} * @inner */ return content.substring(0, start) + content.substring(end); }, StartsWith: function(needle, haystack) { /** * Find string from start position and return * @function StartsWith * @param {string} needle * @param {string} haystack * @memberof StaticLib * @returns {string} * @inner */ var h = haystack; if (typeof(haystack) !== 'string') h = String(h); return (h.startsWith(needle)); }, EndsWith: function(needle, haystack) { /** * Find string from end position and return * @function StartsWith * @param {string} needle * @param {string} haystack * @memberof StaticLib * @returns {string} * @inner */ var h = haystack; var n = needle; if (typeof(haystack) !== 'string') h = String(h); if (typeof(needle) !== 'string') n = String(n); if (n.length > h.length) return false; return (haystack.substring(h.length - n.length) === needle); }, ReformatDateString: function(fromformat, toformat, value) { /** * Format date * @function ReformatDateString * @param {string} fromformat * @param {string} toformat * @param {string} value * @memberof StaticLib * @returns {string} * @inner */ return StaticLib.DateFormat(toformat, StaticLib.FormatIntoDate(fromformat, value)); }, GetFinancialYear: function (dateObj) { /** * Get financial year from dateObj * @function GetFinancialYear * @param {date} dateObj * @memberof StaticLib * @returns {string} * @inner */ var err = 'StaticLib.DateFormat() expects it\'s second argument to be a Date object'; var monthCutoff = 6; //Next financial year begins July 1st in Australia (count month from 0) var dayCutoff = 1; //Next financial year begins July 1st in Australia (count day from 1) //getMonth() if (typeof(dateObj) !== 'object') { throw new Error(err); } else { if (!(dateObj instanceof Date)) { throw new Error(err); } } var start = dateObj.getFullYear(); if (start === new Date().getFullYear()) { return 'NOW'; } if ((dateObj.getMonth() < monthCutoff) || ((dateObj.getMonth() === monthCutoff) && (dateObj.getDate() < dayCutoff))) { start--; } return String(start).substring(String(start).length - 2) + '-' + String(start + 1).substring(String(start + 1).length - 2); }, SetModal: function(type, data, buttons, callbackList, options) { if (typeof(type) !== 'string') { //MOVE EVERYTHING BACK ONE ARG options = callbackList; callbackList = buttons; buttons = data; data = type; } else { var acceptedType = ['msgbox', 'inputbox', 'input', 'suggestivebox', 'suggestive', 'optionsbox', 'options', 'grid', 'gridbox']; switch (type) { case 'msgbox': { break; } case 'input': case 'inputbox': { //return this.SetInputModal(data, buttons, callbackList, options); data.type = 'inputbox'; break; } case 'suggestive': case 'suggestivebox': { //return this.SetSuggestiveModal(data, buttons, callbackList, options); data.type = 'suggestivebox'; break; } case 'options': case 'optionsbox': { //return this.SetOptionsModal(data, buttons, callbackList, options); data.type = 'option_box'; break; } case 'grid': case 'gridbox': { //return this.SetOptionsModal(data, buttons, callbackList, options); data.type = 'gridbox'; break; } default: { throw new Error(__METHOD__ + ' expects when it\'s first argument is a string type which is one of the following: ' + JSON.stringify(acceptedType)); } } } window.Framework.UI.CreateMsgBox(data, buttons, callbackList, options); }, PositionNextToSelected: function(obj) { var selected = jQuery(obj); var invisible = false; var notShown = false; if ((selected.css('visibility') === 'hidden') || (selected.css('display') === 'none')) { if (selected.css('visibility') === 'hidden') { selected.css('visibility', 'visible'); invisible = true; } if (selected.css('display') === 'none') { selected.css('display', ''); notShown = true; } } var selectedOffset = selected.offset(); if (notShown === true) selected.css('display', 'none'); if (invisible === true) selected.css('visibility', 'hidden'); var containerOffset = jQuery('#dialogWindows').offset(); assertgroup('compiler', 'debug compiler points that you need to know about, left and top are compiler keys'); var top = (selectedOffset.top - 18 - containerOffset.top); //TODO compiler .top is a compiler key var left = (selectedOffset.left + selected.width() + 25 - containerOffset.left); //TODO compiler .left is a compiler key return {'top': top, 'left': left}; }, IsPHPDate: function(val) { /** * Check if string is in php date format * @function IsPHPDate * @param {string} val * @memberof StaticLib * @returns {boolean} * @inner */ //{"date":"2019-07-29 15:16:16.127000","timezone_type":3,"timezone":"Australia/Melbourne"} if (typeof(val) !== 'object') return false; if (val === null) return false; if (typeof(val.date) !== 'string') return false; if (typeof(val.timezone) !== 'string') return false; if (typeof(val.timezone_type) !== 'number') return false; return (new RegExp('\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{6}').test(val.date) !== true); }, TranslateDatepickerFormatIntoPHP: function(format) { /* JQUERY DATEPICKER PHP DATE FORMAT -------------------------------------------------------------------------- dd - day of month (two digit) * d Day of the month, 2 digits with leading zeros d - day of month (no leading zero) j Day of the month without leading zeros o - day of the year (no leading zeros) z The day of the year (starting from 0) oo - day of the year (three digit) ------ D - day name short D A textual representation of a day, three letters DD - day name long l A full textual representation of the day of the week m - month of year (no leading zero) n Numeric representation of a month, without leading zeros mm - month of year (two digit) m Numeric representation of a month, with leading zeros M - month name short M A short textual representation of a month, three letters MM - month name long F A full textual representation of a month, such as January or March y - year (two digit) y A two digit representation of a year yy - year (four digit) Y A full numeric representation of a year, 4 digits d -> j jj -> d m->n nn->m MM->F DD->l YY->y */ format = format.replace('d', 'j'); format = format.replace('jj', 'd'); //dd -> jj -> d format = format.replace('m', 'n'); format = format.replace('nn', 'm'); //mm -> nn -> m format = format.replace('MM', 'F'); format = format.replace('DD', 'l'); format = format.replace('YY', 'y'); return format; }, TranslatePHPDate: function(val) { /** * Translate into php date format from datetime obj * @function TranslatePHPDate * @param {string} val * @memberof StaticLib * @returns {string} * @inner */ if (StaticLib.IsPHPDate(val) !== true) throw new Error('TranslatePHPDate() expects a PHP DateTime object or equivilant'); var dateObj = StaticLib.FormatIntoDate('Y-m-d H:i:s.u', val.date); /*if (typeof(dateObj.getTimezoneOffset) === 'function') { //val.timezone }*/ return dateObj; }, FormatIntoDate: function(format, value) { /** * Convert string into formatted date * @function FormatIntoDate * @param {string} val * @memberof StaticLib * @returns {string} * @inner */ if (StaticLib.IsPHPDate(value)) return StaticLib.TranslatePHPDate(value); var tempValue = value; var acceptableKeys = new Array('M', 'm', 'd', 'j', 'Y', 'y', 'h', 'H', 'i', 's', 'u'); var valueArray = []; var key = ''; var index = -1; for (var i = 0; i <= format.length; i++) { //key = format[i]; //index = -1; index = acceptableKeys.indexOf(format[i]); if (index !== -1) { key = key + format[i]; } else { //key = format[i]; index = tempValue.search(format[i]); if (index === -1) index = tempValue.length; //var part1 = tempValue.substring(0, index); while ((index === 0) && (typeof(format[i]) !== 'undefined')) { var test = format[i]; if (test === '.') { test = '[.]'; } else { tempValue = tempValue.substring(1); } index = tempValue.search(test); } if (typeof(format[i]) !== 'undefined') { if (tempValue !== '') { valueArray[key] = tempValue.substring(0, index).trim(); } } else { if (tempValue !== '') { valueArray[key] = tempValue; } } tempValue = tempValue.substring(index+1); key = ''; } } index = null; var isset = false; var newDate = new Date(null); newDate.setHours(0); var monthName = new Array('January', 'Febuary', 'March', 'April', 'May', 'June', 'July','August', 'September', 'October', 'November', 'December'); var shortMonthNames = monthName; shortMonthNames.forEach(function(val, index, obj) {obj[index] = val.substring(0,3);}); // m Numeric representation of a month, with leading zeros if (typeof(valueArray.m) !== 'undefined') { //Note: SETMONTH expects that January is 0, February is 1 index = (Number(valueArray.m) - 1); if (index > 11) throw new Error('Month cannot be larger than 12'); if (index < 0) throw new Error('Month cannot be smaller than 1'); isset = true; newDate.setMonth(index); } // M A short textual representation of a month, three letters Jan through Dec if (typeof(valueArray.M) !== 'undefined') { index = shortMonthNames.indexOf(valueArray.M); if (index === -1) throw new Error('Month name\'' + valueArray.M + '\' was not found'); isset = true; newDate.setMonth(index); if (newDate.getMonth() !== index) newDate.setMonth(index); } // d Day of the month, 2 digits with leading zeros 01 to 31 if (typeof(valueArray.d) !== 'undefined') { index = Number(valueArray.d); if (index > 31) throw new Error('Day cannot be larger than 31'); if (index < 0) throw new Error('Day cannot be smaller than 1'); isset = true; newDate.setDate(index); } // j Day of the month without leading zeros 1 to 31 if (typeof(valueArray.j) !== 'undefined') { index = Number(valueArray.j); if (index > 31) throw new Error('Day cannot be larger than 31'); if (index < 1) throw new Error('Day cannot be smaller than 1'); isset = true; newDate.setDate(index); } // Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003 if (typeof(valueArray.Y) !== 'undefined') { isset = true; newDate.setFullYear(Number(valueArray.Y)); } // y A two digit representation of a year Examples: 99 or 03 if (typeof(valueArray.y) !== 'undefined') { var year = new Date().getFullYear().toString(); var yearCutoff = Number(year.substr((year.length-2) , 2))+3; var currentCentury = Number(year.substr(0, 2)); var temp = valueArray.y; if (Number(temp) > yearCutoff) { temp = (parseInt(currentCentury)-1) + temp; } else { temp = parseInt(currentCentury) + temp; } isset = true; newDate.setFullYear(Number(temp)); } // h 12-hour format of an hour with leading zeros 01 through 12 if (typeof(valueArray.h) !== 'undefined') { index = Number(valueArray.h); if ((value.indexOf('AM') !== -1) && (index === 0)) index = 12; if (index > 12) throw new Error('12-Hour cannot be larger than 12'); if (index < 1) throw new Error('12-Hour cannot be smaller than 1'); if (index === 12) { if (value.indexOf('AM') !== -1) { isset = true; newDate.setHours(0); } else if (value.indexOf('PM') !== -1) { isset = true; newDate.setHours(12); } else throw new Error('12-hour format expects an AM or a PM within'); } else if (value.indexOf('AM') !== -1){ isset = true; newDate.setHours(index); } else if (value.indexOf('PM') !== -1){ isset = true; newDate.setHours(index + 12); } else throw new Error('12-hour format expects an AM or a PM within'); } // H 24-hour format of an hour with leading zeros 00 through 23 if (typeof(valueArray.H) !== 'undefined') { index = Number(valueArray.H); if (index > 23) throw new Error('24-Hour cannot be larger than 23'); if (index < 0) throw new Error('24-Hour cannot be smaller than 0'); isset = true; newDate.setHours(index); } // i Minutes with leading zeros 00 to 59 if (typeof(valueArray.i) !== 'undefined') { index = Number(valueArray.i); if (index > 59) throw new Error('Minutes cannot be larger than 59'); if (index < 0) throw new Error('Minutes cannot be smaller than 0'); isset = true; newDate.setMinutes(Number(valueArray.i)); } // s Seconds with leading zeros 00 to 59 if (typeof(valueArray.s) !== 'undefined') { if ((value.indexOf('AM') !== -1) || (value.indexOf('PM') !== -1)) { valueArray.s = valueArray.s.replace('AM', ''); valueArray.s = valueArray.s.replace('PM', ''); } index = Number(valueArray.s); if (index > 59) throw new Error('Seconds cannot be larger than 59'); if (index < 0) throw new Error('Seconds cannot be smaller than 0'); isset = true; newDate.setSeconds(Number(valueArray.s)); } if (isset){ return newDate; } return null; }, DateFormat: function(format, dateObj) { /** * Convert string into formatted date * @function DateFormat * @param {string} format * @param {object} dateObj * @memberof StaticLib * @returns {string} * @inner */ var err = 'StaticLib.DateFormat() expects it\'s second argument to be a Date object'; if (typeof(dateObj) !== 'object') { throw new Error(err); } else { if (!(dateObj instanceof Date)) { throw new Error(err); } } if (typeof(format) !== 'string') { throw new Error('StaticLib.DateFormat() expects it\'s first argument to be a format string'); } function getDayOfWeek(dateIs){ /** * Get day of the week from date * @function getDayOfWeek * @memberof StaticLib * @param {object} dateIs * @returns {string} * @inner */ switch(dateIs.getDay()) { case 0: { return 'Sunday'; } case 1: { return 'Monday'; } case 2: { return 'Tuesday'; } case 3: { return 'Wednesday'; } case 4: { return 'Thursday'; } case 5: { return 'Friday'; } case 6: { return 'Saturday'; } default: { throw new Error('There was an error processing the date in StaticLib.DateFormat()'); } } } function getMonthName(dateIs){ /** * Get month name from date * @function getMonthName * @memberof StaticLib * @param {object} dateIs * @returns {string} * @inner */ switch( (dateIs.getMonth() + 1) ) { /*case 0: { return ''; }*/ case 1: { return 'January'; } case 2: { return 'Febuary'; } case 3: { return 'March'; } case 4: { return 'April'; } case 5: { return 'May'; } case 6: { return 'June'; } case 7: { return 'July'; } case 8: { return 'August'; } case 9: { return 'September'; } case 10: { return 'October'; } case 11: { return 'November'; } case 12: { return 'December'; } default: { throw new Error('There was an error processing the date in StaticLib.DateFormat()'); } } } function getDaysInMonth(dateIs) { /** * Get days in month * @function getDaysInMonth * @memberof StaticLib * @param {object} dateIs * @returns {number} * @inner */ switch( (dateIs.getMonth() + 1) ) { /*case 0: } return ''; }*/ case 1: case 3: case 5: case 7: case 8: case 10: case 12: { return 31; } case 4: case 6: case 9: case 11: { return 30; } case 2: { if (isLeapYear(dateIs)){ return 29; } return 28; } default: { throw new Error('There was an error processing the date in StaticLib.DateFormat()'); } } } function getMeridian(dateIs){ /** * Get meridian from the date * @function getDaysInMonth * @memberof StaticLib * @param {object} dateIs * @returns {string} * @inner */ var hour = dateIs.getHours(); if (hour >= 12) return 'pm'; return 'am'; } function isLeapYear(dateIs) { /** * Check if the date is in leap years * @function isLeapYear * @memberof StaticLib * @param {object} dateIs * @returns {boolean} * @inner */ var year = dateIs.getFullYear(); if ((year & 3) !== 0) return false; return ((year % 100) !== 0 || (year % 400) === 0); } function twelveHourTime(dateIs) { /** * Get 12 hours time * @function twelveHourTime * @memberof StaticLib * @param {object} dateIs * @returns {number} * @inner */ var hour = dateIs.getHours(); if (hour > 12) return (hour - 12); return hour; } function getNumTh(dateIs) { switch(dateIs.getDate()) { /*case 0: { return 'Sunday'; }*/ case 1: { return 'st'; } case 2: { return 'nd'; } case 3: { return 'rd'; } default: { return 'th'; } } } var temp = format; var temp2 = []; var indexOf = -1; for (var i = 0; i < temp.length; i++) { temp2[i] = temp [i]; } //---------DAYS--------- // d Day of the month, 2 digits with leading zeros 01 to 31 indexOf = temp2.indexOf('d'); if (indexOf !== -1) { temp2[indexOf] = (('0' + dateObj.getDate()).slice(-2)); } // D A textual representation of a day, three letters Mon through Sun indexOf = temp2.indexOf('D'); if (indexOf !== -1) { temp2[indexOf] = (getDayOfWeek(dateObj).slice(0,3)); } // j Day of the month without leading zeros 1 to 31 indexOf = temp2.indexOf('j'); if (indexOf !== -1) { temp2[indexOf] = (dateObj.getDate()); } // l A full textual representation of the day of the week Sunday through Saturday indexOf = temp2.indexOf('l'); if (indexOf !== -1) { temp2[indexOf] = (getDayOfWeek(dateObj)); } // N ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday) indexOf = temp2.indexOf('N'); if (indexOf !== -1) { temp2[indexOf] = (dateObj.getDate() + 1); } // S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j indexOf = temp2.indexOf('S'); if (indexOf !== -1) { temp2[indexOf] = (getNumTh(dateObj)); } // w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) indexOf = temp2.indexOf('D'); if (indexOf !== -1) { temp2[indexOf] = (dateObj.getDay()); } // z The day of the year (starting from 0) 0 through 365 //indexOf = temp2.indexOf('z'); //temp = temp.replace('z', '' ); //---------WEEK--------- // W ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) Example: 42 (the 42nd week in the year) //indexOf = temp2.indexOf('W'); //temp = temp.replace('W', '' ); //---------MONTH--------- // F A full textual representation of a month, such as January or March January through December indexOf = temp2.indexOf('D'); if (indexOf !== -1) { temp2[indexOf] = (getMonthName(dateObj)); } // m Numeric representation of a month, with leading zeros 01 through 12 indexOf = temp2.indexOf('m'); if (indexOf !== -1) { temp2[indexOf] = (('0' + (Number(dateObj.getMonth()) + 1)).slice(-2));} // M A short textual representation of a month, three letters Jan through Dec indexOf = temp2.indexOf('M'); if (indexOf !== -1) { temp2[indexOf] = (getMonthName(dateObj).slice(0,3)); } // n Numeric representation of a month, without leading zeros 1 through 12 indexOf = temp2.indexOf('n'); if (indexOf !== -1) { temp2[indexOf] = ((Number(dateObj.getMonth()) + 1) ); } // t Number of days in the given month 28 through 31 indexOf = temp2.indexOf('t'); if (indexOf !== -1) { temp2[indexOf] = (getDaysInMonth(dateObj)); } //---------YEAR--------- // L Whether it\'s a leap year 1 if it is a leap year, 0 otherwise. indexOf = temp2.indexOf('L'); if (indexOf !== -1) { temp2[indexOf] = (Number(isLeapYear(dateObj))); } // o ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0) Examples: 1999 or 2003 //indexOf = temp2.indexOf('D'); //if (indexOf !== -1) { temp2[indexOf] = ''; } // Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003 indexOf = temp2.indexOf('Y'); if (indexOf !== -1) { temp2[indexOf] = (dateObj.getFullYear()); } // y A two digit representation of a year Examples: 99 or 03 indexOf = temp2.indexOf('y'); if (indexOf !== -1) { temp2[indexOf] = (dateObj.getFullYear().toString().slice(-2));} //---------TIME--------- // a Lowercase Ante meridiem and Post meridiem am or pm indexOf = temp2.indexOf('a'); if (indexOf !== -1) { temp2[indexOf] = (getMeridian(dateObj)); } // A Uppercase Ante meridiem and Post meridiem AM or PM indexOf = temp2.indexOf('A'); if (indexOf !== -1) { temp2[indexOf] = (getMeridian(dateObj).toUpperCase()); } // B Swatch Internet time 000 through 999 //indexOf = temp2.indexOf('B'); //if (indexOf !== -1) { temp2[indexOf] = ''; } // g 12-hour format of an hour without leading zeros 1 through 12 indexOf = temp2.indexOf('g'); if (indexOf !== -1) { temp2[indexOf] = twelveHourTime(dateObj); } // G 24-hour format of an hour without leading zeros 0 through 23 indexOf = temp2.indexOf('G'); if (indexOf !== -1) { temp2[indexOf] = (dateObj.getHours()); } // h 12-hour format of an hour with leading zeros 01 through 12 indexOf = temp2.indexOf('h'); if (indexOf !== -1) { temp2[indexOf] = (('0' + twelveHourTime(dateObj)).slice(-2)); if (temp2[indexOf] === '00') temp2[indexOf] = '12'; } // H 24-hour format of an hour with leading zeros 00 through 23 indexOf = temp2.indexOf('H'); if (indexOf !== -1) { temp2[indexOf] = (('0' + dateObj.getHours()).slice(-2));} // i Minutes with leading zeros 00 to 59 indexOf = temp2.indexOf('i'); if (indexOf !== -1) { temp2[indexOf] = (('0' + dateObj.getMinutes()).slice(-2));} // s Seconds, with leading zeros 00 through 59 indexOf = temp2.indexOf('s'); if (indexOf !== -1) { temp2[indexOf] = (('0' + dateObj.getSeconds()).slice(-2));} // u Microseconds (added in PHP 5.2.2). Note that date() will always generate 000000 since it takes an integer parameter, whereas DateTime::format() does support microseconds if DateTime was created with microseconds. Example: 654321 indexOf = temp2.indexOf('u'); if (indexOf !== -1) { temp2[indexOf] = '0000'; } //---------TIMEZONE--------- // e Timezone identifier (added in PHP 5.1.0) Examples: UTC, GMT, Atlantic/Azores //indexOf = temp2.indexOf('e'); //if (indexOf !== -1) { temp2[indexOf] = ''; } // I (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. //indexOf = temp2.indexOf('I'); //if (indexOf !== -1) { temp2[indexOf] = ''; } // O Difference to Greenwich time (GMT) in hours Example: +0200 //indexOf = temp2.indexOf('O'); //if (indexOf !== -1) { temp2[indexOf] = ''; } // P Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) Example: +02:00 //indexOf = temp2.indexOf('P'); //if (indexOf !== -1) { temp2[indexOf] = ''; } // T Timezone abbreviation Examples: EST, MDT ... //indexOf = temp2.indexOf('T); //if (indexOf !== -1) { temp2[indexOf] = ''; } // Z Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400 //indexOf = temp2.indexOf('Z'); //if (indexOf !== -1) { temp2[indexOf] = ''; } //---------FULL DATE/TIME--------- // c ISO 8601 date (added in PHP 5) 2004-02-12T15:19:21+00:00 //indexOf = temp2.indexOf('c'); //if (indexOf !== -1) { temp2[indexOf] = ''; } // r » RFC 2822 formatted date Example: Thu, 21 Dec 2000 16:01:07 +0200 //indexOf = temp2.indexOf('r'); //if (indexOf !== -1) { temp2[indexOf] = ''; } // U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) //indexOf = temp2.indexOf('U'); //if (indexOf !== -1) { temp2[indexOf] = ''; } return temp2.join(''); }, DeepSealInheritable: function(obj, ignoreList) { // Retrieve the property names defined on obj var propNames = Object.getOwnPropertyNames(obj); if ((propNames === null) || (typeof(propNames) === 'undefined')) return obj; if (typeof(ignoreList) === 'undefined') ignoreList = []; // seal properties before seal self propNames.forEach(function(name) { if (name === '__Props') return; if (name === 'constructor') return; if (typeof(obj) === 'function') return; //var prop = obj[name]; var skipTouch = false; var prop = null; if ((name.startsWith('__') === false) && (typeof(obj.FindProp) === 'function')) { prop = obj.FindProp(name); if (prop !== null) { if (prop.CreateOnTouch === true) skipTouch = true; prop = prop.GetValue(); } } if ((skipTouch === false) && (prop === null)) prop = obj[name]; // seal prop if it is an object //if (prop !== prop2) { //debugger; //} if (prop === null) return; if (ignoreList.indexOf(obj[name]) !== -1) return; if ((typeof(prop) === 'object') && (prop !== null)) { if (typeof(AppStaticLib) !== 'undefined') { if (AppStaticLib.IsAnApp(prop) ) return; } StaticLib.DeepSeal(prop, ignoreList); } else { StaticLib.Seal(prop); } }); // seal self (no-op if already sealed) return StaticLib.SealInheritable(obj); }, InstanceOf: function(obj, func) { /** * Check if object is instance of class or func * @function StripJS * @memberof StaticLib * @param {string} content * @param {boolean} silent * @returns {boolean} * @inner */ var errMsg = __METHOD__ + ' expects 2 arguments, an object and a function'; if (obj === null) return false; if (typeof(obj) !== 'object') throw new Error(errMsg); if (typeof(func) !== 'function') throw new Error(errMsg); var root = {}; var test = obj; var testHash = obj.constructor.toString().hashCode(); while (test.constructor !== root.constructor) { if (test.constructor === func) return true; if (testHash === func.toString().hashCode()) return true; test = Object.getPrototypeOf(test); } return false; }, DeepSeal: function(obj, ignoreList) { /** * Deepseal an object * @function DeepSeal * @param {object} obj * @param {object} ignoreList * @memberof StaticLib * @returns {object} * @inner */ if (typeof(ignoreList) === 'undefined') ignoreList = []; if (obj instanceof jQuery) return obj; if (typeof(obj) === 'undefined') return obj; if (typeof(window.Framework) !== 'undefined') { if ((typeof(window.Framework.Methods) !== 'undefined') && (typeof(window.Framework.Methods.GetAPIV2) !== 'undefined') && (obj.constructor === window.Framework.Methods.GetAPIV2)) return obj; if ((typeof(window.Framework.Lib) !== 'undefined') && (typeof(window.Framework.Lib.PropsBaseV3) !== 'undefined') && (StaticLib.IsPropStructInstance(obj))) return obj; } // Retrieve the property names defined on obj var propNames = Object.getOwnPropertyNames(obj); if ((propNames === null) || (typeof(propNames) === 'undefined')) return obj; // seal properties before seal self propNames.forEach(function(name) { if (name === '__Props') return; if (typeof(obj) === 'function') return; var prop = obj[name]; if (prop === null) return; /* developer code start */ if (name === 'window.Framework.Enum') { /*jshint debug: true */ debugger; } /* developer code end */ if (ignoreList.indexOf(obj[name]) !== -1) return; // seal prop if it is an object if ((typeof(prop) === 'object') && (prop !== null)) { if ((typeof(AppStaticLib) !== 'undefined') && (AppStaticLib.IsAnApp(prop))) return; StaticLib.DeepSeal(prop, ignoreList); } else { StaticLib.Seal(prop); } }); if (Array.isArray(obj)) return; // seal self (no-op if already sealed) return StaticLib.Seal(obj); }, SealInheritable: function(obj) { var sealAllExceptConstructor = function(obj){ var doNotSeal = ['OnValueChange', '_hiddenOnValueChange', 'value']; doNotSeal.forEach(function(name) { if (typeof(obj[name]) === 'undefined') return; obj[name] = obj[name]; }); if (!obj.hasOwnProperty('constructor')) obj.constructor = obj.constructor; Object.preventExtensions(obj); var propNames = Object.getOwnPropertyNames(obj); if ((propNames === null) || (typeof(propNames) === 'undefined')) return obj; // seal properties before seal self propNames.forEach(function(name) { if (name === 'constructor') return; Object.defineProperty(obj, name, { configurable: false } ); }); }; if (typeof(obj) === 'object') return sealAllExceptConstructor(obj); if (typeof(window.ECMAS5) === 'undefined') { try {Object.seal(1); window.ECMAS5 = false;} catch(e) { console.log('You seem to be using ECMAScript 5, this not an issue... Yet.'); window.ECMAS5 = true; } } if (window.ECMAS5 === false) return sealAllExceptConstructor(obj); return obj; }, Seal: function(obj) { /** * Seal an object * @function Seal * @memberof StaticLib * @param {object} obj * @returns {object} * @inner */ if (typeof(obj) === 'function') return obj; if (typeof(obj) === 'object') return Object.seal(obj); if (typeof(window.ECMAS5) === 'undefined') { try { Object.seal(1); window.ECMAS5 = false; } catch(e) { /* developer code start */ console.log('You seem to be using ECMAScript 5, this not an issue... Yet.'); /* developer code end */ window.ECMAS5 = true; } } if (window.ECMAS5 === false) return Object.seal(obj); return obj; }, Freeze: function(obj) { /** * Freeze and object * @function Freeze * @memberof StaticLib * @param {object} dateIs * @returns {object} * @inner */ if (typeof(obj) === 'object') return Object.freeze(obj); if (typeof(window.ECMAS5) === 'undefined') { try { Object.freeze(1); window.ECMAS5 = false; } catch(e) { /* developer code start */ console.log('You seem to be using ECMAScript 5, this not an issue... Yet.'); /* developer code end */ window.ECMAS5 = true; } } if (window.ECMAS5 === false) return Object.freeze(obj); return obj; }, DeepFreeze: function(obj, ignoreList) { /** * Deep freeze an object * @function DeepFreeze * @memberof StaticLib * @param {object} dateIs * @param {object} ignoreList * @returns {object} * @inner */ if (typeof(ignoreList) === 'undefined') ignoreList = []; if (typeof(obj) !== 'object') return null; // Retrieve the property names defined on obj var propNames = Object.getOwnPropertyNames(obj); if ((propNames === null) || (typeof(propNames === 'undefined'))) return obj; // Freeze properties before freezing self propNames.forEach(function(name) { if (name === 'window.Framework.Enum') { /*jshint debug: true */ debugger; } if (ignoreList.indexOf(obj[name]) !== -1) return; // <-- should return not continue, you are in a forEach loop var prop = obj[name]; // Freeze prop if it is an object if ((typeof prop === 'object') && (prop !== null)) { StaticLib.DeepFreeze(prop, ignoreList); } else { StaticLib.Freeze(prop); } }); // Freeze self (no-op if already frozen) return Object.freeze(obj); }, HtmlEncode: function(str) { /** * Encode string as html content * @function HtmlEncode * @memberof StaticLib * @param {object} str * @returns {string} * @inner */ var el = document.createElement('div'); el.innerText = el.textContent = str; str = el.innerHTML; el = null; return str; }, CombineAddressPartsArray: function(arrayObj) { /** * Combine address parts from array of string * @function CombineAddressPartsArray * @memberof StaticLib * @param {array} arrayObj * @returns {string} * @inner */ var errmsg = 'StaticLib.CombineAddressPartsArray expects one argument, an array of strings'; if (typeof(arrayObj) !== 'object') throw new Error(errmsg); if (!(arrayObj.length)) throw new Error(errmsg); var returnStr = ''; var tempData = ''; for (var i = 0; i < arrayObj.length; i++){ tempData = arrayObj[i]; if (tempData === null) continue; if (typeof(tempData) !== 'string') throw new Error(errmsg); tempData = tempData.trim(); if (tempData !== ''){ if (returnStr !== ''){ returnStr = returnStr + ', ' + tempData; } else { returnStr = tempData; } } } return returnStr; }, TodaysDate: function() { /** * Return today's date * @function TodaysDate * @memberof StaticLib * @returns {string} * @inner */ return new Date().toLocaleDateString('en-au'); }, ReplaceAll: function(str0, str1, str2, ignore) { return str0.replace(new RegExp(str1.replace(new RegExp('([\\/\\,\\!\\\\\\^\\$\\{\\}\\[\\]\\(\\)\\.\\*\\+\\?\\|\\<\\>\\-\\&])', 'g'),'\\$&'),(ignore?'gi':'g')),(typeof(str2) === 'string')?str2.replace(new RegExp('\$', 'g'),'$$$$'):str2); }, IsTablet: function() { if ((typeof(window.Framework.V5) !== 'undefined') && (window.Framework.V5 !== null)) { window.StoredIsMobileResult = window.Framework.V5.IsTablet; return window.Framework.V5.IsTablet; } return StaticLib.IsMobile(); }, IsMobile: function() { /** * Check if device is mobile * @function IsMobile * @memberof StaticLib * @returns {boolean} * @inner */ //alert(window.StoredIsMobileResult); if ((typeof(window.Framework.V5) !== 'undefined') && (window.Framework.V5 !== null)) { if (window.StoredIsMobileResult !== undefined) return window.StoredIsMobileResult; window.StoredIsMobileResult = window.Framework.V5.IsMobile; return window.Framework.V5.IsMobile; } var check = false; var mobileTest = (function(browserName){if (new RegExp('(Android|android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino').test(browserName)||new RegExp('1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-').test(browserName.substr(0,4)))return true;}); var temp = navigator.userAgent.toLowerCase(); if (temp.indexOf('android') !== -1) check = true;//return true; if (temp.indexOf('iphone') !== -1) check = true;//return true; if (temp.indexOf('mobile') !== -1) check = true;//return true; if (mobileTest(navigator.userAgent||navigator.vendor||window.opera)) check = true; //window.StoredIsMobileResult = false;//check; /*if (temp.indexOf('android') !== -1) return true; if (temp.indexOf('iphone') !== -1) return true; if (temp.indexOf('mobile') !== -1) return true; if (mobileTest(navigator.userAgent||navigator.vendor||window.opera)) check = true; window.StoredIsMobileResult = (check === true) true : false; */ return check; }, GuessMimeType: function(fileName) { /** * Get mimetype of filename * @function GuessMimeType * @memberof StaticLib * @param fileName * @returns {string} * @inner */ var extension = fileName.toLowerCase(); var type = ''; while (extension.indexOf('.') !== -1) { extension = extension.substring(extension.indexOf('.') + 1); } switch (extension) { case 'csv' : { return 'text/csv'; } case 'txt' : { return 'text/plain'; } case 'zip' : { return 'application/zip'; } case '7z' : { return 'application/x-7z-compressed'; } case 'tar' : { return 'application/x-tar'; } case 'gz' : { return 'application/gzip'; } case 'gif' : { return 'image/gif'; } case 'jpg' : case 'jpeg' : { return 'image/jpeg'; } case 'bmp' : { return 'image/bmp'; } case 'png' : { return 'image/png'; } case 'svg' : { return 'image/svg+xml'; } case 'tif' : case 'tiff' : { return 'image/tiff'; } case 'xls' : { return 'application/vnd.ms-excel'; } case 'xlsx' : { return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; } case 'docxs' : { return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; } case 'ppts' : { return 'application/vnd.ms-powerpoint'; } case 'pptxs' : { return 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; } case 'odps' : { return 'application/vnd.oasis.opendocument.presentation'; } case 'odss' : { return 'application/vnd.oasis.opendocument.spreadsheet'; } case 'odts' : { return 'application/vnd.oasis.opendocument.text'; } case 'docs' : { return 'application/msword'; } case 'pdfs' : { return 'application/pdf'; } } return type; }, GetValues: function(start){ if ((window.GetValueLookup === null) || (typeof(window.GetValueLookup) === 'undefined')) { window.GetValueLookup = []; window.GetValueOrig = []; } if ((window.GetValueDepth === null) || (typeof(window.GetValueDepth) === 'undefined')) window.GetValueDepth = 0; window.GetValueDepth++; var returnObj = {}; var temp = null; /*if (StaticLib.IsPropBaseInstance(start)) { //temp = start.__Props;var keys = this.GetPropList(); temp } else*/ if (StaticLib.IsPropStructInstance(start)) { temp = start.GetValue(); } else { temp = start; } if (temp === null) return null; if (typeof(temp) !== 'object') { window.GetValueDepth--; return temp; } if (temp instanceof Date) { window.GetValueDepth--; return temp; //return StaticLib.DateFormat('Y-m-d H:i:s.u', temp); } if (AppStaticLib.IsAnApp(temp)) { window.GetValueDepth--; return temp; } if ((temp === null) || (typeof(temp) === 'undefined')) { window.GetValueDepth--; return null; } if (typeof(temp.length) !== 'undefined') returnObj = []; var keys = []; if (StaticLib.IsPropBaseInstance(start)) { var pos = window.GetValueLookup.indexOf(start); if (pos !== -1) { window.GetValueDepth--; return window.GetValueOrig[pos]; } window.GetValueLookup.push(start); window.GetValueOrig.push(returnObj); keys = start.GetPropList(); } else { keys = Object.keys(temp); } for (var i = 0; i < keys.length; i++) { if ((typeof(temp[keys[i]]) !== 'function') && (keys[i] !== 'parent')) { returnObj[keys[i]] = StaticLib.GetValues(temp[keys[i]]); } } window.GetValueDepth--; if (window.GetValueDepth === 0) { window.GetValueLookup = null; window.GetValueOrig = null; window.GetValueDepth = null; } return returnObj; }, GetStaticValues: function(start) { var returnObj = {}; var temp = null; /*if (StaticLib.IsPropBaseInstance(start)) { //temp = start.__Props;var keys = this.GetPropList(); temp } else*/ if (StaticLib.IsPropStructInstance(start)) { if ((start.dynamic === true) && (typeof(start.IsNull) === 'function') && (start.IsNull() === true)) return null; temp = start.GetValue(); } else { temp = start; } if (temp === null) return null; if (typeof(temp) !== 'object') return temp; if (temp instanceof Date) return StaticLib.DateFormat('Y-m-d H:i:s.u', temp); if ((temp === null) || (typeof(temp) === 'undefined')) return null; if (typeof(temp.length) !== 'undefined') returnObj = []; var keys = []; var IsPropBase = StaticLib.IsPropBaseInstance(start); if (IsPropBase) { keys = start.GetPropList(); } else { keys = Object.keys(temp); } for (var i = 0; i < keys.length; i++) { if (keys[i] !== 'parent') { if (IsPropBase === false) { if (typeof(temp[keys[i]]) !== 'function') { returnObj[keys[i]] = StaticLib.GetStaticValues(temp[keys[i]]); } } else { var tempValue = temp.FindProp(keys[i]); if ((tempValue !== null) && (typeof(tempValue) !== 'function')) { returnObj[keys[i]] = StaticLib.GetStaticValues(tempValue.GetValue()); } } } } return returnObj; }, JsonEncode: function(data) { if (typeof(data) === 'undefined') return 'null'; if (typeof(data) === 'object') { if (data === null) return 'null'; if (typeof(data.Serialize) === 'function') return data.Serialize(); var values = '{'; var end = '}'; var useStrKeys = true; if (Array.isArray(data) ){ values = '['; end = ']'; useStrKeys = false; } var keys = Object.keys(data); for (var count = 0; count < keys.length; count++) { if (count > 0) values = values + ','; if (useStrKeys) values = values + '"' + keys[count] + '":'; values = values + StaticLib.JsonEncode(data[keys[count]]); } return values + end; } else return JSON.stringify(data); }, MapLookup: function(data) { this.data = data; this.replace = function(value) { if (typeof(this.data[value]) === 'undefined') return value; else return this.data[value]; }; this.replaceAll = function(struct) { var keys = Object.keys(struct); var length = keys.length; for (var i = 0; i < length; i++) { struct[this.replace(keys[i])] = struct[keys[i]]; } }; return this; }, Math: { PreciseAdd: function(val1, val2, precision) { if ((typeof(val1) !== 'number') || (typeof(val2) !== 'number')) throw new Error('StaticLib.Math.PreciseAdd() expects it\'s arguments to be numbers'); if (typeof(precision) !== 'number') precision = 4; //return parseFloat(parseFloat(val1.toFixed(4)) + parseFloat(val2.toFixed(4))); return parseFloat((parseFloat(val1.toFixed(4)) + parseFloat(val2.toFixed(4))).toFixed(4)); }, PreciseMultiply: function(val1, val2) { if ((typeof(val1) !== 'number') || (typeof(val2) !== 'number')) throw new Error('StaticLib.Math.PreciseMultiply() expects it\'s arguments to be numbers'); /* jshint debug: true */debugger; var places1 = 0; var places2 = 0; var power = 0; if (Math.floor(val1) !== val1) places1 = val1.toString().split('.')[1].length; if (Math.floor(val2) !== val2) places2 = val2.toString().split('.')[1].length; power = places1; if (places2 > places1) power = places2; if (power === 0) return val1 * val2; power = Math.pow(10, power); var IntegerMultiply = (Math.round(val1 * power) * Math.round(val2 * power)); //var IntegerString = IntegerMultiply.toString(); //if (new RegExp('^0+[0-9]$').test(IntegerString.split('.')[1])) return Math.round(IntegerMultiply); //if ((IntegerString.indexOf('e') !== -1) && (IntegerString.slice(-1) !== '0')) return val1 * val2; var newValue = (IntegerMultiply/ (power * power)); var newValueString = newValue.toString(); if (newValueString.indexOf('e') !== -1) newValueString = newValueString.split('+e')[0]; if (newValueString.indexOf('.') !== -1) { var newValueDecimalPlace = newValueString.split('.')[1]; //if (parseFloat(newValueDecimalPlace.slice(-2)) > 10) return val1 * val2; if (parseFloat(newValueString).toString() !== newValueString) return val1 * val2; //There are some integers that will always look like floating points... return them so future maths is correct, even if it doesn't DISPLAY correct //decimal place is long enough it may be floating point intstead of rounding if (newValueDecimalPlace.length > 10) { //If the last 5 character still equate to a single digit, it's PROBABLY a floating point issue. if (parseFloat(newValueDecimalPlace.slice(-5)) < 10) return parseFloat(newValueString.substring(0, (newValueString.length-3))); } } return newValue; }, PreciseDivide: function(val1, val2) { if ((typeof(val1) !== 'number') || (typeof(val2) !== 'number')) throw new Error('StaticLib.Math.PreciseDivide() expects it\'s arguments to be numbers'); /* jshint debug: true */debugger; var places1 = 0; var places2 = 0; var power = 0; if (Math.floor(val1) !== val1) places1 = val1.toString().split('.')[1].length; if (Math.floor(val2) !== val2) places2 = val2.toString().split('.')[1].length; power = places1; if (places2 > places1) power = places2; var oldDivide = val1 / val2; if (power === 0) return oldDivide; var oldDivideString = oldDivide.toString(); if (new RegExp('^0+[0-9]$').test(oldDivideString.split('.')[1])) return Math.round(oldDivide); power = Math.pow(10, power); var newDivide = (Math.round(val1 * power) / Math.round(val2 * power)); if (newDivide.toString().length > oldDivideString.length) return oldDivide; return newDivide; }, StringAdd: function(val1, val2) { if ((typeof(val1) !== 'string') || (typeof(val2) !== 'string')) throw new Error('StaticLib.Math.StringAdd() expects it\'s arguments to be strings'); var len1 = val1.length; var len2 = val2.length; var pos1 = val1.indexOf('.'); var pos2 = val2.indexOf('.'); var AfterLength1 = 0; var BeforeLength1 = len1; if (pos2 !== -1) { if (pos1 === -1) { pos1 = len1; val1 = val1 + '.'; } } if (pos1 !== -1) { BeforeLength1 = pos1; AfterLength1 = (len1 - pos1); if (pos2 === -1) { pos2 = len2; val2 = val2 + '.'; len2++; } } var AfterLength2 = 0; var BeforeLength2 = len2; if (pos2 !== -1) { BeforeLength2 = pos2; AfterLength2 = (len2 - pos2); } while (AfterLength2 > AfterLength1) { val1 = val1 + '0'; AfterLength1++; len1++; } while (AfterLength1 > AfterLength2) { val2 = val2 + '0'; AfterLength2++; } while (BeforeLength2 > BeforeLength1) { val1 = '0' + val1; len1++; BeforeLength1++; } while (BeforeLength1 > BeforeLength2) { val2 = '0' + val2; BeforeLength2++; } if ((val1[0] !== '0') && (val2[0] !== '0')) { val1 = '0' + val1; val2 = '0' + val2; len1++; } var carryThe = 0; var value = 0; var newVal = ''; var index = (len1 - 1); while (index >= 0) { if (val1[index] === '.') { index--; newVal = '.' + newVal; continue; } value = parseInt(val1[index]) + parseInt(val2[index]) + carryThe; carryThe = 0; if (value >= 10) { carryThe = Math.floor(value / 10); value = value - (carryThe * 10); } index--; if ((index > 0) || (value > 0)) newVal = value.toString() + newVal; } return newVal; }, RoundNumber: function(value, minPlaces, maxPlaces) { return Number(StaticLib.Math.Round(value, minPlaces, maxPlaces)); }, Round: function(value, minPlaces, maxPlaces) { if (typeof(minPlaces) === 'undefined') { minPlaces = 2;} if (typeof(maxPlaces) === 'undefined') { maxPlaces = minPlaces;} var orgValue = value; if (value < 0) value = (value * -1); var index = -1; var temp = value.toString(); index = temp.indexOf('e'); if (index !== -1) { var places = temp.substring(index+1); places = parseFloat(places); temp = temp.substring(0, index); index = temp.indexOf('.'); temp = temp.slice(0,index)+temp.slice(index+1); while (places !== 0) { if (places > 0) { if (index < temp.length) { index++; } else { temp = temp + '0'; index++; } places--; } else { if (index > 1) { index++; } else { temp = '0' + temp; } places++; } } if (index !== temp.length) temp = temp.slice(0,index)+'.'+temp.slice(index); } index = temp.indexOf('.'); var roundUpUntil = maxPlaces + index; var stopRoundingAt = minPlaces + index; //The value has been modified so use the ORIG value if ((stopRoundingAt >= temp.length) || (index === -1)) return orgValue.toFixed(minPlaces); temp = temp.split(''); temp.splice(index, 1); var i = 0; if (stopRoundingAt >= temp.length) { //temp[stopRoundingAt] = 0; i = (stopRoundingAt - 1); } else { // Convert the last string to numeric temp[stopRoundingAt] = Number(temp[stopRoundingAt]); i = stopRoundingAt; } var newTemp = []; // Round Digits for (i = i; i >= 0; i--) { // Convert the previous string to numeric if (i > 0) temp[(i - 1)] = Number(temp[(i - 1)]); // If over the maxPlaces, Round up if (i >= roundUpUntil) { if (temp[i] > 4) temp[i-1]++; temp = temp.splice(0,roundUpUntil); // If under the maxPlaces, Sum up } else { if (temp[i] >= 10){ temp[i] -= 10; // If the element is not the first, add value if (i > 0) { temp[i-1]++; // If the first element, add new element with 1 } else { temp.splice(0, 0, 1); index++; } } } //console.log(temp); newTemp[i] = temp[i]; } if ((minPlaces > 0) || ((maxPlaces > 0) && (index !== -1))) newTemp.splice(index, 0, '.'); if (orgValue < 0) newTemp.splice(0, 0, '-'); return newTemp.join(''); }, formatCurrency: function(val, decPlaces, symbol, decSeparator, seperateEvery, separator) { if (val === null) return 'N/A'; if ((typeof(symbol) === 'undefined') || (symbol === null)) { symbol = '$'; } else if (typeof(symbol) !== 'string') { throw new Error('StaticLib.Math.formatCurrency expects argument 2 to be a string, the currency symbol to use'); } if (val < 0) { symbol = '-' + symbol; val = val * -1; } return symbol + StaticLib.Math.formatMoney(val, decPlaces, decSeparator, seperateEvery, separator); }, formatMoney: function(val, decPlaces, decSeparator, seperateEvery, separator) { if (val === null) return 'N/A'; if ((typeof(decPlaces) === 'undefined') || (decPlaces === null)) { decPlaces = 2; } else if (typeof(decPlaces) !== 'number') { throw new Error('StaticLib.Math.formatMoney expects argument 2 to be a number, the number of allowed decimal places'); } if ((typeof(decSeparator) === 'undefined') || (decSeparator === null)) { decSeparator = '.'; } else if (typeof(decSeparator) !== 'string') { throw new Error('StaticLib.Math.formatMoney expects argument 3 to be a string, the string or character used to seperate a number from it\'s decimals.'); } if ((typeof(seperateEvery) === 'undefined') || (seperateEvery === null)) { seperateEvery = 3; } else if (typeof(seperateEvery) !== 'number') { throw new Error('StaticLib.Math.formatMoney expects argument 4 to be a number, the number of characters to allow before inserting a seperator'); } if ((typeof(separator) === 'undefined') || (separator === null)) { separator = ','; } else if (typeof(separator) !== 'string') { throw new Error('StaticLib.Math.formatMoney expects argument 5 to be a string, the string or character used to seperate long numbers.'); } //val = Number(val).toFixed(this.DecimalPlaces.GetValue()); val = StaticLib.Math.Round(val*1, decPlaces, decPlaces); if (seperateEvery <= 0) return val; var SeperatorTool = new RegExp('(\\d)(?=(\\d{' + seperateEvery + '})+(?!\\d))', 'g'); var parts = val.toString().split(decSeparator); val = parts[0].replace(SeperatorTool, '$1' + separator); if (parts[1]) val = val + decSeparator + parts[1]; return val; } }, Compare: function(ObjA, ObjB) { // Create arrays of property names if ((ObjA === null) || (typeof(a) === 'undefined')) { if (ObjA === ObjB) return true; return false; } var aProps = Object.keys(ObjA); var bProps = Object.keys(ObjB); // If number of properties is different, // objects are not equivalent if (aProps.length !== bProps.length) return false; var propName = ''; var value = null; for (var i = 0; i < aProps.length; i++) { propName = aProps[i]; value = ObjA[propName]; if ((((value+'') !== value) && ((value+0) !== value))) { if (!StaticLib.Compare(ObjA[propName], ObjB[propName])) return false; } else { // If values of same property are not equal, // objects are not equivalent if (value !== ObjB[propName]) { return false; } } } // If we made it this far, objects // are considered equivalent return true; }, DeveloperMessage: function(msg) { window.Framework.UI.MsgBox({title:'Developer Error A229', message: msg, width: 600, height: 400}); }, SetValues: function(struct, obj) { var items = []; if (StaticLib.IsPropBaseInstance(obj)) items = obj.GetPropList(); else items = Object.keys(obj); items.forEach(function(item){ struct[item] = obj[item]; }); }, SetProps: function(struct, obj, settings) { if (obj === '__construct') return; if (typeof(obj) === 'string') obj = JSON.parse(obj); if ((typeof(struct) !== 'object') || (typeof(obj) !== 'object')) throw new Error('struct or obj IS NOT OBJECT!'); if ((struct === null) || (obj === null)) throw new Error('struct or obj === null'); function type(obj) { return Object.prototype.toString.call(obj).match(/\s\w+/)[0].trim(); } // private function to list all properties function _GetAllProperties(obj){ if (StaticLib.IsPropBaseInstance(obj)) return obj.GetPropList(); var allProps = []; var curr = obj; var funcLoop = function(prop) { if (allProps.indexOf(prop) === -1) allProps.push(prop); }; var props = null; do { props = Object.keys(curr); props.forEach(funcLoop); } while ((curr = StaticLib.Dev.getPrototypeOf(curr))); //EXTRA BRACKETS FOR JSLINT! return allProps; } var items = _GetAllProperties(obj); // var value = null; var autobind = false; var parent = null; var writable = true; var configurable = true; var enumerable = true; var dataErrors = []; if ((typeof(settings) === 'object') && (settings !== null)) { if (typeof(settings.autobind) === 'boolean') autobind = settings.autobind; if ((typeof(settings.parent) === 'object') && (settings.parent !== null)) parent = settings.parent; if (typeof(settings.writable) === 'boolean') writable = settings.writable; if (typeof(settings.configurable) === 'boolean') configurable = settings.configurable; if (typeof(settings.enumerable) === 'boolean') enumerable = settings.enumerable; } if ((autobind) && (typeof(parent) === 'object')) { var propList = _GetAllProperties(struct); propList.forEach(function(item) { if (typeof(struct.FindProp) === 'function') { var temp = struct.FindProp(item); if (temp === null) return; temp.autobind = autobind; temp.parent = parent; temp.writable = writable; temp.configurable = configurable; temp.enumerable = enumerable; } else { struct[item].autobind = autobind; struct[item].parent = parent; struct[item].writable = writable; struct[item].configurable = configurable; struct[item].enumerable = enumerable; } }); } var names = []; items.forEach(function(item) { if (Object.isExtensible(struct)) { if (!(item in struct)) return; } else { if (!(struct.hasOwnProperty(item))) return; } if (StaticLib.StartsWith('__', item)) return; if (item === 'isFinal') return; if ((autobind) && (typeof(parent) === 'object')) { if (typeof(struct.FindProp) === 'function') { var temp = struct.FindProp(item); if (temp === null) return; temp.autobind = autobind; temp.parent = parent; temp.writable = writable; temp.configurable = configurable; temp.enumerable = enumerable; } else { struct[item].autobind = autobind; struct[item].parent = parent; struct[item].writable = writable; struct[item].configurable = configurable; struct[item].enumerable = enumerable; } } var value = null; if (obj[item] !== null) { value = ((typeof(obj[item]) === 'object') && ((obj[item].name === item) && (typeof(obj[item].GetValue) === 'function')))? obj[item].GetValue(true) : obj[item]; //value = obj[item]; } if (StaticLib.IsPropBaseInstance(struct) && (struct.FindProp(item) instanceof window.Framework.DataTypes.ChildPropStruct)) { struct.FindProp(item).SetValue(value, true); } else if (struct[item] === null) { struct[item] = value; //} else if (typeof(struct[item].SetValue) === 'function') { } else if ((typeof(struct[item]) !== 'undefined') && (struct[item].name === item) && (typeof(struct[item]) === 'object') && (typeof(window.Framework.Lib.PropStruct) !== 'undefined') && (StaticLib.InstanceOf(struct[item], window.Framework.Lib.PropStruct)) && (typeof(struct[item].SetValue) === 'function')) { /*if (typeof(value) === 'undefined') { assertdaniel('if the value === undefined then trace the source. You probably have a function missing or something like that'); assertian('if the value === undefined then trace the source. You probably have a function missing or something like that'); dataErrors.push({key: item, value: value}); if (typeof(window.Framework) !== 'undefined') { //if (window.Framework.prop.developer === true) window.Framework.UI.MsgBox({title: 'Developer Error A230', message: 'StaticLib.SetProps(struct, obj) could not set undefined value for \'' + item + '\'. You may be missing an attribute or function.', modal: false}); } }*/ struct[item].MassSet = true; if (!struct[item].SetValue(value)) { if (typeof(window.Framework) !== 'undefined') { assertdaniel(); assertian(); //if (window.Framework.prop.developer === true) window.Framework.UI.MsgBox({title: 'Developer Error A231', message: 'could not set value for key ['+ item +'] for value ['+ value +'] of property type ['+ struct[item].DataType.GetType() +']', modal: false}); } if (window.Framework.prop.developer === true) console.log('StaticLib.SetProps(struct, obj) could not set value for key ['+ item +'] for value ['+ value +'] of property type ['+ struct[item].DataType.GetType() +']'); dataErrors.push({key: item, value: value, error: struct[item].LastError}); } struct[item].MassSet = false; } else { if (StaticLib.IsPropBaseInstance(obj)) { var tempProp = obj.FindProp(item); if ((tempProp.AlwaysSerialize === 1) || (!tempProp.Empty())) { //if (!obj.IsEmpty(item)) { struct[item] = obj[item]; } } else { struct[item] = obj[item]; } } if (typeof(struct.GetProp) === 'function') { var prop = struct.GetProp(item); /*if (struct.GetProp(item).name){ //if (typeof(struct.GetProp(item).Name.GetValue) === 'function') { if (names.indexOf(struct.GetProp(item).name) !== -1) throw new Error('StaticLib.SetProps: Duplicate name(' + struct[item].Name + ')'); names.push(struct.GetProp(item).name); } else { if (names.indexOf(struct[item].Name) !== -1) throw new Error('StaticLib.SetProps: Duplicate name(' + struct[item].Name + ')'); names.push(struct[item].Name); } } else*/ if (typeof(prop.name) !== 'undefined'){ /*if ((struct[item].name !== null) && (typeof(struct[item].name.GetValue) === 'function')) { if (names.indexOf(struct[item].name.GetValue()) !== -1) throw new Error('StaticLib.SetProps: Duplicate name(' + struct[item].name + ')'); names.push(struct[item].name.GetValue()); } else*/ if (prop.name !== null) { if (names.indexOf(prop.name) !== -1) throw new Error('StaticLib.SetProps: Duplicate name(' + prop.name + ')'); names.push(prop.name); } else { throw new Error('Developer Error A232: the name should not be null and must be defined'); } } } }); if (typeof(window.Framework) !== 'undefined') { if (typeof(window.Framework.prop) === 'undefined') return; if (window.Framework.prop.developer === false) return; if (dataErrors.length > 0) { StaticLib.SetModal('gridbox', {title: 'Data Errors found', message: 'Data errors have been detected whilst loading.', messageAfter: 'You should review your data source', Grid:{ DataForBinding: dataErrors, ColLayout: [ {Caption:'Property', Name: 'key', NeverWrap: true, ColDataType: window.Framework.Enum.Controls.Grid.ColDataTypes.STRING}, {Caption:'Error', Name: 'error', ColDataType: window.Framework.Enum.Controls.Grid.ColDataTypes.STRING} ] }}); } } }, Crypto: { md5: { lib: { md5cycle: function(x, k) { var a = x[0], b = x[1], c = x[2], d = x[3]; a = StaticLib.Crypto.md5.lib.ff(a, b, c, d, k[0], 7, -680876936); d = StaticLib.Crypto.md5.lib.ff(d, a, b, c, k[1], 12, -389564586); c = StaticLib.Crypto.md5.lib.ff(c, d, a, b, k[2], 17, 606105819); b = StaticLib.Crypto.md5.lib.ff(b, c, d, a, k[3], 22, -1044525330); a = StaticLib.Crypto.md5.lib.ff(a, b, c, d, k[4], 7, -176418897); d = StaticLib.Crypto.md5.lib.ff(d, a, b, c, k[5], 12, 1200080426); c = StaticLib.Crypto.md5.lib.ff(c, d, a, b, k[6], 17, -1473231341); b = StaticLib.Crypto.md5.lib.ff(b, c, d, a, k[7], 22, -45705983); a = StaticLib.Crypto.md5.lib.ff(a, b, c, d, k[8], 7, 1770035416); d = StaticLib.Crypto.md5.lib.ff(d, a, b, c, k[9], 12, -1958414417); c = StaticLib.Crypto.md5.lib.ff(c, d, a, b, k[10], 17, -42063); b = StaticLib.Crypto.md5.lib.ff(b, c, d, a, k[11], 22, -1990404162); a = StaticLib.Crypto.md5.lib.ff(a, b, c, d, k[12], 7, 1804603682); d = StaticLib.Crypto.md5.lib.ff(d, a, b, c, k[13], 12, -40341101); c = StaticLib.Crypto.md5.lib.ff(c, d, a, b, k[14], 17, -1502002290); b = StaticLib.Crypto.md5.lib.ff(b, c, d, a, k[15], 22, 1236535329); a = StaticLib.Crypto.md5.lib.gg(a, b, c, d, k[1], 5, -165796510); d = StaticLib.Crypto.md5.lib.gg(d, a, b, c, k[6], 9, -1069501632); c = StaticLib.Crypto.md5.lib.gg(c, d, a, b, k[11], 14, 643717713); b = StaticLib.Crypto.md5.lib.gg(b, c, d, a, k[0], 20, -373897302); a = StaticLib.Crypto.md5.lib.gg(a, b, c, d, k[5], 5, -701558691); d = StaticLib.Crypto.md5.lib.gg(d, a, b, c, k[10], 9, 38016083); c = StaticLib.Crypto.md5.lib.gg(c, d, a, b, k[15], 14, -660478335); b = StaticLib.Crypto.md5.lib.gg(b, c, d, a, k[4], 20, -405537848); a = StaticLib.Crypto.md5.lib.gg(a, b, c, d, k[9], 5, 568446438); d = StaticLib.Crypto.md5.lib.gg(d, a, b, c, k[14], 9, -1019803690); c = StaticLib.Crypto.md5.lib.gg(c, d, a, b, k[3], 14, -187363961); b = StaticLib.Crypto.md5.lib.gg(b, c, d, a, k[8], 20, 1163531501); a = StaticLib.Crypto.md5.lib.gg(a, b, c, d, k[13], 5, -1444681467); d = StaticLib.Crypto.md5.lib.gg(d, a, b, c, k[2], 9, -51403784); c = StaticLib.Crypto.md5.lib.gg(c, d, a, b, k[7], 14, 1735328473); b = StaticLib.Crypto.md5.lib.gg(b, c, d, a, k[12], 20, -1926607734); a = StaticLib.Crypto.md5.lib.hh(a, b, c, d, k[5], 4, -378558); d = StaticLib.Crypto.md5.lib.hh(d, a, b, c, k[8], 11, -2022574463); c = StaticLib.Crypto.md5.lib.hh(c, d, a, b, k[11], 16, 1839030562); b = StaticLib.Crypto.md5.lib.hh(b, c, d, a, k[14], 23, -35309556); a = StaticLib.Crypto.md5.lib.hh(a, b, c, d, k[1], 4, -1530992060); d = StaticLib.Crypto.md5.lib.hh(d, a, b, c, k[4], 11, 1272893353); c = StaticLib.Crypto.md5.lib.hh(c, d, a, b, k[7], 16, -155497632); b = StaticLib.Crypto.md5.lib.hh(b, c, d, a, k[10], 23, -1094730640); a = StaticLib.Crypto.md5.lib.hh(a, b, c, d, k[13], 4, 681279174); d = StaticLib.Crypto.md5.lib.hh(d, a, b, c, k[0], 11, -358537222); c = StaticLib.Crypto.md5.lib.hh(c, d, a, b, k[3], 16, -722521979); b = StaticLib.Crypto.md5.lib.hh(b, c, d, a, k[6], 23, 76029189); a = StaticLib.Crypto.md5.lib.hh(a, b, c, d, k[9], 4, -640364487); d = StaticLib.Crypto.md5.lib.hh(d, a, b, c, k[12], 11, -421815835); c = StaticLib.Crypto.md5.lib.hh(c, d, a, b, k[15], 16, 530742520); b = StaticLib.Crypto.md5.lib.hh(b, c, d, a, k[2], 23, -995338651); a = StaticLib.Crypto.md5.lib.ii(a, b, c, d, k[0], 6, -198630844); d = StaticLib.Crypto.md5.lib.ii(d, a, b, c, k[7], 10, 1126891415); c = StaticLib.Crypto.md5.lib.ii(c, d, a, b, k[14], 15, -1416354905); b = StaticLib.Crypto.md5.lib.ii(b, c, d, a, k[5], 21, -57434055); a = StaticLib.Crypto.md5.lib.ii(a, b, c, d, k[12], 6, 1700485571); d = StaticLib.Crypto.md5.lib.ii(d, a, b, c, k[3], 10, -1894986606); c = StaticLib.Crypto.md5.lib.ii(c, d, a, b, k[10], 15, -1051523); b = StaticLib.Crypto.md5.lib.ii(b, c, d, a, k[1], 21, -2054922799); a = StaticLib.Crypto.md5.lib.ii(a, b, c, d, k[8], 6, 1873313359); d = StaticLib.Crypto.md5.lib.ii(d, a, b, c, k[15], 10, -30611744); c = StaticLib.Crypto.md5.lib.ii(c, d, a, b, k[6], 15, -1560198380); b = StaticLib.Crypto.md5.lib.ii(b, c, d, a, k[13], 21, 1309151649); a = StaticLib.Crypto.md5.lib.ii(a, b, c, d, k[4], 6, -145523070); d = StaticLib.Crypto.md5.lib.ii(d, a, b, c, k[11], 10, -1120210379); c = StaticLib.Crypto.md5.lib.ii(c, d, a, b, k[2], 15, 718787259); b = StaticLib.Crypto.md5.lib.ii(b, c, d, a, k[9], 21, -343485551); x[0] = StaticLib.Crypto.md5.lib.add32(a, x[0]); x[1] = StaticLib.Crypto.md5.lib.add32(b, x[1]); x[2] = StaticLib.Crypto.md5.lib.add32(c, x[2]); x[3] = StaticLib.Crypto.md5.lib.add32(d, x[3]); }, cmn: function (q, a, b, x, s, t) { a = StaticLib.Crypto.md5.lib.add32(StaticLib.Crypto.md5.lib.add32(a, q), StaticLib.Crypto.md5.lib.add32(x, t)); return StaticLib.Crypto.md5.lib.add32((a << s) | (a >>> (32 - s)), b); }, ff: function(a, b, c, d, x, s, t) { return StaticLib.Crypto.md5.lib.cmn((b & c) | ((~b) & d), a, b, x, s, t); }, gg: function(a, b, c, d, x, s, t) { return StaticLib.Crypto.md5.lib.cmn((b & d) | (c & (~d)), a, b, x, s, t); }, hh: function(a, b, c, d, x, s, t) { return StaticLib.Crypto.md5.lib.cmn(b ^ c ^ d, a, b, x, s, t); }, ii: function(a, b, c, d, x, s, t) { return StaticLib.Crypto.md5.lib.cmn(c ^ (b | (~d)), a, b, x, s, t); }, md51: function(s) { // Converts the string to UTF-8 'bytes' when necessary if (new RegExp('[\x80-\xFF]').test(s)) { s = unescape(encodeURI(s)); } //var txt = ''; var n = s.length, state = [1732584193, -271733879, -1732584194, 271733878], i; for (i = 64; i <= s.length; i += 64) { StaticLib.Crypto.md5.lib.md5cycle(state, StaticLib.Crypto.md5.lib.md5blk(s.substring(i - 64, i))); } s = s.substring(i - 64); var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; for (i = 0; i < s.length; i++) tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3); tail[i >> 2] |= 0x80 << ((i % 4) << 3); if (i > 55) { StaticLib.Crypto.md5.lib.md5cycle(state, tail); for (i = 0; i < 16; i++) tail[i] = 0; } tail[14] = n * 8; StaticLib.Crypto.md5.lib.md5cycle(state, tail); return state; }, md5blk: function(s) { /* I figured global was faster. */ var md5blks = [], i; /* Andy King said do it this way. */ for (i = 0; i < 64; i += 4) { md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24); } return md5blks; }, hex_chr: '0123456789abcdef'.split(''), rhex: function(n) { var s = '', j = 0; for (; j < 4; j++) { s += StaticLib.Crypto.md5.lib.hex_chr[(n >> (j * 8 + 4)) & 0x0F] + StaticLib.Crypto.md5.lib.hex_chr[(n >> (j * 8)) & 0x0F]; } return s; }, hex: function(x) { for (var i = 0; i < x.length; i++) { x[i] = StaticLib.Crypto.md5.lib.rhex(x[i]); } return x.join(''); }, /* this function is much faster, so if possible we use it. Some IEs are the only ones I know of that need the idiotic second function, generated by an if clause. */ add32: function(a, b) { return (a + b) & 0xFFFFFFFF; } }, encode: function (s) { return StaticLib.Crypto.md5.lib.hex(StaticLib.Crypto.md5.lib.md51(s)); }, validate: function(md5sum, value) { var value2 = StaticLib.Crypto.md5.encode(value); return (value === value2); } // StaticLib.Crypto } }, IsAssociativeArray: function(value) { return ((typeof(value) === 'object') && (value !== null) && (typeof(value.length) === 'undefined')); }, IsArray: function(value) { if (StaticLib.Empty(value)) return false; return (value.length >= 0); }, IsNumeric: function(value, optStrict, optCurrency) { //Deal with Defaults and Negatives FIRST if (typeof(optCurrency) === 'undefined') optCurrency = 'Dollar'; if (typeof(optStrict) === 'undefined') optStrict = false; if (typeof(optStrict) !== 'boolean') throw new Error('Strict must be set to Boolean type: True or False'); if ((optCurrency === 'AUD') || (optCurrency === 'USD')) optCurrency = 'Dollar'; //UNIT TEST BEGINS if (typeof(value) === 'number') return true; if (StaticLib.Empty(value)) return false; if (typeof(value) !== 'string') return false; //Does it start with $, +, -, -$ or +$...? It is allowed, but we temporaily remove it to do later tests value = value.replace(/^-\$|^\+\$|^\$|^-|^\+/,''); //Change our format test based on submitted Currency... switch (optCurrency) { case 'Dollar': { var afterDec = ' + '; if (!optStrict) afterDec = '*'; var test = '^[0-9]{1,3}(\,[0-9]{3})+(\.[0-9]' + afterDec + ')?$'; if (new RegExp(test).test(value)) value = value.replace(new RegExp('\,','g'), ''); break; } default: { //And if we can't find it, throw an error throw new Error('Currency not implemented [' +optCurrency+ ']'); } } //Check it only contains acceptable numbers an dots if (new RegExp('[^0-9\.]').test(value)) return false; //Check if it has a dot... var index = value.indexOf('.'); if (index >= 0) { //Don't allow it to be the last char if we are being strict if ((optStrict) && (index === (value.length - 1))) return false; //Or ALWAYS deny it if it includes multiple dots if (value.split('.').length > 2) return false; //You have completed all of our tests!... but your princess is in another castle. return true; } //If you didn't have a dot, and the only other characters you have are numbers... you are OBVIOUSLY A NUMBER! return true; }, SetJSONArray: function(jsonData) { if ((typeof(jsonData) === 'undefined') || (StaticLib.Empty(jsonData))) return null; if ((typeof(jsonData) !== 'object') && (!StaticLib.IsJSONString(jsonData))) { window.Framework.UI.MsgBox({title: 'Error', message: 'Grid.BuildTableRows(jsonData) is not a valid JSON format', modal: false}); return null; } // check to see if it is a string and if so, the syntax length we are looking for is [{'a':1}] which = 9 if (typeof(jsonData) === 'string') { if (jsonData.length < 9) return null; if (!StaticLib.IsJSONArray(jsonData)) jsonData = '[' + jsonData + ']'; } else if (typeof(jsonData) === 'object') { if ((jsonData.length) || (jsonData.length > 0)) return jsonData; var arrayConstructor = [].constructor; if (jsonData.constructor !== arrayConstructor) { // need to make it an array object var t = []; t.push(jsonData); jsonData = t; } } return jsonData; }, IsJSONArray: function(str) { try { if ((typeof(str) === 'object') && (str.length)) return true; if ((typeof(str) === 'string') && (str.length < 2)) return false; // !== [] if ((str.substr(0, 1) !== '[') || (str.substr((str.length - 1), 1) !== ']')) return false; // check the first and last char if = to [] JSON.parse(str); return true; } catch (e) { return false; } return false; }, IsJSONString: function(str) { if (typeof(str) !== 'string') return false; if (str.length === 0) return false; try { JSON.parse(str); } catch (e) { return false; } return true; }, mobilecheck:function() { return jQuery.browser.mobile; }, escapeHTML:function(t) { return jQuery('
').text(t).html(); }, escapeAttr:function(t) { var txt = StaticLib.escapeHTML(t); // List of HTML entities for escaping. var htmlEscapes = { '&': '&', '<': '<', '>': '>', '"': '"', '\'': ''', '/': '/' }; // Regex containing the keys listed immediately above. var htmlEscaper = new RegExp('[&<>"\'\/]','g'); return txt.replace(htmlEscaper, function(match) { return htmlEscapes[match]; }); }, ObjectToInt: function(obj, unsigned, def) { if (obj === null) return def; if (typeof(unsigned) === 'undefined') unsigned = false; if (typeof(def) === 'undefined') def = 0; var val = def; if (typeof(obj) === 'number') { val = obj; } else { if (parseInt(obj)) { val = parseInt(obj); } } if (unsigned) { if (val < 0) return def; } return val; }, ObjectToFloat: function(obj, unsigned, def) { if (typeof(def) === 'undefined') def = 0; if (typeof(unsigned) === 'undefined') unsigned = false; if (obj === null) return def; var val = def; if (typeof(obj) === 'number') { val = obj; } else { if (parseFloat(obj)) { val = parseFloat(obj); } else { return def; } } if (unsigned) { if (val < 0) return def; } return val; }, StringToFloat: function(obj, thouSeparator) { var value = String(obj).replace(new RegExp('[^-0-9\.]+','g'),''); return StaticLib.ObjectToFloat(value, false, 0); }, ObjectToPercentage:function(obj) { var value = StaticLib.StringToFloat(obj); return value+ '%'; }, ObjectToCurrency: function(obj, decimalPlaces) { decimalPlaces = (typeof(decimalPlaces) !== 'undefined') ? decimalPlaces : 2; var floatValue = StaticLib.ObjectToFloat(obj, false, 0); var firstChar = ('' + floatValue).substring(0,1); if (firstChar === '-') { return '-$' + floatValue.formatMoney().replace('-',''); } else{ return '$' + floatValue.formatMoney(); } }, BytesToSize: function(bytes,decimals) { if (bytes === 0) return '0 Bytes'; var k = 1000; var dm = decimals + 1 || 3; var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; var i = Math.floor(Math.log(bytes) / Math.log(k)); return (bytes / Math.pow(k, i)).toPrecision(dm) + ' ' + sizes[i]; }, // Empty() tests if the value of the object is null or '' // it tests the javascript types and conditionally tests against them and returns accordingly // the final test is a string length test Empty: function(obj) { if (obj === null) return true; // if it is null, if (typeof(obj) === 'undefined') return true; // it is empty if undefined if (typeof(obj) === 'object') { if (obj === null) return true; if (obj instanceof jQuery) { if (obj.length === 0) return true; return false; } if (!Array.isArray(obj)) return false; // it is an object //WE ARE AN Array if (obj.length !== Object.keys(obj).length) return false; //we are actually an associative array } if (typeof(obj) === 'boolean') return false; // it is an boolean if (typeof(obj) === 'number') return false; // it is an number if (typeof(obj) === 'function') return false; // it is an function // ECMAScript 6 if (typeof(obj) === 'symbol') return false; // it is an symbol // /*COMMENTED BY DANIEL 13/7/2020*/return (obj.length > 0)?false:true; //return (obj.length > 0)?true:false; return (obj.length > 0)?false:true; }, ObjectToBoolean: function(obj) { if (typeof(obj) === 'undefined') return false; if (obj === null) return false; // true for Empty function to work if (typeof(obj) === 'boolean' ) return obj; // false for Empty function to work //if the value is less than or equal to 0 return false if (typeof obj === 'number') return (obj > 0) ? true: false; // for Empty // if the object is a string type, check the value it may contain one of the values we consider to be a boolean if (typeof obj === 'string') { if (obj.toLowerCase() === 'true') return true; if (obj.toLowerCase() === 'false') return false; if (obj.toLowerCase() === 'yes') return true; if (obj.toLowerCase() === 'no') return false; if (obj.toLowerCase() === 'y') return true; if (obj.toLowerCase() === 'n') return false; if (obj.toLowerCase() === '1') return true; if (obj.toLowerCase() === '0') return false; if (obj.toLowerCase() === '') return false; } // if (obj.length === 0) return false; return false; }, IsBoolean: function(bool) { if (typeof(bool) === 'boolean') { return true; } else { return false; } }, IsString: function(str) { //check if undefined or not a boolean if (str === undefined) return false; if (typeof(str)!== 'string') return false; return true; }, IsFloat: function(value, unsigned) { // check the unsigned value first. If value < 0 and unsigned is true, return false if ((typeof(unsigned) === 'boolean') && (unsigned === true) && (Number(value) < 0)) return false; return ((value === Number(value)) && ((value % 1) !== 0)); }, IsInt: function(n, unsigned) { //check if undefined or not a boolean unsigned = ((unsigned === undefined) && (!StaticLib.ObjectToBoolean(unsigned))) ? false : unsigned; //check is a number, value can be positive or negative if (isNaN(n)) return false; //if unsigned is true value cannot be less than 0 if ( (unsigned) && (n < 0) ) return false; return true; }, IsHTMLElement: function(o){ return ( (typeof(window.HTMLElement) === 'object') ? ((o instanceof window.HTMLElement) === true) : ((o) && (typeof(o) === 'object') && (o !== null) && (o.nodeType === 1) && (typeof o.nodeName === 'string')) ); }, GetPropsList: function(data) { var keys = null; if (StaticLib.IsPropBaseInstance(data)) { keys = data.GetPropList(); } else { keys = Object.keys(data); } return keys; }, IsPropBaseInstance: function(obj) { if (typeof(window.Framework.Lib) === 'undefined') return false; if (typeof(window.Framework.Lib.PropsBaseV3) === 'undefined') return false; if (obj === null) return false; if (typeof(obj) === 'undefined') return false; if (!obj.constructor) return false; if (obj.constructor === Function) return false; if (obj.constructor === String) return false; if (obj.constructor === Boolean) return false; if (obj.constructor === Number) return false; if (obj.constructor === Object) return false; if (obj.constructor === Array) return false; if (obj.constructor === Date) return false; if (obj instanceof window.Framework.Lib.PropsBaseV3) return true; if (typeof(window.AppBase) !== 'undefined') { if (obj instanceof window.AppBase) return false; } if (obj.constructor === window.Framework.Lib.PropStruct) return false; if (obj.constructor === window.Framework.Lib.PropsBaseV3) return true; if (obj.constructor === window.BaseType) return false; if (StaticLib.IsHTMLElement(obj)) return false; if (obj.constructor.prototype) return StaticLib.IsPropStructInstance(obj.constructor.prototype); }, IsPropStructInstance: function(obj) { if (obj === null) return false; if (typeof(obj) === 'undefined') return false; if (!obj.constructor) return false; if (obj.constructor === Function) return false; if (obj.constructor === String) return false; if (obj.constructor === Boolean) return false; if (obj.constructor === Number) return false; if (obj.constructor === Object) return false; if (obj.constructor === Array) return false; if (obj.constructor === Date) return false; if (obj instanceof window.Framework.Lib.PropsBaseV3) return false; if (typeof(window.AppBase) !== 'undefined') { if (obj instanceof window.AppBase) return false; } if (obj.constructor === window.Framework.Lib.PropStruct) return true; if (obj.constructor === window.BaseType) return false; if (StaticLib.IsHTMLElement(obj)) return false; if (obj.constructor.prototype) { if (obj.constructor.prototype === obj) return false; return StaticLib.IsPropStructInstance(obj.constructor.prototype); } }, isDisabled: function(formItem) { if (typeof(formItem) === 'undefined') return; formItem = jQuery(formItem); return formItem.is(':disabled'); }, disableItem: function(formItem) { if (typeof(formItem) === 'undefined') return; formItem = jQuery(formItem); var ref = formItem.tagName; if (typeof(ref) === 'undefined') { if (formItem.length === 0) return; ref = formItem.get(0).tagName; } switch(ref) { case 'A': formItem.addClass('disabled'); break; default: formItem.prop('disabled', true); break; } }, markButtonLoading: function(formItem) { formItem = jQuery(formItem); StaticLib.disableItem(formItem); formItem.addClass('btn-loading'); formItem.prepend(''); }, unmarkButtonLoading: function(formItem) { formItem = jQuery(formItem); StaticLib.enableItem(formItem); formItem.removeClass('btn-loading'); formItem.find('.progress-icon').remove(); }, markInputLoading: function(formItem) { formItem = jQuery(formItem); //StaticLib.disableItem(formItem); if (formItem.hasClass('element-loading')) { return; } formItem.addClass('element-loading'); var html = '
'; formItem.after(html); }, unmarkInputLoading: function(formItem) { formItem = jQuery(formItem); //StaticLib.enableItem(formItem); formItem.removeClass('element-loading'); formItem.next('.element-loading-container').remove(); }, enableItem: function(formItem) { /** * Enable form item * @function componentToHex * @memberof StaticLib * @param {number} c * @returns {string} * @inner */ if (typeof(formItem) === 'undefined') return; if (formItem.length === 0) return; formItem = jQuery(formItem); switch(formItem.get(0).tagName) { case 'A': { formItem.removeClass('disabled'); break; } default: { formItem.prop('disabled', false); break; } } }, componentToHex: function (c) { /** * Convert component to hex * @function componentToHex * @memberof StaticLib * @param {number} c * @returns {string} * @inner */ var hex = c.toString(16); return hex.length === 1 ? '0' + hex : hex; }, rgbToHex: function(r, g, b) { /** * Change rgb colors to hex * @function rgbToHex * @memberof StaticLib * @param {number} r * @param {number} g * @param {number} b * @returns {string} * @inner */ return StaticLib.componentToHex(r) + StaticLib.componentToHex(g) + StaticLib.componentToHex(b); }, combineFunctions: function(func1, func2) { /** * Combine two functions * @function combineFunctions * @memberof StaticLib * @param {function} func1 * @param {function} func2 * @returns {function} * @inner */ var type1 = typeof(func1); var type2 = typeof(func2); var handler = function(){}; if (type1 !== 'function') { //func2 IS function and func1 is not... RETURN FUNC2! if (type2 === 'function') return func2; //Neither are functions... RETURN A FUNCTION! return handler; } else { //func1 IS function and func2 is not... RETURN FUNC1! if (type2 !== 'function') return func1; //BOTH ARE FUNCTIONS! return jQuery.proxy(function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) { this.func1(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); this.func2(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); }, {func1:func1, func2:func2}); } } }; //extend current objects /* * OBSOLETE CODE 20160225 * * DELETE AFTER 20160229 Function.prototype.inheritsFrom = function(parentClassOrObject) { if (parentClassOrObject.constructor === 'function') { //Normal Inheritance this.prototype = new parentClassOrObject(); this.prototype.constructor = this; this.prototype.parent = parentClassOrObject.prototype; } else { //Pure Virtual Inheritance this.prototype = parentClassOrObject; this.prototype.constructor = this; this.prototype.parent = parentClassOrObject; } return this; }; */ Number.prototype.formatMoney = function(decPlaces, thouSeparator, decSeparator) { var n = this; return n.formatUI(decPlaces, thouSeparator, decSeparator); }; Number.prototype.formatUI = function(decPlaces, thouSeparator, decSeparator) { var n = this; decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces; decSeparator = decSeparator === undefined ? '.' : decSeparator; thouSeparator = thouSeparator === undefined ? ',' : thouSeparator; var sign = n < 0 ? '-' : ''; var i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + ''; var j = (j = i.length) > 3 ? j % 3 : 0; return sign + (j ? i.substr(0, j) + thouSeparator : '') + i.substr(j).replace(new RegExp('(\d{3})(?=\d)','g'), '$1' + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : ''); }; StaticLib.DeepFreeze(StaticLib); StaticLib.DeepSeal(StaticLib);