'use strict'; debugger; /* jshint quotmark: single, undef: true, eqnull: true, shadow: false, unused: false, globalstrict: true, curly: false, funcscope: true, strict: true, eqeqeq: true */ /* global __METHOD__, __FILE__, __LINE__, window, StaticLib, jQuery, WindowStruct, DependencyLoader, LoadingScreen, assert, atob, document, AppStaticLib, TaskManagerControl, setTimeout, V5Action */ /* global assertgroup, LoadingScreen, window, jQuery, AppStaticLib, WindowLib, StaticLib, document, DependencyLoader, ENUM_DLLKEYS_LAYOUTMANAGER, LayoutManager, WindowStruct, atob, Notification, VersionStruct */ /* developer code start */ /* global console, alert */ /* developer code end */ if (typeof(window.Framework) === 'undefined') throw new Error('Action requires the framework prior to loading'); if (typeof(window.Framework.Methods) === 'undefined') window.Framework.Methods = {}; /* developer code start */ if (typeof(window.Framework.FileLoading) === 'undefined') window.Framework.FileLoading = []; window.Framework.FileLoading.push('action'); /* developer code end */ var _callerList = []; var _callbackList = []; var _controlList = []; var _registeredList = []; var _registeredApps = []; /* jshint ignore:start */ var pumpKeyA = 'TXN23xQoAZutiQDqZ1Xr6ybI4vMHmaAE4KOO';var pumpKeyB = '8lcB6BdbeIil74Y1RWkiVItVLyq87zwOpxet';/* jshint ignore:end */ window.Framework.EmptyCallback = function() { }; window.Framework.DeregisterThisApp = function(thisApp) { var i = _callerList.indexOf(thisApp); if (i !== -1) _callerList[i] = null; }; window.Framework.InformApps = function(taskId, uniqueID, data){ var AppList = _GetAppListForTaskID(taskId, uniqueID); for (var i = 0; i < AppList.length; i++){ try { if ((typeof(AppList[i].App.IsClosed) === 'function') && (AppList[i].App.IsClosed() === true)) continue; AppList[i].InformThis(data); } catch(e) { /* jshint ignore: line */ /* developer code start */ if (typeof(window.Framework) === 'undefined') return; if ((typeof(window.Framework.prop) === 'undefined') || (window.Framework.prop.developer === false)) return; console.log(e.message); /* developer code end */ } } }; window.Framework.RegisterAppForEvents = function(App, FunctionName, taskId, uniqueId){ //this if (typeof(uniqueId) === 'undefined') uniqueId = null; var expects = 'window.Framework.RegisterApp expects 3 mandatory arguments, '; if (AppStaticLib.IsAnApp(App) === false) throw new Error(expects + 'the first an App Instance.'); if ((typeof(FunctionName) !== 'string') || (typeof(App[FunctionName]) !== 'function')) throw new Error(expects + 'the second the Name of a Function on that App.'); if (typeof(taskId) !== 'string') throw new Error(expects + 'the third a string uniquely identifying the type of task this wishes to be informed about.'); var type = typeof(uniqueId); if ((uniqueId !== null) && (type !== 'string') && (type !== 'number')) throw new Error(expects + 'the fourth (optional) argument, is an id (string or numeric) identifying a particular record.'); //Get this Task var row = _registeredList[taskId]; //If the task doesn't exist, Add It if (typeof(row) === 'undefined') _registeredList[taskId] = []; //If the ID for that task doesn't exist, Add It if (typeof(_registeredList[taskId][uniqueId]) === 'undefined') _registeredList[taskId][uniqueId] = []; var context = { App: App, FunctionName: FunctionName, InformThis: WindowLib.GetOwnMethod(App, FunctionName) }; //Then Add this App (and related info) to the list of things caring about that task _registeredList[taskId][uniqueId].push(context); //If this App isn't registered for anything... Add it if (typeof(_registeredApps[App.prop.handle]) === 'undefined') _registeredApps[App.prop.handle] = []; //Then push this Task on the list of things it cares about. _registeredApps[App.prop.handle].push({taskId:taskId, uniqueId:uniqueId}); }; window.Framework.DeregisterAppEvents = function(App) { //this var TaskList = _registeredApps[App.prop.handle]; var IdList = null; //If the App is on the list of registered Apps if (typeof(TaskList) === 'undefined') return; //It is registered for 1 or more Tasks var registeredLocation, suspect, position; for (var j = 0; j < TaskList.length; j++) { //So for each Task IdList = TaskList[j]; //Find the list of Apps registered for that Task registeredLocation = _registeredList[IdList.taskId][IdList.uniqueId]; suspect = null; position = -1; for (var i = 0; i < registeredLocation.length; i++) { suspect = registeredLocation[i]; //Then Find the App... if (suspect.App === App) { position = i; break; } } //And if found... if (position !== -1) { //Remove the row associated with that App from the list of Tasks. registeredLocation.splice(position, 1); } } //Then with it removed from all Tasks... //Delete it from the list of Registered Apps delete _registeredApps[App.prop.handle]; }; var _GetAppListForTaskID = function(taskId, uniqueId){ if (typeof(_registeredList[taskId]) === 'undefined') return []; var LookingAtAnyChange = []; var LookingAtThisID = []; if (typeof(_registeredList[taskId][null]) !== 'undefined') LookingAtAnyChange = _registeredList[taskId][null]; if ((uniqueId !== null) && (typeof(uniqueId) !== 'undefined') && (typeof(_registeredList[taskId][uniqueId]) !== 'undefined')) { LookingAtThisID = _registeredList[taskId][uniqueId]; } else { return LookingAtAnyChange; } return LookingAtAnyChange.concat(LookingAtThisID); }; var _ProcessOne = function(caller, data, errorList, thisApp, errorHandler) { var temp = data; try { /* developer code start */ /* if (typeof(window.Framework) !== 'undefined') { if (typeof(window.Framework.prop) !== 'undefined') { if (window.Framework.prop.developer === true) { console.log('ProcessOne() processing one'); console.log(data); } } } */ /* developer code end */ if ((typeof(data) === 'string') && (StaticLib.IsJSONString(data) === true)) data = JSON.parse(data); // check to see if the data is a json string if ((typeof(data) !== 'object') || (data === null)) return; var _Unflatten = function(data) { assertgroup('compiler', 'debug your compiler stuff'); if (typeof(data.a) !== 'undefined') { // TODO: Compiler data.a (a is a compiled word) if (data.a !== '') data.id = _callerList[data.a]; // TODO: Compiler data.a (a is a compiled word) delete data.a; // TODO: Compiler data.a (a is a compiled word) } if (typeof(data.b) !== 'undefined') { // TODO: Compiler data.b (b is a compiled word) if (data.b !== '') data.method = _callbackList[data.b]; // TODO: Compiler data.b (b is a compiled word) delete data.b; // TODO: Compiler data.b (b is a compiled word) } if (typeof(data.c) !== 'undefined') { // TODO: Compiler data.c (c is a compiled word) if (data.c !== '') data.controlID = _controlList[data.c]; // TODO: Compiler data.c (c is a compiled word) delete data.c; // TODO: Compiler data.c (c is a compiled word) } return data; }; var msg = _Unflatten(data); var loader; var NewApp; if (typeof(msg[pumpKeyA]) !== 'undefined') { if (msg.iserror === 1) errorList.count++; var eventtype = msg[pumpKeyA]; if ((eventtype === /*window.Framework.Enum.EventTypes.APPEVENT*/ 7) || ((typeof(window.Framework.Enum) !== 'undefined') && (typeof(window.Framework.Enum.EventTypes) !== 'undefined') && (eventtype === window.Framework.Enum.EventTypes.APPEVENT_NOLOGIN) )) { /* developer code start */ if (typeof(msg.desktop) !== 'undefined') { var target = {id:'desktop'}; var d = document.getElementById(target.id); if (d !== null) d.innerHTML = 'loading'; assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); var task = { Type: window.LoadingScreenTaskTypes.app, TaskID: 'layoutmanager', TaskDescription: 'Loading Desktop Layout', Priority: 1 }; if (window.Framework.prop.Loader === null) { window.Framework.prop.Loader = new LoadingScreen({ TaskList:[task] }); } else { window.Framework.prop.Loader.AddTask(task); } loader = new DependencyLoader(ENUM_DLLKEYS_LAYOUTMANAGER, jQuery.proxy(function() { var json = null; if (typeof(msg.desktop) === 'string') { json = JSON.parse(msg.desktop); } else { json = msg.desktop; } //Create and Render a new Layout Manager var lm = new LayoutManager(this.id); lm.prop._layout = json; lm.Render(); if (window.Framework.prop.Loader !== null) window.Framework.prop.Loader.CompleteTask('layoutmanager'); }, target)); } /* developer code end */ if (typeof(msg.app) !== 'undefined') { //alert('OPENING: ' + msg.layout); var isFrameworkApp = false; var TypeID = window.EnumAppTypes.WINDOW; if ((typeof(msg.settings) !== 'undefined') && (msg.settings !== null) && (typeof(msg.settings.TypeID) !== 'undefined')) TypeID = msg.settings.TypeID; NewApp = window.GetAppStructOfTypeID(TypeID); var putHere = NewApp.dialogOptions.appendTo; if (msg.settings) { if (typeof(msg.settings) === 'string') msg.settings = JSON.parse(msg.settings); var attributeList = msg.settings; var keyList = Object.keys(attributeList); var key = ''; var value = ''; for (var count = 0; count < keyList.length; count++) { key = keyList[count]; if (key === 'dialogOptions.appendTo') { isFrameworkApp = true; } value = attributeList[key]; NewApp.setOption(key, value); } } NewApp.name = msg.app; if ((typeof(msg.layout) !== 'undefined') && (StaticLib.Empty(msg.layout) === false)) NewApp.layout = msg.layout; if ((typeof(msg.servletGroup) !== 'undefined') && (StaticLib.Empty(msg.servletGroup) === false)) NewApp.servletGroup = msg.servletGroup; if (eventtype === window.Framework.Enum.EventTypes.APPEVENT_NOLOGIN) { if (NewApp.argsIn === null) NewApp.argsIn = {}; if (typeof(NewApp.argsIn.callback) === 'undefined') NewApp.argsIn.callback = {}; if (typeof(NewApp.argsIn.callback.caller) === 'undefined') NewApp.argsIn.callback.caller = window.Framework; if (typeof(NewApp.argsIn.callback.callbackOnClose) !== 'function') NewApp.argsIn.callback.callbackOnClose = window.Framework.CheckLoggedIn; } if (typeof(msg.LoaderPriority) !== 'undefined') { var taskName = msg.app + '_' + msg.layout + window.Framework.prop.LatestRecordID.is(msg.app); assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); var task1 = { Type: window.LoadingScreenTaskTypes.app, TaskID: taskName, TaskDescription: msg.LoaderTask, Priority: msg.LoaderPriority }; if (window.Framework.prop.Loader === null) { window.Framework.prop.Loader = new LoadingScreen({ TaskList:[task1] }); } else { window.Framework.prop.Loader.AddTask(task1); } NewApp.LoaderID = taskName; } var app = new window.Framework.Methods.GetApp(msg.app, NewApp); if (app.preventLoad === true) return; if (isFrameworkApp === true) app.args.p = -1; if (NewApp.dialogOptions.appendTo === putHere) { app.invoke(); } else { app.putHere(jQuery(NewApp.dialogOptions.appendTo)); } } if (typeof(msg.id) !== 'undefined') { var newcaller = msg.id; if ((newcaller !== null) && (typeof(newcaller) !== 'undefined')) { var method = null; if (typeof(msg.method) === 'string') { method = jQuery.proxy(newcaller[msg.method], newcaller); } else if (typeof(msg.method) === 'function') { method = jQuery.proxy(msg.method, newcaller); } else if (msg.id !== 0) { throw new Error(__METHOD__ + ' reports that the method is unknown... on line ' + __LINE__); } if (typeof(method) === 'function') { data = window.Base64.decode(msg.data); if (StaticLib.IsJSONString(data) === true) data = JSON.parse(data); method(data, msg.controlID); } } } if (typeof(window.Framework.teapot) === 'undefined') window.Framework.teapot = false; if (window.Framework.teapot === true) return false; if (typeof(msg.LoggedIn) !== 'undefined') { if (msg.LoggedIn === 1) { if (window.Framework.V5 !== null) { var socket = window.Framework.V5.SocketServer(); if ((socket.IsConnected === false) && (socket.CheckState() === socket.CLOSED)) socket.Connect(); } /* developer code start */ //if ((window.Framework.prop.developer === true) && ((msg.Name.toLowerCase() === 'maryam') || (msg.Name.toLowerCase() === 'adrian giacominato'))) window.Framework.prop.developer = false; /* developer code end */ window.Framework.prop.CurrentUser = new window.UserDetails(msg); if (window.Framework.prop.Loader !== null) window.Framework.prop.Loader.CompleteTask('LoggedIn'); window.Framework.prop.sessionLocked = false; window.Framework.ProcessUnresolvedActions(); return true; } if (typeof(window.Framework) !== 'undefined') { if (window.Framework.V5.SocketServer().IsConnected === true) window.Framework.V5.SocketServer().Disconnect(); //if ((!window.Framework.prop.screenLocked) || ((msg.LoggedIn === 0) && (window.Framework.prop.screenLocked === true))) { if (!window.Framework.prop.screenLocked) { window.Framework.UI.ShowLogin(); if (typeof(errorHandler) === 'function' ) return errorHandler(msg); } } } if ((typeof(msg.FrameworkID) === 'string') && (msg.FrameworkID.length === 3)) window.Framework._OnSetupComplete(msg); // we processed the command return true; } // if we process the app event, we don't need to run through the switch statement. After this line, constants do not exist yet and if we attempt to continue processing, the software will crash if ((typeof(window.Framework.Enum) === 'undefined') || (typeof(window.Framework.Enum.EventTypes) === 'undefined')) { /* developer code start */ alert('There was an error attempting to load the window.Framework: ' + msg.message); console.log(msg); /* developer code end */ return; } if (eventtype === window.Framework.Enum.EventTypes.APPEVENT) return; var action; switch(eventtype) { // constants are not loaded by time we get to here case window.Framework.Enum.EventTypes.LOAD: { if (typeof(Notification) !== 'undefined') { if (Notification.permission !== 'granted') { Notification.requestPermission(); } else { window.Framework.UI.Notifications.useDesktop = true; } } window.Framework.UI.ClearMenus(); break; } case window.Framework.Enum.EventTypes.MSGBOX: { if ((typeof(thisApp) !== 'undefined') && (AppStaticLib.IsAnApp(thisApp))) { // Check to see if this is an app or a widget if (AppStaticLib.GetContainerOf(thisApp) === null) { window.Framework.UI.MsgBox(msg); } else { if (msg.iserror === 1) { thisApp.AddAppError({Body: msg.message}); } else { thisApp.SetModal(msg); } } } else { window.Framework.UI.MsgBox(msg); } if (msg.iserror === 1) { errorHandler(msg); errorList.count--; } // now check for actions if (typeof(msg.action) === 'undefined') return; action = msg.action; //console.log('ACTION_CLEANUP_PREVIOUS'); if (action === window.ACTION_CLEANUP_PREVIOUS) window.Framework.prop.previous.reset(); return; } case window.Framework.Enum.EventTypes.NOTIFICATION: { var pollingLink = window.Framework.polling.defaultPolling.action; if (pollingLink.postData === null) { pollingLink.postData = {SendTM: msg.SendTM}; } else if (typeof(pollingLink.postData.SendTM) !== 'string') { pollingLink.postData.SendTM = msg.SendTM; } else { var date1 = StaticLib.FormatIntoDate('d/m/Y H:i:s a', msg.SendTM); var date2 = StaticLib.FormatIntoDate('d/m/Y H:i:s a', pollingLink.postData.SendTM); if (date1 > date2) pollingLink.postData.SendTM = msg.SendTM; } if ((typeof(msg.title) === 'string') && (typeof(msg.message) === 'string')) { if (typeof(msg.type) === 'undefined') { window.Framework.UI.Notifications.Add(msg.title, msg.message, msg.type, msg.handler, msg.UniqueGUID, msg.SendTM); } else { var handler = function(){}; if ((typeof(msg.ActionType) === 'string') && ((typeof(msg.ActionID) === 'string') || (typeof(msg.ActionID) === 'number'))) { handler = jQuery.proxy(function(){ new V5Action({Type: this.ActionType, ID: this.ActionID}); }, msg); } window.Framework.UI.Notifications.Add(msg.title, msg.message, msg.type, handler); } } return; } case window.Framework.Enum.EventTypes.UPGRADE: { var k = VersionStruct.create(); k.modal = true; assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); k.dialogExtendOptions.closable = false; k.argsIn = msg; new window.Framework.Methods.GetApp(k).invoke(); break; } case window.Framework.Enum.EventTypes.FATALERROR: { window.Framework.UI.MsgBox({title: 'Maintenance Error', message:msg.message, closable:false, modal:1}, 0, {ok:window.Framework.UI.ForceRefresh }); break; } case window.Framework.Enum.EventTypes.LOCK: { NewApp = WindowStruct.create(); NewApp.name = 'login'; NewApp.servletGroup = 'platform'; NewApp.TypeID = window.EnumAppTypes.LOGIN; NewApp.layout = 'screenlock'; NewApp.modal = true; NewApp.dialogExtendOptions.closable = false; if (typeof(msg.data) !== 'undefined') NewApp.argsIn = msg.data; action = new window.Framework.Methods.GetApp(NewApp); action.invoke(); return; } case window.Framework.Enum.EventTypes.FEEDBACK: { debugger; if (msg.message === null) return; var feedback = msg.message; if (typeof(msg.message) === 'string') feedback = JSON.parse(msg.message); //this.InformApps(feedback.task, feedback.uniqueid, feedback.data); window.Framework.InformApps(feedback.task, feedback.uniqueid, feedback.data); return; } case window.Framework.Enum.EventTypes.SYSTEMCALL: { switch(msg.EventKey) { case window.Framework.Enum.EventKeys.MAILTO : { window.Framework.API.SendEmail(msg.EventValue); break; } case window.Framework.Enum.EventKeys.HTTP: { window.Framework.API.OpenURL(msg.EventValue); break; } default: { window.Framework.UI.MsgBox({ title:'Event Handler', message:'Unknown system call event: ' +msg.EventKey, modal:false, width:400, height:300 }); return; } } return; } case window.Framework.Enum.EventTypes.APIISSUE: { NewApp = WindowStruct.create(); NewApp.name = 'appsetup'; NewApp.servletGroup = 'platform'; NewApp.layout = 'missingapi'; NewApp.argsIn = msg; NewApp.dialogOptions.height = msg.height; NewApp.dialogOptions.width = msg.width; action = new window.Framework.Methods.GetApp(NewApp); action.invoke(); return; } case window.Framework.Enum.EventTypes.NOPERMS: { if (typeof(errorHandler) === 'function' ) { try { errorHandler(msg); } catch(e) { /* jshint ignore: line */ return window.__handleConnectionError(e, -1, e.message, false, false, caller); } } if ((typeof(thisApp) !== 'undefined') && (AppStaticLib.IsAnApp(thisApp))) { // Check to see if this is an app or a widget if (AppStaticLib.GetContainerOf(thisApp) === null) return window.Framework.UI.MsgBox(msg); return thisApp.SetModal(msg); } return window.Framework.UI.MsgBox(msg); } case window.Framework.Enum.EventTypes.EVENTTYPE_ADDSTUB: { assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); var task2 = { Type: window.LoadingScreenTaskTypes.app, TaskID: msg.TaskID, TaskDescription: msg.LoaderTask, Priority: msg.LoaderPriority }; if (window.Framework.prop.Loader === null) { window.Framework.prop.Loader = new LoadingScreen({ TaskList:[task2] }); } else { window.Framework.prop.Loader.AddTask(task2); } break; } case window.Framework.Enum.EventTypes.EVENTTYPE_REMOVESTUB: { if (window.Framework.prop.LoadingTask !== null) window.Framework.prop.Loader.CompleteTask(msg.TaskID); break; } default: { // eventtype not supported /* developer code start */ if ((typeof(window.Framework) !== 'undefined') && (window.Framework.prop.developer)) window.Framework.UI.MsgBox({title: 'Developer Error A234', message: 'Invalid eventtype received [' + eventtype + ']'}); /* developer code end */ return; } } } } catch (e) { throw new Error(e); } if ((temp !== '{}') || (temp !== '[]') || (temp !== '')) return; /* developer code start */ throw new Error('We got a json string passed to the pump and we did not process it'); /* developer code end */ return; }; var PumpProcess = function() { this.IsMessageType = function(msg, type) { var typeid = window.Framework.Enum.EventTypes[type]; if (typeof(typeid) === 'undefined') throw new Error('Invalid EventType received [' + type + ']'); if ((msg === null) || (typeof(msg) !== 'object')) throw new Error('Invalid Message received [' + JSON.stringify(msg) + ']'); return (msg[pumpKeyA] === typeid); }; this.ProcessOrHandle = function(data, handler) { if (typeof(handler) !== 'function') handler = function(){}; if (typeof(data[pumpKeyB]) !== 'undefined') this.process(data, handler); else throw new Error('Unexpected message received: ' + JSON.stringify(data)); }; this.GetMessageList = function(data) { return data[pumpKeyB].messages; }; this.Flatten = function (data) { var _GetCode = function(caller, name, list) { //var thisList = caller[list+ 'List']; var thisList = []; switch (list) { case 'caller' : { thisList = _callerList; break; } case 'callback' : { thisList = _callbackList; break; } case 'control' : { thisList = _controlList; break; } default: { throw new Error('Invalid list type provided: "' + list + '"'); } } //_registeredList, _registeredApps var index = thisList.indexOf(name); if (index !== -1) return index; thisList[thisList.length] = name; return (thisList.length - 1); }; if (data === null) return null; if (typeof(data.caller) !== 'undefined') { assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); data.a = _GetCode(this, data.caller, 'caller'); delete data.caller; } if (typeof(data.callback) !== 'undefined') { assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); data.b = _GetCode(this, data.callback, 'callback'); delete data.callback; } if (typeof(data.controlID) !== 'undefined') { assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); data.c = _GetCode(this, data.controlID, 'control'); delete data.controlID; } }; this.process = function (data, onError, caller) { if (typeof(onError) !== 'function') throw new Error('process requires 2 arguments, data and an error-handling function.'); var msg = ''; if ((typeof(data) === 'string') && (StaticLib.IsJSONString(data) === true)) data = JSON.parse(data); // the server is trying to tell us something, hand the message to Wndprc() if (typeof(data) === 'object') { var hasError = {count:0}; if (typeof(data[pumpKeyB]) !== 'undefined') { var messages = data[pumpKeyB].messages; for (var i = 0; i < messages.length; i++) { /* developer code start */ //if ((typeof(window.Framework) !== 'undefined') && ((typeof(window.Framework.prop) !== 'undefined') && (window.Framework.prop.developer === true))) console.log(messages[i]); /* developer code end */ _ProcessOne(this, messages[i], hasError, caller, onError); } } else { _ProcessOne(this, data, hasError, caller, onError); } if (hasError.count > 0) onError(); if ((typeof(data.msg) !== 'undefined') && (data.msg !== '')) msg = atob(data.msg); } else { msg = data; } }; }; StaticLib.DeepFreeze(PumpProcess); StaticLib.DeepSeal(PumpProcess); //END window.Framework.ControlLookup = { 'core/framework/controls/tabscontrol/tabscontrol.js' : {}, 'core/framework/controls/grid/Grid.js' : {}, 'core/framework/controls/treeview/treeview.js' : {}, 'core/framework/controls/fileupload/fileupload.js' : {}, 'core/framework/controls/appbutton/appbutton.js' : {}, 'core/framework/controls/date/date.js' : {}, 'core/framework/controls/progressbar/progressbar.js' : {}, 'core/framework/js/menu.js' : {}, 'core/framework/controls/selectbox/selectbox.js' : {}, 'core/framework/controls/suggestivesearch/suggestivesearch.js' : {}, 'core/framework/controls/availablesearch/availablesearch.js' : {}, 'core/framework/controls/smartgrid/smartgrid.js' : {}, 'core/framework/controls/emailselect/emailselect.js' : {}, 'core/framework/controls/selectboxbutton/selectboxbutton.js' : {}, 'core/framework/controls/invoiceengine/invoiceengine.js' : {}, 'core/framework/controls/iframe/iframe.js' : {ClassLocation: 'IFrameControl', ClassName:'IFrameControl'} }; // load the data and return the data window.Framework.Methods.GetFile = function(tabElement, url, opt_callback) { var obj = {callback: opt_callback}; var date = new Date(); date = (date + 1); var newURL = url + '?' + StaticLib.Crypto.md5.encode(date.toString()); jQuery(tabElement).load(newURL, jQuery.proxy(function(response, status, xhr) { if (status === 'error' ) { var msg = 'Error: ' + xhr.status + ' ' + xhr.statusText; /* developer code start */ if (window.Framework.Methods.IsDeveloper() === true) window.Framework.UI.MsgBox({title: 'Developer Error A47', message: 'The requested file [' + newURL + '] was not found on the server', modal: false}); /* developer code end */ return; } if (typeof(this.callback) === 'function') this.callback(); return response; }, obj)); }; StaticLib.DeepSeal(window.Framework.Methods.GetFile); window.Framework.Methods.GetApp = function(servletName, opt_struct, opt_servletAction, opt_Layout, opt_Caller) { if ((typeof(servletName) === 'object') && (typeof(servletName.name) === 'string') && (servletName.name !== '')) { this.struct = servletName; servletName = servletName.name; } else { this.struct = null; if ((opt_struct !== null) && (typeof(opt_struct) !== 'undefined')) { this.struct = opt_struct; } else { this.struct = WindowStruct.create(); this.struct.name = servletName; } } //-----RECEIVE LoadJSFor FROM Framework-----// var _LoadJsWith = null; this.ReceiveJSLoaderAndSet = function(JSLoader) { _LoadJsWith = jQuery.proxy(JSLoader, window.Framework); }; this.ApplySetterToFramework = function() { window.Framework.ReceiveSetter(this.ReceiveJSLoaderAndSet); }; this.constructor = window.Framework.Methods.GetApp; window.Framework.SetJSLoader(this); //---------END RECEIVE LoadJSFor--------// if ((servletName === null) || (typeof(servletName) !== 'string') || (servletName === '')) throw new Error('Action requires a Servlet name (as a string) in order to initialise'); this.servlet = servletName; this.action = 'display'; this.args = {}; this.caller = null; this.preventLoad = false; var loadingStyle = ''; this.loadingHTML = '
' + loadingStyle + 'Logo
'; this.CurrentRecord = window.Framework.prop.LatestRecordID.is(this.struct.name); this.struct.CurrentRecord = this.CurrentRecord; if (((this.struct.uniqueType !== '') && (this.struct.uniqueTypeId !== '')) || ((opt_Caller !== null) && (typeof(opt_Caller) !== 'undefined'))) { this.caller = this; if ((opt_Caller !== null) && (typeof(opt_Caller) !== 'undefined')) this.caller = opt_Caller; this.prop = {handle:'__loader'}; if ((this.struct.uniqueType !== '') && (this.struct.uniqueTypeId !== '')) { if (typeof(window.Framework.prop.UniqueWindowCollection[this.struct.uniqueType]) !== 'undefined') { if (typeof(window.Framework.prop.UniqueWindowCollection[this.struct.uniqueType][this.struct.uniqueTypeId]) !== 'undefined') { this.preventLoad = true; if (this.struct.LoaderID !== '') window.Framework.prop.Loader.CompleteTask(this.struct.LoaderID); return false; } } else { window.Framework.prop.UniqueWindowCollection[this.struct.uniqueType] = {}; } window.Framework.prop.UniqueWindowCollection[this.struct.uniqueType][this.struct.uniqueTypeId] = this.prop; } var temp = jQuery.proxy(function(newWindow) { if ((this.caller !== this) && (typeof(this.caller.__actionLoader) !== 'undefined') && (this.caller.__actionLoader !== null)) this.caller.__actionLoader.CompleteTask(this.servlet + '-' + this.struct.layout); if ((this.struct.uniqueType !== '') && (this.struct.uniqueTypeId !== '')) { if (typeof(window.Framework.prop.UniqueWindowCollection[this.struct.uniqueType]) === 'undefined') window.Framework.prop.UniqueWindowCollection[this.struct.uniqueType] = {}; window.Framework.prop.UniqueWindowCollection[this.struct.uniqueType][this.struct.uniqueTypeId] = newWindow.prop.handle; } }, this); if ((this.struct.argsIn === null) || (typeof(this.struct.argsIn) === 'undefined')) { this.struct.argsIn = {callback:{caller:this}}; } else if ((this.struct.argsIn.callback === null) || (typeof(this.struct.argsIn.callback) === 'undefined')) { this.struct.argsIn.callback = {caller:this}; } if (((this.struct.argsIn.callback.callbackOnLoad === null) || (typeof(this.struct.argsIn.callback.callbackOnLoad) === 'undefined')) === false) { var temp2 = {first: temp, second: this.struct.argsIn.callback.callbackOnLoad}; temp = jQuery.proxy(function(arg1) { this.first(arg1); this.second(arg1); }, temp2); } this.struct.argsIn.callback.callbackOnLoad = temp; } if ((typeof(opt_Layout) !== 'undefined') && (opt_Layout !== null)) { this.args.layout = opt_Layout; this.struct.layout = opt_Layout; } if ((opt_servletAction !== null) && (typeof(opt_servletAction) !== 'undefined')) this.action = opt_servletAction; this.createWindow = null; this.opt_BeforeInvoke = null; this.repeatCall = null; this.isComplete = false; this.LastCalledURL = ''; var _Callback_OnSuccess = jQuery.proxy(function(data, status, connection) { var msg = ''; var dependencies = true; if (typeof(connection) === 'undefined') throw new Error('Unknown connection'); /* developer code start */ window.Framework.Methods.LogDataSize(connection, data); /* developer code end */ // code1 //_CheckData(connection, data); var ct = connection.getResponseHeader('content-type') || ''; if (ct.indexOf('html') > -1) { //do something if (StaticLib.IsJSONString(data)) { /* developer code start */ if (window.Framework.Methods.IsDeveloper() === true) return window.Framework.UI.MsgBox({title: '_Callback_OnSuccess Error', message: 'Data returned is not HTML but instead JSON, please specify your content-type header before returning your data', modal: false, width: 400, height: 300}); /* developer code end */ data = JSON.parse(data); } else { var AddError = jQuery.proxy(function(msg){ this.errors.push(msg.message); }, this.struct); data = StaticLib.StripJS(data, AddError); data = StaticLib.ImagifyHTMLorCSS(data, AddError); } //throw new Error('html content type not yet handled'); } else if (ct.indexOf('json') > -1) { // handle json here if (StaticLib.IsJSONString(data) === true) { data = JSON.parse(data); } else { throw new Error('Not a valid JSON string [' + data + ']'); } } else { throw new Error('Unknown content type'); } var _handler = jQuery.proxy(function(msg) { if ((typeof(msg) !== 'undefined') && (msg !== null)) { if (this.struct.handle !== null) { try { var temp = jQuery('#' + this.struct.handle); if (temp.length > 0) temp[0].Popup.Close(); } catch(e) { /* jshint ignore: line */ } jQuery('#' + this.struct.handle).remove(); } if ((msg[pumpKeyA] === window.Framework.Enum.EventTypes.NOPERMS) || (msg[pumpKeyA] === window.Framework.Enum.EventTypes.MSGBOX)) return window.Framework.UI.MsgBox(msg); if ((msg.LoggedIn === 0) && (this.action !== 'CheckLoggedIn')) window.Framework.UnresolvedActions.push(this); } }, this); if (typeof(this.struct.onError) === 'function') _handler = StaticLib.combineFunctions(_handler, this.struct.onError); // the server is trying to tell us something, hand the message to system() if (typeof(data) === 'object') { if (typeof(data[pumpKeyB]) !== 'undefined') { var outputter = new PumpProcess(); outputter.process(data, _handler); } if (data.load) { if (typeof(this.postData) === 'undefined') { this.postData = {}; } else { if (typeof(this.postData.try) === 'undefined') { this.postData.try = 2; } else { this.postData.try++; } } if (Array.isArray(data.load)) { var loadThese = []; data.load.sort(function(obj1, obj2) {return obj1.priority - obj2.priority;}); for (var i = 0; i < data.load.length; i++) { if (typeof(data.load[i].file) === 'string') { //THIS RECORD IS A DEPENDENCY TO LOAD!!! loadThese.push(data.load[i]); if (Array.isArray(this.struct.Controls) !== true) this.struct.Controls = []; if (data.load[i].file.slice(-3) !== 'css') { var filename = data.load[i].file; if (filename.indexOf('?') !== -1) filename = filename.substr(0, filename.indexOf('?')); if (window.Framework.GlobalControls.indexOf(filename) === -1) this.struct.Controls.push(filename); } } else { //THIS RECORD IS STORED CONTROL SETTINGS!!@! if (Array.isArray(this.struct.ControlSettings) !== true) { this.struct.ControlSettings = []; } this.struct.ControlSettings.push(data.load[i]); } } if (loadThese.length === 0) { if ((typeof(this.postData) === 'undefined') || (this.postData === null)) this.postData = {}; this.postData.dll = 1; this.postData.try = 1; return this.repeatCall(); } var loader = new DependencyLoader(loadThese/*data.load*/, jQuery.proxy(function() { if ((typeof(this.postData) === 'undefined') || (this.postData === null)) this.postData = {}; this.postData.dll = 1; this.postData.try = 1; this.repeatCall(); }, this), false/*showLoading*/, true/*loadAsControls*/); } } else { if (typeof(data.msg) !== 'undefined') { if (data.msg !== '') { msg = atob(data.msg); dependencies = false; } } } } else { msg = data; dependencies = false; } if ((dependencies === false) && (msg !== '')) { this.isComplete = true; msg = StaticLib.StripJS(msg); msg = StaticLib.ImagifyHTMLorCSS(msg); var recordId = this.CurrentRecord; this.createWindow(this.struct, msg, recordId); } }, this); var _Callback_OnComplete = jQuery.proxy(function(data, status, connection) { if ((typeof(this.onComplete) !== 'undefined') && (this.onComplete !== null) && (this.isComplete)) this.onComplete(data); }, this); var _Callback_OnError = jQuery.proxy(function(connection, status, errorText) { assert(function(){ return (typeof(connection) !== 'undefined');}); if (typeof(connection) === 'undefined') return; window.__handleConnectionError(connection, connection.status, errorText, true); if ((typeof(this.caller) !== 'undefined') && (this.caller !== null)) { if ((typeof(this.caller.__actionLoader) !== 'undefined') && (this.caller.__actionLoader !== null)) this.caller.__actionLoader.CompleteTask(this.servlet + '-' + this.struct.layout); } this.isComplete = true; var handler = jQuery.proxy(function(msg) { /* developer code start */ if (window.Framework.Methods.IsDeveloper() === true) console.log('there was an error'); /* developer code end */ if ((msg.LoggedIn === 0) && (this.action !== 'CheckLoggedIn')) window.Framework.UnresolvedActions.push(this); }, this); if (typeof(this.struct.onError) === 'function') { handler = this.struct.onError; assert(function(){return false;/*Error Accessing App*/}); } if (StaticLib.IsJSONString(connection.responseText)) { /* developer code start */ //if (window.Framework.Methods.IsDeveloper() === true) console.log('B6-CALLBACK FROM: ' + _createURL()); /* developer code end */ var outputter = new PumpProcess(); outputter.process(connection.responseText, handler); return; } }, this); this._createURL = function() { return _createURL(); }; var _createURL = jQuery.proxy(function() { var extraArgs = ''; var group = ''; if (!((typeof(this.struct) === 'object') && (typeof(this.struct.servletGroup) === 'string') && (this.struct.servletGroup !== ''))) throw new Error ('All Apps are part of a Program Group. This needs to be an attribute on the windowstruct'); if ((this.struct !== null) && (typeof(this.struct) !== 'undefined')) { if (this.action !== 'display') extraArgs = '&action=' + this.action; var handleID = '0'; if (this.struct.CurrentRecord !== null) handleID = this.struct.CurrentRecord; extraArgs = '&w=' + handleID; if ((this.args !== null) && (typeof(this.args) !== 'undefined')) jQuery.each(this.args, function( index, value ) {extraArgs = extraArgs + '&' + index + '=' + encodeURI(value);}); } if (this.struct.layout === '') this.struct.layout = 'default'; var frameworkID = window.FrameworkID; if ((typeof(window.Framework.V5) === 'object') && (window.Framework.V5 !== null) && (typeof(window.Framework.V5.RunningFrameworkID) === 'string')) frameworkID = window.Framework.V5.RunningFrameworkID; var handle = '0'; if (this.struct.handle !== null) handle = this.struct.handle; this.LastCalledURL = this.struct.servletGroup + '/' + this.servlet + '/' + this.struct.layout + '/display/?r=' + handle + '&f=' + frameworkID + extraArgs; return this.LastCalledURL; }, this); this.invoke = function(opt_resetTimer) { if (window.Online === false) return window.Framework.UI.MsgBox({title: 'Error',message: 'Not online', height: 200, width: 300, modal: false}); //_FillWindow if (this.hasOpenedWindow !== true) { this.hasOpenedWindow = true; window.Framework.UI._CreateWindow(this.struct, this.loadingHTML, this.CurrentRecord, true); } this.createWindow = jQuery.proxy(window.Framework.UI._ShowWidget_callback, window.Framework.UI); this.repeatCall = this.invoke; this.contactServer(opt_resetTimer); }; this.contactServer = function(opt_resetTimer) { if (window.Online === false) return window.Framework.UI.MsgBox({title: 'Error',message: 'Not online', height: 200, width: 300, modal: false}); var allowedTries = 3; if (typeof(this.postData) !== 'undefined') { if (typeof(this.postData.try) !== 'number') { if (this.struct.JSLink() in window.Framework.prop.ClassCollection) { this.postData.dll = 1; this.postData.try = 1; } } else { if (this.postData.try > allowedTries) { assert(function(){ return (this.postData.try <= allowedTries);/*Maximum attempts reached*/}); return; } } } else { this.postData = {}; } if ((this.caller !== null) && (typeof(this.caller) === 'object')) { if (this.postData === null) this.postData = {}; //Remove the first and last letters to turn the selector into just the id var pos = (this.caller.prop.handle.startsWith('#') === true) ? 1 : 0; var callerID = this.caller.prop.handle.slice(pos, this.caller.prop.handle.length).trim(); this.args.caller = callerID; } var _link = _createURL(); if (typeof(this.opt_BeforeInvoke) === 'function') this.opt_BeforeInvoke(this); if (AppStaticLib.IsAnApp(this.caller) === true) { if ((typeof(this.caller.__actionLoader) === 'undefined') || (this.caller.__actionLoader === null)) { var overlay = document.createElement('div'); overlay.setAttribute('class', 'ui-widget-overlay ui-front'); overlay.setAttribute('style', 'position: absolute;'); jQuery(this.caller.prop.handle).append(overlay); debugger; var debug = true; if (debug === true) { this.progressbar = new window.Framework.Controls.ProgressBar ('', 'rectangle', 'append', '', this.caller); this.progressbar.vars.div.setAttribute('style', 'position: absolute; top: 0px;'); this.progressbar.load(); } this.caller.__actionLoader = new TaskManagerControl({ParentObject: this.caller, TaskList: [this.servlet + '-' + this.struct.layout] , WhenDone: jQuery.proxy(function() { jQuery(this.caller.prop.handle).find('.ui-widget-overlay').first().remove(); delete this.progressbar; this.caller.__actionLoader = null; }, this)}); } else { if (typeof(this.postData.try) === 'undefined') this.caller.__actionLoader.AddTask(this.servlet + '-' + this.struct.layout); } } if (window.Online === false) return window.Framework.UI.MsgBox({title: 'Error',message: 'Not online', height: 200, width: 300, modal: false}); jQuery.ajax({ url: _link, method: 'POST', data: this.postData, dataType: 'text', context: this, error: _Callback_OnError, complete: _Callback_OnComplete, success: _Callback_OnSuccess }).ActionObj = this; if ((typeof(opt_resetTimer) !== 'undefined') && (opt_resetTimer === false)) return; if ((typeof(window.Framework.prop) !== 'undefined') && (typeof(window.Framework.prop.SessionTimer) !== 'undefined') && (window.Framework.prop.SessionTimer !== null)) window.Framework.prop.SessionTimer.resetTimer(); }; this.FillSectionAndWrap = function(NewApp, data) { var id = 0; if ((window.Framework) && (window.Framework !== null) && (window.Framework.prop) && (window.Framework.prop !== null) && (window.Framework.prop.LatestRecordID) && (window.Framework.prop.LatestRecordID !== null)) id = window.Framework.prop.LatestRecordID.is(this.name); var newID = 'ContainedApp_' + id; var newLocation = jQuery('
'); jQuery(this.putHere).append(newLocation); this.putHere = newLocation; jQuery.proxy(this.context.callback_FillSectionWithWidget, this)(NewApp, data); }; this.putHere = function(putHere, opt_resetTimer, opt_CallbackAfterComplete) { var context = {putHere: putHere, opt_resetTimer: opt_resetTimer, opt_CallbackAfterComplete: opt_CallbackAfterComplete, func: this.putHere, context: this}; this.createWindow = jQuery.proxy(this.FillSectionAndWrap, context); this.repeatCall = jQuery.proxy(function() { return jQuery.proxy(this.func, this.context)(this.putHere, this.opt_resetTimer, this.opt_CallbackAfterComplete); }, context); if (typeof(opt_CallbackAfterComplete) !== 'undefined') this.onComplete = opt_CallbackAfterComplete; if (jQuery(putHere)[0].id !== '') this.struct.handle = jQuery(putHere)[0].id; this.contactServer(opt_resetTimer); }; this.callback_FillSectionWithWidget = function(NewApp, data) { var putHere = jQuery(this.putHere); var thisApp = null; var container = document.createElement('DIV'); var jContainer = jQuery(container); var handle_Modal = NewApp.servletGroup + NewApp.name + NewApp.layout + '_' + NewApp.CurrentRecord; container.setAttribute('id', handle_Modal); container.setAttribute('class', 'containedapp'); /* developer code start */ if ((window.Framework.prop.developer) || (window.Framework.prop.visualTest)) { var extraStyles = ''; if (window.Framework.prop.visualTest) extraStyles = 'height:100%; '; data = '
' + data + '
'; } /* developer code end */ container.innerHTML = data; putHere.html(container); if (AppStaticLib.GetThisApp(container) === null) { jContainer.hover( /*HOVER IN*/ jQuery.proxy (function(){ jQuery(this).addClass('ui-front'); }, putHere), /*HOVER OUT*/ jQuery.proxy (function(){ jQuery(this).removeClass('ui-front'); }, putHere) ); } if (NewApp.hasScript) { var JSurl = NewApp.JSLink(); _LoadJsWith(JSurl, jContainer, NewApp); //window.Framework.LoadJSFor(JSurl, jContainer, NewApp); var parentApp = null; if (NewApp.type !== 'FrameworkComponent') { try { if (jQuery.contains(document, putHere[0])) parentApp = AppStaticLib.GetThisApp(putHere); } catch(e) { /* jshint ignore: line */ //already handled... } } } /* developer code start */ if (NewApp.hasAngular === true) { // interesting, jshint says that thisApp is out of context without this line, but with it, angularjs apps will not load if (thisApp === null) { if (window.Framework.prop.developer) window.Framework.UI.MsgBox({title: 'Error',message: 'NewApp.hasAngular()
Error: Failed to find the App instance to compile', height: 200, width: 300, modal: false}); return; } window.Framework.LoadAngularFor('#' +handle_Modal, thisApp.prop._angularAppID); } /* developer code end */ if ((NewApp.LoaderID !== '') && (window.Framework.prop.Loader !== null)) window.Framework.prop.Loader.CompleteTask(NewApp.LoaderID); }; return this; }; StaticLib.DeepSeal(window.Framework.Methods.GetApp); StaticLib.DeepFreeze(window.Framework.Methods.GetApp); window.APIV2Struct = { create: function(obj) { var struct = { servlet: '', view: '', servletGroup: '', api: '', proxy: false, proxyServlet: '', proxyServletGroup: '', proxyView: 'default', controlID: '', caller: null, from: null, callback: null, postData: null, oneVal: true, showLoading: true, isControl: false, LoadingTask: null }; if ((obj !== null) && (typeof(obj) !== 'undefined')) { if ((obj.api === '') || (typeof(obj.api) !== 'string')) throw new Error ('APIV2Struct expects an \'api\' argument that is a function name'); if ((obj.LoadingTask !== null) && (typeof(obj.LoadingTask) !== 'undefined')) obj.LoadingTask = new window.LoadingTaskSTRUCT(obj.LoadingTask); if ((obj.caller === null) || (typeof(obj.caller) === 'undefined')) { if ((obj.from !== null) && (typeof(obj.from) === 'object')) { if (obj.isControl !== true) obj.caller = obj.from; } else { throw new Error ('APIV2Struct expects a \'caller\' argument'); } } if ((obj.from === null) || (typeof(obj.from) !== 'object')) { if ((obj.caller !== null) && (typeof(obj.caller) === 'object')) { obj.from = obj.caller; } else { //Shouldn't be possible to get here... throw new Error ('APIV2Struct expects a \'caller\' argument'); } } //BOTH 'From' AND 'Caller' SHOULD NOW BE SET! if (AppStaticLib.IsAnApp(obj.from)) { obj.servlet = obj.from.AppDetails.servlet; obj.view = obj.from.AppDetails.view; obj.servletGroup = obj.from.AppDetails.servletGroup; } else if (obj.from === window.Framework) { obj.servlet = obj.proxyServlet; obj.view = obj.proxyView; obj.servletGroup = obj.proxyServletGroup; } else { throw new Error ('APIV2Struct expects a \'caller\' argument (or the \'from\' argument when providing BOTH \'caller\' & \'from\') to be an instance of an App'); } if (obj.isControl !== true) { if ((!AppStaticLib.IsAnApp(obj.caller)) && (obj.from !== window.Framework)) { throw new Error ('APIV2Struct expects the \'caller\' argument to be an instance of an App, unless the \'isControl\' argument is provided'); } //WE NOW KNOW 'Caller' IS SET TO AN INSTANCE OF AN APP! if (obj.from === window.Framework) { if (typeof(obj.from[obj.callback]) !== 'function' ) throw new Error('APIV2Struct expects a \'callback\' argument that is a string name of a function available on the \'window.Framework\''); } else { if ((typeof(obj.callback) !== 'string') || (typeof(obj.caller[obj.callback]) !== 'function' )) throw new Error ('APIV2Struct expects a \'callback\' argument that is a string name of a function available on the \'caller\''); obj.servlet = obj.from.AppDetails.servlet; obj.view = obj.from.AppDetails.view; obj.servletGroup = obj.from.AppDetails.servletGroup; } } if ((obj.proxyServlet !== '') && (typeof(obj.proxyServlet) === 'string') && (obj.proxyServletGroup !== '') && (typeof(obj.proxyServletGroup) === 'string')) { //WE NOW KNOW BOTH 'proxyServlet' AND 'proxyServletGroup' ARE SET! if ((obj.proxyView === '') || (typeof(obj.proxyView) !== 'string')) obj.proxyView = 'default'; // ...AND NOW 'proxyView' IS ALSO SET! if ((obj.servletGroup !== obj.proxyServletGroup) || (obj.servlet !== obj.proxyServlet) || (obj.view !== obj.proxyView)) obj.proxy = true; } else { //WE KNOW AT LEAST ONE OF 'proxyServlet' AND 'proxyServletGroup' ARE MISSING! if (((obj.proxyServlet !== '') && (typeof(obj.proxyServlet) === 'string')) || (obj.proxy === true)) throw new Error ('When \'proxy\' is set to true or proxyServlet is provided, APIV2Struct expects the \'proxyServletGroup\' & \'proxyServlet\' arguments'); } } if ((typeof(obj) !== 'undefined') && (obj !== null)) StaticLib.SetProps(struct, obj); return struct; } }; StaticLib.DeepSeal(window.APIV2Struct); StaticLib.DeepFreeze(window.APIV2Struct); window.Framework.Methods.GetAPIV2 = function(o) { // properties for GetArgs this.prop = window.APIV2Struct.create(o); var keys = Object.keys(this.prop); keys.forEach(jQuery.proxy(function(key) { Object.defineProperty(this, key, { get: function() { return this.prop[key]; }, set: function(value) { this.prop[key] = value; }, enumerable: false, writeable: true, configurable: true }); }, this)); Object.defineProperty(this, 'callbackName', { get: function() { return this.prop.callback; }, set: function(value) { this.prop.callback = value; }, enumerable: false, writeable: true, configurable: true }); if ((this.prop.servlet === null) || (typeof(this.prop.servlet) !== 'string')) throw new Error('Action requires a Servlet name (as a string) in order to initialise'); this.showLoading = true; //if (o.showLoading === true) this.showLoading = false; var callObj = null; this.opt_BeforeInvoke = null; this.opt_SuccessCallback = null; this.opt_CompleteCallback = null; this.opt_ErrorCallback = null; this.args = {}; this.onError = null; this.onComplete = null; this.opt_BeforeProcess = null; this.LastCalledURL = ''; this.Frame = { Level: 0, Start: null, Method: null, URL: '', ServletGroup: '', Servlet: '', View: '', IsProxyCall: false, ProxyServletGroup: '', ProxyServlet: '', ProxyView: '', Duration: function() { var end = window.performance.now(); var ms = parseInt((end - this.Start).toString().split('.'[0])); var time = (end - this.Start); var label = 'milliseconds'; if (ms > 1000) { time = (ms / 1000); label = 'seconds'; } return time + ' ' + label; } }; if (typeof(this.prop.callback) !== 'undefined') { if ((!this.prop.isControl) && ((this.prop.callback === null) || (typeof(this.prop.callback) !== 'string'))) throw new Error('The appCallback argument that Action was passed was not a string as required'); this.callbackName = this.prop.callback; } if ((this.prop.postData !== null) && (typeof(this.prop.postData) !== 'undefined')) this.postData = this.prop.postData; var _Callback_OnSuccess = jQuery.proxy(function(data, status, connection) { if (typeof(connection) === 'undefined') throw new Error('connection is unknown'); if (typeof(this.opt_BeforeProcess) === 'function') this.opt_BeforeProcess(data); /* developer code start */ window.Framework.Methods.LogDataSize(connection, data); /* developer code end */ /* developer code start */ if (window.Framework.Methods.IsDeveloper() === true) { assertgroup('stack', 'debugging the client and server side callstack'); if (typeof(this.Frame.Start) !== 'undefined') { //var timeTaken = (new Date().getTime() - this.startTime); console.log( '---GETAPI COMPLETE---\n' + 'Servlet: ' + this.prop.proxyServlet + '\n' + 'View: ' + this.prop.proxyView + '\n' + 'API: ' + this.prop.api + '\n' + 'Time: ' + this.Frame.Duration() ); } } /* developer code end */ var msg = ''; // code1 var ct = connection.getResponseHeader('content-type') || ''; if (ct.indexOf('html') > -1) { if (StaticLib.IsJSONString(data) === true) { var caller = null; if ((connection.ActionObj !== null) && (connection.ActionObj.caller !== null)) caller = connection.ActionObj.caller; var msg = __METHOD__ + ' reports that the data returned is not JSON but instead HTML, please specify your content-type header before returning your data'; if (caller === null) throw new Error(msg); if (typeof(this.onError) === 'function') this.onError(data); try { throw new Error(msg); } catch (e) { return window.__handleConnectionError(e, -1, msg, false, false, caller); } } else { window.Framework.UI.MsgBox({title: 'Error',message: data}); } //data = StaticLib.StripJS(data); } else if (ct.indexOf('json') > -1) { // handle json here if (StaticLib.IsJSONString(data) === false) { if (typeof(this.onError) === 'function') handler = this.onError(data); throw new Error('Not a valid JSON string'); } data = JSON.parse(data); } else { throw new Error('Unknown content type'); } if ((typeof(data.CallStack) !== 'undefined') && ((typeof(connection.ActionObj) !== 'undefined') && (AppStaticLib.IsAnApp(connection.ActionObj.prop.caller) === true))) connection.ActionObj.prop.caller.AddAppCall(data.CallStack); var handler = jQuery.proxy(function() { if (msg.LoggedIn === 0) window.Framework.UnresolvedActions.push(this); }, this); if (typeof(this.onError) === 'function') handler = this.onError; // the server is trying to tell us something, hand the message to the system if (typeof(data) === 'object') { if (Array.isArray(data.NewKey) === true) { pumpKeyA = data.NewKey[0]; pumpKeyB = data.NewKey[1]; } if (typeof(data[pumpKeyB]) !== 'undefined') { var outputter = new PumpProcess(); outputter.process(data, handler); } if ((typeof(data.msg) !== 'undefined') && (data.msg !== '')) msg = atob(data.msg); } if (typeof(this.opt_SuccessCallback) === 'function') this.opt_SuccessCallback(data); }, this); var _Callback_OnComplete = jQuery.proxy(function(data, status, connection) { var caller = this.caller; if (AppStaticLib.IsAnApp(this.prop.proxyCaller)) caller = this.prop.proxyCaller; if (AppStaticLib.IsAnApp(caller)) { var index = caller.currentAPICalls.indexOf(this); if (index !== -1) { caller.currentAPICalls.splice(index, 1); } } if ((this.showLoading) && (typeof(caller) !== 'undefined') && (caller !== null) && (typeof(caller.__actionLoader) !== 'undefined') && (caller.__actionLoader !== null)) caller.__actionLoader.CompleteTask(this.servlet + '-' + this.action); if ((typeof(this.onComplete) !== 'undefined') && (this.onComplete !== null)) { try { this.onComplete(data); } catch(e) { /* jshint ignore: line */ if (AppStaticLib.IsAnApp(caller) !== true) { if (AppStaticLib.IsAnApp(caller.vars.ParentObject)) caller = caller.vars.ParentObject; else if (AppStaticLib.IsAnApp(caller.prop.ParentObject)) caller = caller.vars.ParentObject; else if ((typeof(caller.prop.ParentObject) === 'object') && (typeof(caller.prop.ParentObject.GetValue) === 'function')) { if (AppStaticLib.IsAnApp(caller.prop.ParentObject)) caller = caller.vars.ParentObject; } } if (AppStaticLib.IsAnApp(caller) === false) window.ErrorHandler(caller.prop.struct, e, _createURL(), true, caller); } } if (this.prop.LoadingTask !== null) window.Framework.prop.Loader.CompleteTask(this.prop.LoadingTask.TaskID); }, this); var _Callback_OnError = jQuery.proxy(function(connection, status, errorText) { if (typeof(connection) === 'undefined') return; window.__handleConnectionError(connection, connection.status, errorText, true); var caller = this.caller; if (typeof(this.opt_BeforeProcess) === 'function') this.opt_BeforeProcess(null); if (AppStaticLib.IsAnApp(this.prop.proxyCaller) === true) caller = this.prop.proxyCaller; if ((this.showLoading) && (typeof(caller) !== 'undefined') && (caller !== null) && (typeof(caller.__actionLoader) !== 'undefined') && (caller.__actionLoader !== null)) caller.__actionLoader.CompleteTask(this.servlet + '-' + this.action); if (typeof(this.onError) === 'function') this.onError(); if (StaticLib.IsJSONString(connection.responseText) === true) { var outputter = new PumpProcess(); outputter.process(connection.responseText, function(){}, caller); return; } }, this); this.ReturnDataLocation = function (DataSourceObj) { if ((DataSourceObj instanceof DatasourceArray) !== true) return; DataSourceObj.ReceiveURL(_createURL()); }; var _createURL = jQuery.proxy(function() { var layout = ''; var group = ''; if ((typeof(this.prop.caller) !== 'undefined') && (this.prop.caller !== null)) { if (this.args === null) this.args = {}; this.args.caller = this.prop.caller; } else { throw new Error('You can\'t _createURL for an API that doesn\'t have a caller'); } if ((this.prop.from === null) && (typeof(this.prop.from) !== 'object')) throw new Error('You can\'t _createURL for an API that doesn\'t have a \'from\' source'); if (this.prop.from !== window.Framework) this.args.w = this.prop.from.prop.struct.CurrentRecord; if (this.prop.callback !== null) this.args.callback = this.prop.callback; if (this.controlID !== null) this.args.controlID = this.prop.controlID; // is this a proxy call if (this.prop.proxy === true) { this.args.proxy = 1; if (this.postData === null) this.postData = {}; } var outputter = new PumpProcess(); outputter.Flatten(this.args); var extraArgs = ''; if (this.action !== 'display') { if (this.args !== null) { jQuery.each(this.args, function( index, value ) { if (value === null) return; if (typeof(value) === 'undefined') return; extraArgs = extraArgs + '&' + index + '=' + encodeURI(value); }); } } var servletGroup = this.prop.servletGroup; var servlet = this.prop.servlet; var view = this.prop.view; if (this.prop.from !== window.Framework) { servletGroup = this.prop.from.AppDetails.servletGroup; servlet = this.prop.from.AppDetails.servlet; view = this.prop.from.AppDetails.view; } if (StaticLib.Empty(servletGroup) === true) throw new Error('ServletGroup is empty'); if (StaticLib.Empty(servlet) === true) throw new Error('Servlet is empty'); if (StaticLib.Empty(view) === true) throw new Error('View is empty'); var frameworkID = window.FrameworkID; if ((typeof(window.Framework.V5) === 'object') && (window.Framework.V5 !== null) && (typeof(window.Framework.V5.RunningFrameworkID) === 'string') ) frameworkID = window.Framework.V5.RunningFrameworkID; this.LastCalledURL = servletGroup + '/' + servlet + '/' + view + '/' + this.prop.api + '/?' + 'f=' + frameworkID + extraArgs; return this.LastCalledURL; }, this); this.PreviewContent = function(IFrameName) { if (typeof(this.postData) !== 'object') throw new Error('GetAPI.PreviewContent should only be called with PostForm Data'); var url = _createURL(); var params = this.postData; var newWindow = true; if (this.prop.oneVal) params = {POSTDATA: this.postData}; var addParam = function(paramName, paramValue) { var input = jQuery(''); if (typeof(paramValue) ==='object') { if (typeof(StaticLib) !== 'undefined') paramValue = StaticLib.JsonEncode(paramValue); else paramValue = JSON.stringify(paramValue); } input.attr({'id': paramName, 'name': paramName, 'value': paramValue}); form.append(input); }; var form = jQuery('
'); form.attr('action', url); form.attr('method', 'POST'); var targetName = '_blank'; if ((typeof(IFrameName) !== 'undefined') && (IFrameName !== null) && (IFrameName !== '')) targetName = IFrameName; if (newWindow === true) form.attr('target', targetName); for(var key in params) addParam(key, params[key]); // Submit the form, then remove it from the page assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); form.appendTo(document.body); form.submit(); form.remove(); }; var _ProxyPost = jQuery.proxy(function() { if (this.postData === null) return null; var temp = this.postData; var tempVal = this.postData; if (this.oneVal === true) { if (this.postData !== null) { if (typeof(StaticLib) !== 'undefined') temp = StaticLib.JsonEncode(this.postData); else temp = JSON.stringify(this.postData); } temp = {'POSTDATA': temp}; } else { temp = JSON.parse(StaticLib.JsonEncode(this.postData)); } if (this.prop.proxy === true) temp.proxy = {servlet: this.prop.proxyServlet, view: this.prop.proxyView, proxyServletGroup: this.prop.proxyServletGroup}; return temp; }, this); this.invoke = function(opt_resetTimer) { if (window.Online === false) return window.Framework.UI.MsgBox({title: 'Error',message: 'Not online', height: 200, width: 300, modal: false}); var _link = _createURL(); var temp = ''; /* developer code start */ if (window.Framework.Methods.IsDeveloper() === true) { this.Frame.Start = window.performance.now(); if (this.isControl === true) { this.Frame.ServletGroup = this.from.AppDetails.servletGroup; this.Frame.Servlet = this.from.AppDetails.servlet; this.Frame.View = this.from.AppDetails.view; } //this.Frame.ServletGroup = this.servletGroup; //this.Frame.Servlet = this.servlet; //this.Frame.View = this.view; if (this.proxy === true) { this.Frame.IsProxyCall = this.prop.proxy; this.Frame.ProxyServletGroup = this.proxyServlet; this.Frame.ProxyServlet = this.proxyView; this.Frame.ProxyView = this.proxyServletGroup; } this.Frame.Method = this.api; this.Frame.URL = _link; } /* developer code end */ if (this.postData !== null) { if (typeof(StaticLib) !== 'undefined') temp = StaticLib.JsonEncode(this.postData); else temp = JSON.stringify(this.postData); } if (typeof(this.opt_BeforeInvoke) === 'function') this.opt_BeforeInvoke(this); var caller = this.caller; if (AppStaticLib.IsAnApp(this.prop.proxyCaller) === true) caller = this.prop.proxyCaller; if ((this.showLoading === true) && (AppStaticLib.IsAnApp(caller) === true) && (caller.prop.struct.hasScript === true) && (jQuery(caller.prop.handle).hasClass('loading') === false)) { if ((typeof(caller.__actionLoader) === 'undefined') || (caller.__actionLoader === null)){ var debugoverlay = false; if (debugoverlay === true) { var overlay = document.createElement('div'); overlay.setAttribute('class', 'ui-widget-overlay ui-front'); overlay.setAttribute('style', 'position: absolute; top: 0px;'); jQuery(caller.prop.handle).append(overlay); } var message = ''; if (typeof(this.prop.LoaderMessage) === 'string') message = this.prop.LoaderMessage; var canAbort = false; if (this.prop.cancellable === true) canAbort = true; debugger; var debug = false; if (debug === true) { this.progressbar = new window.Framework.Controls.ProgressBar ('', 'rectangle', 'append', message, caller, canAbort); this.progressbar.vars.div.setAttribute('style', 'position: absolute; top: 0px;'); this.progressbar.load(); } var context = {GetAPI:this, overlay:overlay, caller:caller}; caller.__actionLoader = new TaskManagerControl({ParentObject: caller, TaskList: [this.servlet + '-' + this.action] , WhenDone: jQuery.proxy(function(){ jQuery(this.overlay).remove(); delete this.GetAPI.progressbar; this.caller.__actionLoader = null; }, context)}); } else { caller.__actionLoader.AddTask(this.servlet+'-'+this.action); } } if (this.prop.LoadingTask !== null) { if (window.Framework.prop.Loader === null) { window.Framework.prop.Loader = new LoadingScreen({ TaskList:[this.prop.LoadingTask] }); } else { window.Framework.prop.Loader.AddTask(this.prop.LoadingTask); } } temp = _ProxyPost(); if (window.Online === false) return window.Framework.UI.MsgBox({title: 'Error',message: 'Not online', height: 200, width: 300, modal: false}); callObj = jQuery.ajax({ url: _link, method: 'POST', data: temp, dataType: 'text', context: this, error: _Callback_OnError, complete: _Callback_OnComplete, success: _Callback_OnSuccess, startTime: window.performance.now() }); callObj.ActionObj = this; if (AppStaticLib.IsAnApp(caller) === true) { caller.currentAPICalls.push(this); } if (canAbort === true) { if (this.progressbar !== null) { jQuery(this.progressbar.vars.closeBtn).click(jQuery.proxy(function(){this.abort();}, this)); } else { JQuery.proxy(function(){this.abort();}, this); } } if ((typeof(opt_resetTimer) !== 'undefined') && (opt_resetTimer === false)) return; if ((typeof(window.Framework.prop) !== 'undefined') && (typeof(window.Framework.prop.SessionTimer) !== 'undefined') && (window.Framework.prop.SessionTimer !== null)) window.Framework.prop.SessionTimer.resetTimer(); }; this.abort = function() { callObj.abort(); }; this.clone = function() { var temp = new window.Framework.Methods.GetAPIV2(this.prop); temp.postData = _ProxyPost(); return temp; }; return this; }; StaticLib.DeepSeal(window.Framework.Methods.GetAPIV2); StaticLib.DeepFreeze(window.Framework.Methods.GetAPIV2); window.Framework.Methods.GetAPIV1 = function(servletName, servletAction, opt_CallerApp, opt_appCallback, opt_postData, opt_controlID) { var o = window.APIV2Struct.create(); o.servlet = servletName; if (opt_CallerApp !== null) { var parentApp = opt_CallerApp; //if (AppStaticLib.IsControl(parentApp) === true) { if (((typeof(parentApp.OuterParentObject) === 'object') && (parentApp.OuterParentObject !== null)) || ((typeof(parentApp.prop) !== 'undefined') && (typeof(parentApp.prop.ParentObject) === 'object') && (parentApp.prop.ParentObject !== null))) { while (parentApp.OuterParentObject) parentApp = parentApp.OuterParentObject; parentApp = parentApp.prop.ParentObject; if (typeof(parentApp.GetValue) === 'function') parentApp = parentApp.GetValue(); } if (AppStaticLib.IsAnApp(parentApp) === true) o.view = parentApp.AppDetails.view; } o.api = servletAction; if ((typeof(opt_CallerApp) !== 'undefined') && (opt_CallerApp !== null)) o.caller = opt_CallerApp; if ((typeof(opt_appCallback) === 'undefined') && (opt_appCallback === null)) { opt_appCallback = '_devnull'; } else { o.callback = opt_appCallback; } if ((typeof(opt_postData) !== 'undefined') && (opt_postData !== null)) o.postData = opt_postData; if ((typeof(opt_controlID) !== 'undefined') && (opt_controlID !== null)) o.controlID = opt_controlID; return new window.Framework.Methods.GetAPIV2(o); }; StaticLib.DeepSeal(window.Framework.Methods.GetAPIV1); window.Framework.Methods.IsDeveloper = function() { if (typeof(window.Framework.prop) === 'undefined') return false; return (window.Framework.prop.developer === true); }; StaticLib.DeepSeal(window.Framework.Methods.IsDeveloper); window.Framework.Methods.GetAPI = function(servletName, servletAction, opt_CallerApp, opt_appCallback, opt_postData, opt_controlID) { if (typeof(opt_CallerApp) === 'undefined') opt_CallerApp = null; if (typeof(opt_appCallback) === 'undefined') opt_appCallback = null; if (typeof(opt_postData) === 'undefined') opt_postData = null; if (typeof(opt_controlID) === 'undefined') opt_controlID = null; if ((opt_CallerApp !== null) && (AppStaticLib.IsAnApp(opt_CallerApp) === true)) { if ((opt_appCallback !== null) && (typeof(opt_appCallback) !== 'string')) throw new Error('The appCallback argument that Action was passed was not a string as required'); } // properties for GetArgs this.prop = window.APIV2Struct.create(); if ((servletName === null) || (typeof(servletName) !== 'string')) throw new Error('Action requires a Servlet name (as a string) in order to initialise'); this.servlet = servletName; this.action = 'display'; this.controlID = (typeof(opt_controlID) !== 'undefined') ? opt_controlID : null; this.oneVal = false; this.args = {}; if ((servletAction !== null) && (typeof(servletAction) !== 'undefined')) this.action = servletAction; if ((opt_CallerApp !== null) && (typeof(opt_CallerApp) === 'object')) this.caller = opt_CallerApp; this.servletGroup = ''; this.showLoading = true; this.callbackName = null; this.opt_BeforeInvoke = null; this.opt_SuccessCallback = null; this.opt_CompleteCallback = null; this.opt_ErrorCallback = null; this.postData = null; this.onError = null; this.LastCalledURL = ''; /* developer code start */ this.Frame = { Level: 0, Start: null, //End: null, Method: null, URL: '', ServletGroup: '', Servlet: '', View: '', IsProxyCall: false, ProxyServletGroup: '', ProxyServlet: '', ProxyView: '', Duration: function() { var end = window.performance.now(); var ms = parseInt((end - this.Start).toString().split('.'[0])); var time = (end - this.Start); var label = 'milliseconds'; if (ms > 1000) { time = (ms / 1000); label = 'seconds'; } return time + ' ' + label; } }; /* developer code end */ this.callbackName = opt_appCallback; if ((opt_postData !== null) && (typeof(opt_postData) !== 'undefined')) this.postData = opt_postData; var _Callback_OnSuccess = jQuery.proxy(function(data, status, connection) { /* developer code start */ if (window.Framework.Methods.LogDataSize(connection, data) === false) return; /* developer code end */ if ((this.showLoading === true) && (typeof(this.caller) !== 'undefined') && (this.caller !== null) && (typeof(this.caller.__actionLoader) !== 'undefined') && (this.caller.__actionLoader !== null)) this.caller.__actionLoader.CompleteTask(this.servlet + '-' + this.action); var msg = ''; var ct = connection.getResponseHeader('content-type') || ''; if (ct.indexOf('html') > -1) { if (StaticLib.IsJSONString(data) === true) throw new Error(__METHOD__ + ' reports that the data returned is not JSON but instead HTML, please specify your content-type header before returning your data'); throw new Error('html content type not yet handled (' + data) + ')'; } else if (ct.indexOf('json') > -1) { if (StaticLib.IsJSONString(data)) { data = JSON.parse(data); } else { throw new Error('Not a valid JSON string'); } } else { throw new Error('Unknown content type'); } if (typeof(connection.ActionObj) !== 'undefined') { if ((connection.ActionObj.servletGroup === 'platform') && (connection.ActionObj.servlet === 'system') && (connection.ActionObj.action === 'CheckServerMessages') && (data.length === 0)) return; /* developer code start */ if (window.Framework.Methods.IsDeveloper() === true) { //var timeTaken = (new Date().getTime() - connection.ActionObj.Frame.Start); console.log('Time Taken: ' + 'Servlet: ' + this.servlet + '\n' + 'API: ' + this.action + '\n' + 'Time: ' + connection.ActionObj.Frame.Duration()); if ((typeof(data.CallStack) !== 'undefined') && (data.CallStack !== null)) { //connection.ActionObj.CallStack = data.CallStack; //var frame = this.Frame.NewFrame(); //frame.Method = this.api; data.CallStack.Frames.unshift(this.Frame); delete data.CallStack; } } /* developer code end */ } var handler = jQuery.proxy(function(msg){ if ((typeof(msg) !== 'undefined') && (msg.LoggedIn === 0) && (this.action !== 'CheckLoggedIn')) window.Framework.UnresolvedActions.push(this); }, this); if (typeof(this.onError) === 'function') handler = this.onError; // the server is trying to tell us something, hand the message to system if (typeof(data) === 'object') { if (Array.isArray(data.NewKey) === true) { pumpKeyA = data.NewKey[0]; pumpKeyB = data.NewKey[1]; } /* developer code start */ //if (window.Framework.Methods.IsDeveloper() === true) console.log('B3-CALLBACK FROM: ' + _createURL()); /* developer code end */ if (typeof(data[pumpKeyB]) !== 'undefined') { var outputter = new PumpProcess(); outputter.process(data, handler); } if (typeof(data.msg) !== 'undefined') if (data.msg !== '') msg = atob(data.msg); } else { msg = data; } if (typeof(this.opt_SuccessCallback) === 'function') this.opt_SuccessCallback(data); }, this); var _Callback_OnComplete = jQuery.proxy(function(data, status, connection) { if ((typeof(this.onComplete) !== 'undefined') && (this.onComplete !== null)) this.onComplete(data); }, this); var _Callback_OnError = jQuery.proxy(function(connection, status, errorText) { if (typeof(connection) === 'undefined') return; window.__handleConnectionError(connection, connection.status, errorText, true); if ((this.showLoading === true) && (typeof(this.caller) !== 'undefined') && (this.caller !== null) && (typeof(this.caller.__actionLoader) !== 'undefined') && (this.caller.__actionLoader !== null)) this.caller.__actionLoader.CompleteTask(this.servlet + '-' + this.action); if (typeof(this.onError) === 'function') this.onError(); if (StaticLib.IsJSONString(connection.responseText) === true) { var outputter = new PumpProcess(); outputter.process(connection.responseText, function(){}); return; } }, this); var _createURL = jQuery.proxy(function() { var layout = ''; var group = ''; if ((typeof(this.caller) !== 'undefined') && (this.caller !== null)) { if (this.args === null) this.args = {}; this.args.caller = this.caller; } if (this.callbackName !== null) { if (this.args === null) this.args = {}; this.args.callback = this.callbackName; } if (this.controlID !== null) { if (this.args === null) this.args = {}; this.args.controlID = this.controlID; } // is this a proxy call if (this.prop.proxy) { if (this.args === null) this.args = {}; this.args.proxy = 1; if (this.postData === null) this.postData = {}; this.postData.proxy = {servlet: this.prop.servlet, view: this.prop.view}; } if (typeof(this.caller) !== 'undefined') { var parentApp = this.caller; if (((typeof(parentApp.OuterParentObject) === 'object') && (parentApp.OuterParentObject !== null)) || ((typeof(parentApp.prop) !== 'undefined') && (typeof(parentApp.prop.ParentObject) === 'object') && (parentApp.prop.ParentObject !== null))) { while (parentApp.OuterParentObject) parentApp = parentApp.OuterParentObject; parentApp = parentApp.prop.ParentObject; if (typeof(parentApp.GetValue) === 'function') parentApp = parentApp.GetValue(); } if (AppStaticLib.IsAnApp(parentApp)) { if (this.args === null) this.args = {}; this.args.r = parentApp.prop.struct.CurrentRecord; layout = parentApp.AppDetails.view; group = this.caller.AppDetails.servletGroup; } } var outputter = new PumpProcess(); outputter.Flatten(this.args); var extraArgs = ''; if ((this.action !== 'display') && (this.args !== null)) jQuery.each(this.args, function( index, value ) { if (value !== null) extraArgs = extraArgs + '&' + index + '=' + encodeURI(value); }); if (this.servletGroup !== '') group = this.servletGroup; if ((group === '')) throw new Error ('Group was not set'); if (layout === '') layout = 'default'; var frameworkID = window.FrameworkID; if ((typeof(window.Framework.V5) === 'object') && (window.Framework.V5 !== null) && (typeof(window.Framework.V5.RunningFrameworkID) === 'string')) frameworkID = window.Framework.V5.RunningFrameworkID; this.LastCalledURL = group + '/' + this.servlet + '/' + layout + '/' + this.action + '/?' + 'f=' + frameworkID + extraArgs; return this.LastCalledURL; }, this); this.PreviewContent = function(IFrameName) { if (typeof(this.postData) !== 'object') throw new Error(__METHOD__ + ' reports that should only be called with PreviewContent Data on line ' + __LINE__); var url = _createURL(); var params = this.postData; var newWindow = true; var addParam = function(paramName, paramValue) { var input = jQuery(''); if (typeof(paramValue) ==='object') paramValue = JSON.stringify(paramValue); input.attr({'id': paramName, 'name': paramName, 'value': paramValue}); form.append(input); }; var form = jQuery(''); form.attr('action', url); form.attr('method', 'POST'); var targetName = '_blank'; if ((typeof(IFrameName) !== 'undefined') && (IFrameName !== null) && (IFrameName !== '')) targetName = IFrameName; if (newWindow === true) form.attr('target', targetName); for (var key in params) addParam(key, params[key]); // Submit the form, then remove it from the page assertgroup('compiler', 'debug compiler points that you need to know about compiler keys'); form.appendTo(document.body); form.submit(); form.remove(); }; this.invoke = function(opt_resetTimer) { var _link = _createURL(); var tempVal = null; var temp = ''; /* developer code start */ if (window.Framework.Methods.IsDeveloper() === true) { this.Frame.Start = window.performance.now(); this.Frame.Method = this.action; assertgroup('stack', 'debugging the client and server side callstack'); //this.Frame.IsProxyCall = this.prop.proxy; //this.Frame.ProxyServletGroup = this.proxyServlet; //this.Frame.ProxyServlet = this.proxyView; //this.Frame.ProxyView = this.proxyServletGroup; this.Frame.URL = _link; } /* developer code end */ if (typeof(this.opt_BeforeInvoke) === 'function') this.opt_BeforeInvoke(this); if ((this.showLoading) && (AppStaticLib.IsAnApp(this.caller)) && (!jQuery(this.caller.prop.handle).hasClass('loading'))){ if ((typeof(this.caller.__actionLoader) === 'undefined') || (this.caller.__actionLoader === null)){ var overlay = document.createElement('div'); overlay.setAttribute('class', 'ui-widget-overlay ui-front'); overlay.setAttribute('style', 'position: absolute;'); jQuery(this.caller.prop.handle).append(overlay); debugger; var debug = false; if (debug === true) { this.progressbar = new window.Framework.Controls.ProgressBar ('', 'rectangle', 'append', '', this.caller); this.progressbar.vars.div.setAttribute('style', 'position: absolute; top: 0px;'); this.progressbar.load(); } var context = {GetAPI:this, overlay:overlay}; this.caller.__actionLoader = new TaskManagerControl({ParentObject: this.caller, TaskList: [this.servlet + '-' + this.action] , WhenDone: jQuery.proxy(function(){ jQuery(this.overlay).remove(); delete this.GetAPI.progressbar; this.GetAPI.caller.__actionLoader = null; }, context)}); } else { this.caller.__actionLoader.AddTask(this.servlet + '-' + this.action); } } temp = this.postData; tempVal = this.postData; if (this.oneVal === true) { if (((tempVal !== null) && (typeof(tempVal) === 'object')) && (typeof(tempVal.Serialize) === 'function')) tempVal = tempVal.Serialize(); temp = {POSTDATA: JSON.stringify(tempVal)}; } var method = 'POST'; if (this.action === 'CheckServerMessages') method = 'GET'; jQuery.ajax({ url: _link, method: method, data: temp, dataType: 'text', context: this, error: _Callback_OnError, complete: _Callback_OnComplete, success: _Callback_OnSuccess }).ActionObj = this; if ((typeof(opt_resetTimer) !== 'undefined') && (opt_resetTimer === false)) return; if ((typeof(window.Framework.prop) !== 'undefined') && (typeof(window.Framework.prop.SessionTimer) !== 'undefined') && (window.Framework.prop.SessionTimer !== null)) window.Framework.prop.SessionTimer.resetTimer(); }; this.clone = function() { return new window.Framework.Methods.GetAPI(this.servlet, this.action, this.caller, (this.callbackName) ? this.callbackName: undefined, this.postData, this.controlID); }; return this; }; StaticLib.DeepSeal(window.Framework.Methods.GetAPI); StaticLib.DeepFreeze(window.Framework.Methods.GetAPI); function DatasourceArray(o) { this.OrderBy = ''; this.UniqueID = ''; this.Prefetch = false; this.DatasourcePostdataArgs = []; this.callback = ''; this.caller = null; this.onComplete = null; this.opt_BeforeInvoke = null; this.IDlookup = {}; this.callCache = {}; this.Cache = []; this.DataLocation = ''; this.AllDataFetched = false; this.API = new window.Framework.Methods.GetAPIV2(o); if (typeof(o.OrderBy) === 'string') this.OrderBy = o.OrderBy; if (typeof(o.UniqueID) === 'string') this.UniqueID = o.UniqueID; if (o.Prefetch === true) this.Prefetch = true; if ((this.OrderBy === '') || (this.UniqueID === '')) throw new Error('Datasource expects and \'OrderBy\' and \'UniqueID\' string attribute in it\'s argument'); if ((typeof(o.DatasourcePostdataArgs) === 'object') && (typeof(o.DatasourcePostdataArgs.length) === 'number')) this.DatasourcePostdataArgs = o.DatasourcePostdataArgs; this.ReceivedURL = false; Object.defineProperty(this, 'ReceiveURL', { value: jQuery.proxy(function(url) { if (this.ReceivedURL === true) return; this.DataLocation = url; this.ReceivedURL = true; }, this) }); this.caller = this.API.from; this.API.caller = this; //this.DataLocation = this.API._createURL(); this.API.ReturnDataLocation(this); this.LastCalledURL = this.DataLocation; var index = this.DataLocation.indexOf('?'); if (index !== -1) this.DataLocation = this.DataLocation.substring(0, index); if (this.API.proxy === true) this.DataLocation = this.DataLocation + this.API.proxyServletGroup + '/' + this.API.proxyServlet + '/' + this.API.proxyView + '/'; if (this.DatasourcePostdataArgs.length > 0) { for (var count = 0; count < this.DatasourcePostdataArgs.length; count++) { if (typeof(this.API.postData[this.DatasourcePostdataArgs[count]]) === 'undefined') throw new Error('When creating DatasourceArray, the DatasourcePostdataArgs[] each need to refer to an attribute of the postData. ("' + this.DatasourcePostdataArgs[count] + '") not found)'); this.DataLocation = this.DataLocation + this.API.postData[this.DatasourcePostdataArgs[count]] + '/'; } } if (typeof(window.Framework.DataStores[this.DataLocation]) === 'undefined') { window.Framework.DataStores[this.DataLocation] = {Cache:[], Calls:{}, Prefetch: this.Prefetch, AllDataFetched: false, HasPrefetched: false}; } else if (this.Prefetch === true) { window.Framework.DataStores.Prefetch = this.Prefetch; } this.callbackName = this.API.callbackName; this.API.callbackName = '_Callback_OnSuccess'; Object.defineProperty(this, 'postData', { get: function() { return this.API.postData; }, set: function(value) { this.API.postData = value; }, enumerable: false, writeable: true, configurable: true }); Object.defineProperty(this, 'isControl', { get: function() { return this.API.isControl; }, set: function(value) { this.API.isControl = value; }, enumerable: false, writeable: true, configurable: true }); this._Callback_OnSuccess = jQuery.proxy(function(data) { this.AddToCache(data); var status = window.Framework.DataStores[this.DataLocation]; if (status.Prefetch !== true) { this.ReturnData(); } else { status.Prefetch = false; status.AllDataFetched = true; } }, this); this.invoke = function() { if (typeof(this.opt_BeforeInvoke) === 'function') this.opt_BeforeInvoke(this); if (this.MakeNewCall()) { var tempVal = this.API.prop.postData; if (typeof(tempVal.Serialize) === 'function') { tempVal = tempVal.Serialize(); } else { tempVal = JSON.stringify(this.API.prop.postData); } var callCache = window.Framework.DataStores[this.DataLocation].Calls; callCache[tempVal] = true; this.API.invoke(); } else { this.ReturnData(); } }; this.MakeNewCall = function() { var status = window.Framework.DataStores[this.DataLocation]; if (status.AllDataFetched === true) return false; var tempVal = this.API.prop.postData; if (typeof(tempVal.Serialize) === 'function') { tempVal = tempVal.Serialize(); } else { tempVal = JSON.stringify(this.API.prop.postData); } var callCache = window.Framework.DataStores[this.DataLocation].Calls; if (typeof(callCache[tempVal]) !== 'undefined') return false; return true; }; this.AddToCache = function(data) { for (var count = 0; count < data.length; count++) { if (typeof(this.IDlookup[data[count][this.UniqueID]]) !== 'undefined') continue; this.IDlookup[data[count][this.UniqueID]] = true; var index = 0; var DB = window.Framework.DataStores[this.DataLocation].Cache; while ((index < DB.length) && (data[count][this.UniqueID] < DB[index][this.UniqueID])) index++; DB.splice(index, 0, data[count]); } }; this.ReturnData = function() { var subset = []; var matched = 0; var limit = -1; var start = 0; if (typeof(this.API.prop.postData.Limit) === 'number') limit = this.API.prop.postData.Limit; if (typeof(this.API.prop.postData.Start) === 'number') start = this.API.prop.postData.Start; var matches = jQuery.proxy(function(row) { if (typeof(this.API.prop.postData.SearchVal) === 'undefined') return true; if (typeof(this.API.prop.postData.SearchBy) === 'undefined') return true; var tempIndex = 0; //Only acceptable if found at the beginning (index 0) var tempSearch = this.API.prop.postData.SearchVal.toLowerCase(); if (tempSearch.charAt(0) === '%') { tempIndex = 9999; //starts with %, so find match at any index tempSearch = tempSearch.slice(1); } if (tempSearch.substr(-1) === '%') tempSearch = tempSearch.slice(0, (tempSearch.length - 1)); var searchVal = row[this.API.prop.postData.SearchBy].toString().toLowerCase(); var foundIndex = searchVal.indexOf(tempSearch); if (foundIndex > tempIndex) return false; //found later in the string than acceptable, return FALSE if (foundIndex <= -1) return false; //NOT FOUND! Not acceptable, return FALSE return true; }, this); var DB = window.Framework.DataStores[this.DataLocation].Cache; for (var count = 0; count < DB.length; count++) { if (matches(DB[count])) { if (matched >= start) { subset.push(DB[count]); } else { matched++; } if ((limit > -1) && (subset.length >= limit)) break; } } this.caller[this.callbackName](subset); if (typeof(this.onComplete) === 'function') this.onComplete(subset); }; var status = window.Framework.DataStores[this.DataLocation]; if ( (status.Prefetch === true) & (status.HasPrefetched === false)) { status.HasPrefetched = true; var initialData = {}; if (typeof(this.API.prop.postData.Limit) === 'number') initialData.Limit = this.API.prop.postData.Limit; this.API.prop.postData.Limit = null; if (typeof(this.API.prop.postData.Start) === 'number') { initialData.Start = this.API.prop.postData.Start; this.API.prop.postData.Start = 0; } if (typeof(this.API.prop.postData.SearchVal) === 'undefined') { initialData.SearchVal = this.API.prop.postData.SearchVal; this.API.prop.postData.SearchVal = '%'; this.API.prop.postData.OrderBy = this.OrderBy; } this.invoke(); StaticLib.SetProps(this.API.prop.postData, initialData); } } StaticLib.DeepSeal(DatasourceArray); StaticLib.DeepFreeze(DatasourceArray);