function BootstrapBase() { var gSobject = gs.init('BootstrapBase'); gSobject.clazz = { name: 'BootstrapBase', simpleName: 'BootstrapBase'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.completed = false; gSobject.callbacks = gs.list([]); gSobject['callback'] = function(callback) { if (gs.bool(gSobject.completed)) { return gs.execCall(callback, this, []); }; return gs.mc(gSobject.callbacks,"add",[callback]); } gSobject['runCallbacks'] = function(it) { gSobject.completed = true; return gs.mc(gSobject.callbacks,"each",[function(callback) { return gs.execCall(callback, this, []); }]); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function Transmission() { var gSobject = gs.init('Transmission'); gSobject.clazz = { name: 'Transmission', simpleName: 'Transmission'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'onReady', { get: function() { return Transmission.onReady; }, set: function(gSval) { Transmission.onReady = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'onAuthReady', { get: function() { return Transmission.onAuthReady; }, set: function(gSval) { Transmission.onAuthReady = gSval; }, enumerable: true }); if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; Transmission.onReady = BootstrapBase(); Transmission.onAuthReady = BootstrapBase(); function StartupParams() { var gSobject = gs.init('StartupParams'); gSobject.clazz = { name: 'StartupParams', simpleName: 'StartupParams'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.session = gs.execStatic(Session,'instance', this,[]); Object.defineProperty(gSobject, 'deviceReadyListers', { get: function() { return StartupParams.deviceReadyListers; }, set: function(gSval) { StartupParams.deviceReadyListers = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'bootstrapComplete', { get: function() { return StartupParams.bootstrapComplete; }, set: function(gSval) { StartupParams.bootstrapComplete = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'deviceReady', { get: function() { return StartupParams.deviceReady; }, set: function(gSval) { StartupParams.deviceReady = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'doAuthToken', { get: function() { return StartupParams.doAuthToken; }, set: function(gSval) { StartupParams.doAuthToken = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'supportOfflineStart', { get: function() { return StartupParams.supportOfflineStart; }, set: function(gSval) { StartupParams.supportOfflineStart = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'websocketClientDebug', { get: function() { return StartupParams.websocketClientDebug; }, set: function(gSval) { StartupParams.websocketClientDebug = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'offlineStartFunction', { get: function() { return StartupParams.offlineStartFunction; }, set: function(gSval) { StartupParams.offlineStartFunction = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'onlineStartNoAuthFunction', { get: function() { return StartupParams.onlineStartNoAuthFunction; }, set: function(gSval) { StartupParams.onlineStartNoAuthFunction = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'onlineStartAuthSuccessFunction', { get: function() { return StartupParams.onlineStartAuthSuccessFunction; }, set: function(gSval) { StartupParams.onlineStartAuthSuccessFunction = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'onlineStartTokenAuthFailedFunction', { get: function() { return StartupParams.onlineStartTokenAuthFailedFunction; }, set: function(gSval) { StartupParams.onlineStartTokenAuthFailedFunction = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'beforeSocketInit', { get: function() { return StartupParams.beforeSocketInit; }, set: function(gSval) { StartupParams.beforeSocketInit = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'afterSocketInit', { get: function() { return StartupParams.afterSocketInit; }, set: function(gSval) { StartupParams.afterSocketInit = gSval; }, enumerable: true }); gSobject.shouldCheckStartupAuth = function() { if (typeof checkStartupAuth !== 'undefined') { return checkStartupAuth } return true } gSobject['checkStartupAuth'] = function(it) { if (gs.execStatic(Utils,'getCookie', this,[gs.gp(Socket,"AUTH_TOKEN")])) { gs.println(gs.plus("Writing session auth to local storage:", gs.execStatic(Utils,'getCookie', this,[gs.gp(Socket,"AUTH_TOKEN")]))); gs.mc(gs.fs('localStorage', this, gSobject),"setItem",["authToken", gs.plus((gs.plus("\"", gs.execStatic(Utils,'getCookie', this,[gs.gp(Socket,"AUTH_TOKEN")]))), "\"")]); }; if (gs.execStatic(Utils,'getCookie', this,[gs.gp(Socket,"DEVICE_TOKEN")])) { gs.println(gs.plus("Writing device token to local storage:", gs.execStatic(Utils,'getCookie', this,[gs.gp(Socket,"DEVICE_TOKEN")]))); gs.mc(gs.fs('localStorage', this, gSobject),"setItem",["deviceToken", gs.plus((gs.plus("\"", gs.execStatic(Utils,'getCookie', this,[gs.gp(Socket,"DEVICE_TOKEN")]))), "\"")]); }; var rememberMe = gs.mc(gs.fs('localStorage', this, gSobject),"getItem",["remember_me"]); var rememberMeActive = rememberMe != "false"; if (gs.equals(rememberMe, "once")) { gs.mc(gs.fs('localStorage', this, gSobject),"setItem",["remember_me", "false"]); }; if ((gs.mc(gSobject,"shouldCheckStartupAuth",[])) && (gs.bool(StartupParams.doAuthToken))) { gs.println("Checking tokens..."); if (((!gs.bool(rememberMeActive)) || (!gs.bool(gs.gp(gSobject.session,"authToken")))) || (!gs.bool(gs.gp(gSobject.session,"deviceToken")))) { gs.println("Token NOT found"); gs.println("Redirecting to LOGIN"); return null; }; return gs.println("Tokens good"); }; } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; StartupParams.deviceReadyListers = gs.list([]); StartupParams.bootstrapComplete = false; StartupParams.deviceReady = true; StartupParams.doAuthToken = true; StartupParams.supportOfflineStart = false; StartupParams.websocketClientDebug = false; StartupParams.offlineStartFunction = null; StartupParams.onlineStartNoAuthFunction = function(it) { }; StartupParams.onlineStartAuthSuccessFunction = null; StartupParams.onlineStartTokenAuthFailedFunction = function(it) { return gs.println("onlineStartTokenAuthFailedFunction"); }; StartupParams.beforeSocketInit = function(it) { gs.println(gs.plus("beforeSocketInit:", StartupParams.supportOfflineStart)); if (gs.bool(StartupParams.supportOfflineStart)) { gs.println(gs.plus("beforeSocketInit:session.firstStartupCompleted:", gs.gp(this.session,"firstStartupCompleted"))); if (gs.bool(gs.gp(this.session,"firstStartupCompleted"))) { gs.println("startupParams.onlineStartFunction:3"); gs.mc(StartupParams,"offlineStartFunction",[]); StartupParams.bootstrapComplete = true; }; return gs.sp(this.session,"firstStartupCompleted",true); }; }; StartupParams.afterSocketInit = function(it) { gs.println("afterSocketInit"); if (!gs.bool(StartupParams.doAuthToken)) { gs.println("onlineStartNoAuthFunction:0"); gs.mc(StartupParams,"onlineStartNoAuthFunction",[]); StartupParams.bootstrapComplete = true; return null; }; return gs.execStatic(Utils,'tokenAuth', this,[function(it) { gs.println("onlineStartAuthSuccessFunction:1"); gs.mc(StartupParams,"onlineStartAuthSuccessFunction",[]); StartupParams.bootstrapComplete = true; return gs.mc(gs.gp(gs.fs('transmission', this),"onAuthReady"),"runCallbacks",[]); }, function(it) { gs.println("onlineStartTokenAuthFailedFunction:2"); gs.mc(StartupParams,"onlineStartTokenAuthFailedFunction",[]); StartupParams.bootstrapComplete = true; return gs.mc(gs.gp(gs.fs('transmission', this),"onAuthReady"),"runCallbacks",[]); }]); }; function Session() { var gSobject = gs.init('Session'); gSobject.clazz = { name: 'Session', simpleName: 'Session'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'sessionMap', { get: function() { return Session.sessionMap; }, set: function(gSval) { Session.sessionMap = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'self', { get: function() { return Session.self; }, set: function(gSval) { Session.self = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'zoner', { get: function() { return Session.zoner; }, set: function(gSval) { Session.zoner = gSval; }, enumerable: true }); gSobject.zonerRoleMap = gs.map(); gSobject.instance = function() { return Session.instance(); } gSobject.toJs = function() { return Session.toJs(); } gSobject.setSessionStorage = function(x0,x1) { return Session.setSessionStorage(x0,x1); } gSobject.getSessionStorage = function(x0) { return Session.getSessionStorage(x0); } gSobject.clear = function() { var remember_me = localStorage.getItem('remember_me'); localStorage.clear(); localStorage.setItem('remember_me', remember_me); } gSobject['setProperty'] = function(name, value) { (Session.sessionMap[name]) = value; Session.setSessionStorage(name, value); if (gs.equals(name, "zoner")) { Session.zoner = null; return gSobject.zonerRoleMap = gs.map(); }; } gSobject['getProperty'] = function(name) { if (!gs.bool(Session.sessionMap[name])) { var value = Session.getSessionStorage(name); (Session.sessionMap[name]) = value; }; return Session.sessionMap[name]; } gSobject['hasRole'] = function(roles) { var result = gSobject.zonerRoleMap[roles]; if (result != null) { return result; }; if (!gs.bool(Session.zoner)) { Session.zoner = gs.mc(gSobject,"getProperty",["zoner"]); }; if (!gs.bool(Session.zoner)) { return false; }; if (gs.instanceOf(roles, "String")) { result = (gs.gSin(roles, gs.gp(Session.zoner,"roles"))); (gSobject.zonerRoleMap[roles]) = result; return result; }; for (_i79 = 0, role = roles[0]; _i79 < roles.length; role = roles[++_i79]) { if (gs.gSin(role, gs.gp(Session.zoner,"roles"))) { (gSobject.zonerRoleMap[roles]) = true; return true; }; }; (gSobject.zonerRoleMap[roles]) = false; return false; } gSobject['toString'] = function(it) { return gs.mc(Session.sessionMap,"toString",[]); } gSobject['Session0'] = function(it) { gs.println("SESSION HERE I AM"); return this; } if (arguments.length==0) {gSobject.Session0(); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; Session.instance = function(it) { if (!gs.bool(Session.self)) { Session.self = Session(); }; return Session.self; } Session.toJs = function(it) { return Session.sessionMap; } Session.setSessionStorage = function(name, value) { value = JSON.stringify(value) localStorage.setItem(name, value) return value } Session.getSessionStorage = function(name) { var value = localStorage.getItem(name) try{ return gs.toGroovy(jQuery.parseJSON(value)) }catch(all){} return null } Session.sessionMap = gs.map(); Session.self = null; Session.zoner = null; function Modals() { var gSobject = gs.init('Modals'); gSobject.clazz = { name: 'Modals', simpleName: 'Modals'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.showModalCustom = function(x0,x1) { return Modals.showModalCustom(x0,x1); } gSobject.showModal = function(x0) { return Modals.showModal(x0); } gSobject.hideModal = function(x0) { return Modals.hideModal(x0); } gSobject.closeModal = function(x0) { return Modals.closeModal(x0); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; Modals.showModalCustom = function(id, type) { $(id).css("display", type); $(id).css("pointer-events", "initial"); } Modals.showModal = function(id) { $(id).css("display", "block"); $(id).css("pointer-events", "initial"); } Modals.hideModal = function(id) { $(id).css("display", "none"); $(id).css("pointer-events", "none"); } Modals.closeModal = function(id) { $(id).trigger( "click" ); } function Socket() { var gSobject = gs.init('Socket'); gSobject.clazz = { name: 'Socket', simpleName: 'Socket'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'SOCKET_URL', { get: function() { return Socket.SOCKET_URL; }, set: function(gSval) { Socket.SOCKET_URL = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'SOCKET_USER_URL', { get: function() { return Socket.SOCKET_USER_URL; }, set: function(gSval) { Socket.SOCKET_USER_URL = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'SOCKET_OBJECT_URL', { get: function() { return Socket.SOCKET_OBJECT_URL; }, set: function(gSval) { Socket.SOCKET_OBJECT_URL = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'SOCKET_OVER_HTTP_SYNCHRONOUS_URL', { get: function() { return Socket.SOCKET_OVER_HTTP_SYNCHRONOUS_URL; }, set: function(gSval) { Socket.SOCKET_OVER_HTTP_SYNCHRONOUS_URL = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'SOCKET_OVER_HTTP_ASYNCHRONOUS_URL', { get: function() { return Socket.SOCKET_OVER_HTTP_ASYNCHRONOUS_URL; }, set: function(gSval) { Socket.SOCKET_OVER_HTTP_ASYNCHRONOUS_URL = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'SESSION_REFRESH_MINS', { get: function() { return Socket.SESSION_REFRESH_MINS; }, set: function(gSval) { Socket.SESSION_REFRESH_MINS = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'SOCKET_CHECK_MSG_RECEIVED_SEC', { get: function() { return Socket.SOCKET_CHECK_MSG_RECEIVED_SEC; }, set: function(gSval) { Socket.SOCKET_CHECK_MSG_RECEIVED_SEC = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'SOCKET_RUNNER_RETRY_MS', { get: function() { return Socket.SOCKET_RUNNER_RETRY_MS; }, set: function(gSval) { Socket.SOCKET_RUNNER_RETRY_MS = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'SOCKET_QUEUE_TIMEOUT_MIN', { get: function() { return Socket.SOCKET_QUEUE_TIMEOUT_MIN; }, set: function(gSval) { Socket.SOCKET_QUEUE_TIMEOUT_MIN = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'AUTH_TOKEN', { get: function() { return Socket.AUTH_TOKEN; }, set: function(gSval) { Socket.AUTH_TOKEN = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'DEVICE_TOKEN', { get: function() { return Socket.DEVICE_TOKEN; }, set: function(gSval) { Socket.DEVICE_TOKEN = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'window', { get: function() { return Socket.window; }, set: function(gSval) { Socket.window = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'navigator', { get: function() { return Socket.navigator; }, set: function(gSval) { Socket.navigator = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'sendProtocol', { get: function() { return Socket.sendProtocol; }, set: function(gSval) { Socket.sendProtocol = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'queue', { get: function() { return Socket.queue; }, set: function(gSval) { Socket.queue = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'socketHeaders', { get: function() { return Socket.socketHeaders; }, set: function(gSval) { Socket.socketHeaders = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'userDataPipe', { get: function() { return Socket.userDataPipe; }, set: function(gSval) { Socket.userDataPipe = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'session', { get: function() { return Socket.session; }, set: function(gSval) { Socket.session = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'connected', { get: function() { return Socket.connected; }, set: function(gSval) { Socket.connected = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'socket', { get: function() { return Socket.socket; }, set: function(gSval) { Socket.socket = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'websocketClient', { get: function() { return Socket.websocketClient; }, set: function(gSval) { Socket.websocketClient = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'subscriptions', { get: function() { return Socket.subscriptions; }, set: function(gSval) { Socket.subscriptions = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'sessionRefresherThreads', { get: function() { return Socket.sessionRefresherThreads; }, set: function(gSval) { Socket.sessionRefresherThreads = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'socketReadyQueue', { get: function() { return Socket.socketReadyQueue; }, set: function(gSval) { Socket.socketReadyQueue = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'intervalRunner', { get: function() { return Socket.intervalRunner; }, set: function(gSval) { Socket.intervalRunner = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'reconnectMutex', { get: function() { return Socket.reconnectMutex; }, set: function(gSval) { Socket.reconnectMutex = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'SOCKET_PING_TIMEOUT_MS', { get: function() { return Socket.SOCKET_PING_TIMEOUT_MS; }, set: function(gSval) { Socket.SOCKET_PING_TIMEOUT_MS = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'websocketPingCount', { get: function() { return Socket.websocketPingCount; }, set: function(gSval) { Socket.websocketPingCount = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'nextQueueClean', { get: function() { return Socket.nextQueueClean; }, set: function(gSval) { Socket.nextQueueClean = gSval; }, enumerable: true }); gSobject.init = function() { return Socket.init(); } gSobject.initSocket = function(x0,x1) { return Socket.initSocket(x0,x1); } gSobject.socketReady = function(x0) { return Socket.socketReady(x0); } gSobject.socketReadyQueueCallAll = function() { return Socket.socketReadyQueueCallAll(); } gSobject.addUserDataPipe = function() { return Socket.addUserDataPipe(); } gSobject.startSessionRefresher = function() { return Socket.startSessionRefresher(); } gSobject.sessionRefresher = function(x0,x1) { return Socket.sessionRefresher(x0,x1); } gSobject.reconnect = function(x0) { return Socket.reconnect(x0); } gSobject.socketConnectionInterval = function(x0,x1) { return Socket.socketConnectionInterval(x0,x1); } gSobject.socketConnect = function(x0,x1,x2) { return Socket.socketConnect(x0,x1,x2); } gSobject.pingHttp = function(callback) { if (!this.inUse) { this.status = 'unchecked'; this.inUse = true; this.callback = callback; this.ip = ip; var _that = this; this.img = new Image(); this.img.onload = function () { _that.inUse = false; _that.callback('responded'); }; this.img.onerror = function (e) { if (_that.inUse) { _that.inUse = false; _that.callback('responded', e); } }; this.start = new Date().getTime(); this.img.src = 'http://'+ window.location.hostname + '/index/ping'; this.timer = setTimeout(function () { if (_that.inUse) { _that.inUse = false; _that.callback('timeout'); } }, 1500); } } gSobject.pingWebSocket = function(x0) { return Socket.pingWebSocket(x0); } gSobject.remote = function(x0,x1,x2,x3) { return Socket.remote(x0,x1,x2,x3); } gSobject.callChain = function(x0,x1,x2) { return Socket.callChain(x0,x1,x2); } gSobject.callObject = function(x0,x1,x2,x3,x4) { return Socket.callObject(x0,x1,x2,x3,x4); } gSobject.isDymicoSystemUpdating = function() { return Socket.isDymicoSystemUpdating(); } gSobject.send = function(x0,x1,x2,x3) { return Socket.send(x0,x1,x2,x3); } gSobject.doSend = function(x0,x1) { return Socket.doSend(x0,x1); } gSobject.doSendNativeHttp = function(x0,x1) { return Socket.doSendNativeHttp(x0,x1); } gSobject.doSendNative = function(x0,x1) { return Socket.doSendNative(x0,x1); } gSobject.checkMessageReceived = function(x0) { return Socket.checkMessageReceived(x0); } gSobject.resendMessageQueue = function() { return Socket.resendMessageQueue(); } gSobject.cleanQueue = function() { return Socket.cleanQueue(); } gSobject.receive = function(x0) { return Socket.receive(x0); } gSobject.processException = function(x0) { return Socket.processException(x0); } gSobject.subscribe = function(x0,x1,x2) { return Socket.subscribe(x0,x1,x2); } gSobject.addSubscription = function(x0,x1,x2) { return Socket.addSubscription(x0,x1,x2); } gSobject.subscribeJs = function(x0,x1,x2) { return Socket.subscribeJs(x0,x1,x2); } gSobject.doReceiveNative = function(x0,x1) { return Socket.doReceiveNative(x0,x1); } gSobject.resubscribeAll = function() { return Socket.resubscribeAll(); } gSobject.unsubscribe = function(x0,x1) { return Socket.unsubscribe(x0,x1); } gSobject.post = function(x0,x1,x2,x3,x4) { return Socket.post(x0,x1,x2,x3,x4); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; Socket.init = function(it) { gs.sp(Socket.session,"domain",gs.gp(gs.gp(Socket.window,"location"),"hostname")); gs.sp(Socket.session,"incomingUrl",(gs.plus((gs.plus(gs.gp(gs.gp(Socket.window,"location"),"protocol"), "//")), gs.gp(gs.gp(Socket.window,"location"),"hostname")))); gs.sp(Socket.socketHeaders,"domain",gs.gp(gs.gp(Socket.window,"location"),"hostname")); gs.sp(Socket.socketHeaders,"" + (Socket.AUTH_TOKEN) + "",gs.execStatic(Utils,'getAuthToken', this,[])); gs.sp(Socket.socketHeaders,"" + (Socket.DEVICE_TOKEN) + "",gs.execStatic(Utils,'getDeviceToken', this,[])); return gs.sp(GrooscriptGrails,"remoteUrl",gs.gp(Socket.session,"incomingUrl")); } Socket.initSocket = function(success, failure) { if (success === undefined) success = null; if (failure === undefined) failure = null; return gs.execStatic(Socket,'socketConnectionInterval', this,[Socket.socketHeaders, success, failure]); } Socket.socketReady = function(callback) { gs.println("socketReady"); gs.println(callback); if (gs.bool(Socket.connected)) { gs.execCall(callback, this, []); return null; }; return gs.mc(Socket.socketReadyQueue,"add",[callback]); } Socket.socketReadyQueueCallAll = function(it) { gs.println("socketReadyQueueCallAll"); gs.println(Socket.socketReadyQueue); var socketReadyQueueLocal = Socket.socketReadyQueue; Socket.socketReadyQueue = gs.list([]); return gs.mc(socketReadyQueueLocal,"each",[function(callback) { try { gs.execCall(callback, this, []); } catch (all) { gs.println(gs.fs('all', this)); } ; }]); } Socket.addUserDataPipe = function(it) { gs.println("addUserDataPipe"); return Socket.addSubscription(gs.execStatic(Utils,'getDeviceToken', this,[]), Socket.SOCKET_USER_URL, Socket.userDataPipe); } Socket.startSessionRefresher = function(it) { gs.println("starting session refresher"); gs.println(gs.gp(Socket.session,"authToken")); if (gs.bool(gs.gp(Socket.session,"authToken"))) { var sessionRefresherCallback = function(data) { gs.println("sessionRefresherCallback"); gs.println(data); if (data != "authed") { gs.println("NOT AUTHED"); return gs.execStatic(Utils,'logout', this,[]); }; }; Socket.sessionRefresher(gs.gp(Socket.session,"authToken"), sessionRefresherCallback); for (_i80 = 0, sessionRefresherThread = Socket.sessionRefresherThreads[0]; _i80 < Socket.sessionRefresherThreads.length; sessionRefresherThread = Socket.sessionRefresherThreads[++_i80]) { gs.execStatic(Utils,'clearInterval', this,[sessionRefresherThread]); gs.mc(Socket.sessionRefresherThreads,"remove",[sessionRefresherThread]); }; return gs.mc(Socket.sessionRefresherThreads,"add",[gs.execStatic(Utils,'setInterval', this,[function(it) { return gs.mc(Socket,"sessionRefresher",[gs.gp(Socket.session,"authToken"), sessionRefresherCallback]); }, gs.multiply((gs.multiply(1000, 60)), Socket.SESSION_REFRESH_MINS)])]); }; } Socket.sessionRefresher = function(token, sessionRefresherCallback) { console.log("refresing:" + token +':'+new Date()); $.ajax({ url : '/login/tokenAuth?token='+token, type : 'GET', processData: false, contentType: false, success : function(data) { console.log("grails session re-auth:"+data); sessionRefresherCallback(data) } }); } Socket.reconnect = function(retryInMs) { if (retryInMs === undefined) retryInMs = 0; if (gs.bool(retryInMs)) { return gs.execStatic(Utils,'setTimeout', this,[function(it) { return gs.mc(Socket,"reconnect",[]); }, retryInMs]); }; if ((gs.bool(Socket.reconnectMutex)) || (!gs.bool(Socket.intervalRunner))) { return Socket.reconnect(500); }; Socket.reconnectMutex = true; return gs.mc(Socket,"intervalRunner",[function(it) { return Socket.reconnectMutex = false; }]); } Socket.socketConnectionInterval = function(socketHeadersx, success) { var reconnectCallback = function(it) { gs.println("Socket reconnected"); Socket.connected = true; gs.mc(Socket,"addUserDataPipe",[]); gs.mc(Socket,"resubscribeAll",[]); gs.mc(Socket,"resendMessageQueue",[]); gs.mc(Socket,"startSessionRefresher",[]); gs.execCall(success, this, []); success = function(it) { }; return gs.mc(Socket,"socketReadyQueueCallAll",[]); }; var disconnectSockets = function(it) { gs.println("Socket disconnect"); Socket.connected = false; try { gs.mc(gs.gp(Socket,"websocketClient"),"disconnect",[]); } catch (all) { } ; }; Socket.intervalRunner = function(done) { gs.println(gs.plus((gs.plus((gs.plus((gs.plus((gs.plus("navigator.onLine:", gs.gp(Socket.navigator,"onLine"))), ":")), gs.gp(gs.gp(Socket,"websocketClient"),"connected"))), ":")), Socket.connected)); if (!gs.bool(gs.gp(gs.gp(Socket,"websocketClient"),"connected"))) { gs.println("Socket.websocketClient.connected:false:reconnecting..."); gs.mc(Socket,"socketConnect",[gs.map().add("domain",gs.gp(Socket.session,"domain")), function(it) { gs.println(gs.plus("Socket.websocketClient.connected:", gs.gp(gs.gp(Socket,"websocketClient"),"connected"))); Socket.connected = true; gs.execCall(reconnectCallback, this, []); return gs.execCall(done, this, []); }, function(it) { gs.println("Socket.websocketClient.connected:connection down"); gs.execCall(disconnectSockets, this, []); gs.execCall(done, this, []); if (gs.bool(Socket.queue)) { return gs.mc(Socket,"reconnect",[Socket.SOCKET_RUNNER_RETRY_MS]); }; }]); return null; }; gs.println("Sockets believed to be online. Pinging socket connection..."); gs.mc(Socket,"pingWebSocket",[function(pingResponse) { gs.println(gs.plus("pingWebSocket:", pingResponse)); if (gs.equals(pingResponse, "timeout")) { gs.println("Connection timed out, reconnecting..."); gs.execCall(disconnectSockets, this, []); gs.mc(Socket,"reconnect",[]); return gs.execCall(done, this, []); }; gs.println("Connection good, false alarm."); return gs.execCall(done, this, []); }]); return gs.println(gs.plus("intervalRunner:Socket.websocketClient.connected:", gs.gp(gs.gp(Socket,"websocketClient"),"connected"))); }; return Socket.reconnect(); } Socket.socketConnect = function(socketHeaders, success, failed) { try{ Socket.socket = new SockJS('/stomp'); Socket.websocketClient = Stomp.over(Socket.socket); if (!StartupParams.websocketClientDebug){ //switch off debuggging Socket.websocketClient.debug = function () {} } Socket.websocketClient.connect(gs.toJavascript(socketHeaders), success, failed); }catch(error) { console.info(error); } } Socket.pingWebSocket = function(callback) { var websocketPingCountNow = Socket.websocketPingCount; var wrapper = gs.mc(gs.map().add("uuid","ping").add("call","callChain").add("data",gs.list([gs.map().add("property","transmissionService") , gs.map().add("method","ping")])),'leftShift', gs.list([Socket.socketHeaders])); Socket.doSendNative(Socket.SOCKET_URL, wrapper); return gs.execStatic(Utils,'setTimeout', this,[function(it) { if (gs.equals(websocketPingCountNow, Socket.websocketPingCount)) { gs.execCall(callback, this, ["timeout"]); return null; }; return gs.execCall(callback, this, ["responded"]); }, Socket.SOCKET_PING_TIMEOUT_MS]); } Socket.remote = function(closure, data, success, fail) { if (success === undefined) success = null; if (fail === undefined) fail = null; return gs.execStatic(Socket,'send', this,["remoteExec", closure, data, success, fail]); } Socket.callChain = function(callChain, success, fail) { if (success === undefined) success = null; if (fail === undefined) fail = null; if (Socket.isDymicoSystemUpdating()) { return null; }; gs.println(gs.plus("callChain:", callChain)); return gs.execStatic(Socket,'send', this,["callChain", callChain, success, fail]); } Socket.callObject = function(self, method, args, success, fail) { if (fail === undefined) fail = null; if (Socket.isDymicoSystemUpdating()) { return null; }; gs.println(gs.plus("callObject:OObject:", self)); gs.println(gs.plus("callObject:method:", method)); return gs.execStatic(Socket,'send', this,["callObject", gs.map().add("self",self).add("method",method).add("args",args), success, fail]); } Socket.isDymicoSystemUpdating = function() { try{ if (typeof dymicoVersionUpdater !== 'undefined') { return dymicoVersionUpdater.dymicoSystemUpdating; } }catch(all){ } return false; } Socket.send = function(call, data, success, fail) { if (fail === undefined) fail = null; var uuid = gs.execStatic(Utils,'uuid', this,[]); var wrapper = gs.map().add("uuid",uuid).add("call",call).add("data",data); var queueItem = gs.map().add("success",success).add("fail",fail).add("dataStr",gs.mc(data,"toString",[])).add("date",gs.gp(gs.date(),"time")).add("wrapper",wrapper); (Socket.queue[uuid]) = queueItem; Socket.doSend(Socket.SOCKET_URL, queueItem); return uuid; } Socket.doSend = function(channel, queueItem) { if (gs.equals(Socket.sendProtocol, "websocket")) { Socket.doSendNative(channel, gs.mc(gs.gp(queueItem,"wrapper"),'leftShift', gs.list([Socket.socketHeaders]))); gs.execStatic(Utils,'setTimeout', this,[function(it) { return gs.mc(Socket,"checkMessageReceived",[queueItem]); }, gs.multiply(Socket.SOCKET_CHECK_MSG_RECEIVED_SEC, 1000)]); if (!gs.bool(Socket.connected)) { return Socket.reconnect(); }; } else { if (gs.equals(Socket.sendProtocol, "http")) { return Socket.doSendNativeHttp(gs.mc(gs.gp(queueItem,"wrapper"),'leftShift', gs.list([Socket.socketHeaders])), function(it) { gs.println("HTTP TIMEOUT"); return gs.mc(Socket,"reconnect",[]); }); } else { throw "Exception"; }; }; } Socket.doSendNativeHttp = function(map, timeoutCallback) { var sendMessage = map; sendMessage = JSON.stringify(sendMessage); // sendMessage = LZString.compressToBase64(sendMessage); //no compression needed, cause the browser will gzip it anyway sendMessage = "message="+encodeURIComponent(sendMessage) var xhr = new XMLHttpRequest(); xhr.ontimeout = timeoutCallback xhr.open('POST', Socket.SOCKET_OVER_HTTP_SYNCHRONOUS_URL, true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function(e) { if (this.status == 404) { console.log('AJAX FAILED'); } if (this.readyState == 4 && this.status == 200) { Socket.receive(Socket.doReceiveNative(this.responseText, false)) } }; xhr.send(sendMessage); } Socket.doSendNative = function(channel, map) { try{ var sendMessage = map; sendMessage = JSON.stringify(sendMessage) sendMessage = LZString.compressToBase64(sendMessage) return Socket.websocketClient.send(channel, {}, sendMessage); }catch(all){ } } Socket.checkMessageReceived = function(queueItem) { if (Socket.queue[gs.gp(gs.gp(queueItem,"wrapper"),"uuid")]) { Socket.reconnect(); return Socket.cleanQueue(); }; } Socket.resendMessageQueue = function(it) { return gs.mc(gs.mc(gs.mc(Socket.queue,"values",[]),"sort",[function(it) { return gs.gp(it,"date",true); }]),"each",[function(queueItem) { return gs.mc(Socket,"doSend",[Socket.SOCKET_URL, queueItem]); }]); } Socket.cleanQueue = function(it) { if (Socket.nextQueueClean < gs.gp(gs.date(),"time")) { var timeoutMs = gs.multiply((gs.multiply(Socket.SOCKET_QUEUE_TIMEOUT_MIN, 60)), 1000); Socket.nextQueueClean = (gs.plus(gs.gp(gs.date(),"time"), timeoutMs)); gs.println(gs.plus("nextQueueClean:", Socket.nextQueueClean)); gs.println("cleanQueue.start"); var timeout = gs.minus(gs.gp(gs.date(),"time"), timeoutMs); gs.println(gs.plus("cleanQueue.queue.size:", gs.mc(Socket.queue,"size",[]))); gs.mc(Socket.queue,"each",[function(key, queueItem) { if (gs.gp(queueItem,"date") < timeout) { gs.println("REMOVED"); gs.mc(Socket.queue,"remove",[key]); return gs.mc(queueItem,"fail",[]); }; }]); return gs.println("cleanQueue.end"); }; } Socket.receive = function(wrapper) { Socket.websocketPingCount++; if (gs.equals(gs.gp(wrapper,"uuid"), "ping")) { return null; }; var queueItem = Socket.queue[gs.gp(wrapper,"uuid")]; gs.mc(Socket.queue,"remove",[gs.gp(wrapper,"uuid")]); if (gs.bool(gs.gp(wrapper,"error"))) { Socket.processException(gs.gp(wrapper,"data")); if (gs.bool(gs.gp(queueItem,"fail"))) { gs.mc(queueItem,"fail",[gs.gp(wrapper,"data")]); }; throw "Exception"; return null; }; if (gs.bool(queueItem)) { var object = gs.execStatic(ObjectRegistry,'register', this,[gs.gp(wrapper,"data")]); if (gs.bool(gs.gp(queueItem,"success"))) { return gs.mc(queueItem,"success",[object]); }; }; } Socket.processException = function(ex) { gs.execStatic(Utils,'logExceptionStack', this,[gs.plus((gs.plus((gs.plus("", (ex["class"]))), ":")), gs.gp(ex,"message"))]); gs.mc(gs.gp(ex,"stackTrace"),"each",[function(it) { return gs.execStatic(Utils,'logExceptionStack', this,[gs.plus((gs.plus((gs.plus((gs.plus((gs.plus((gs.plus((gs.plus((gs.plus(" at:", gs.gp(it,"className"))), ".")), gs.gp(it,"methodName"))), "(")), gs.gp(it,"fileName"))), ":")), gs.gp(it,"lineNumber"))), ")")]); }]); return gs.println(ex); } Socket.subscribe = function(objectId, success, topic) { if (topic === undefined) topic = Socket.SOCKET_OBJECT_URL; gs.println(gs.plus("subscribe:", objectId)); Socket.unsubscribe(objectId, topic); var successWrapper = function(messageObject) { if (gs.equals(topic, Socket.SOCKET_OBJECT_URL)) { return gs.execCall(success, this, [gs.execStatic(ObjectRegistry,'register', this,[messageObject])]); }; return gs.execCall(success, this, [messageObject]); }; Socket.addSubscription(objectId, topic, success); try { Socket.subscribeJs(objectId, gs.plus(topic, objectId), successWrapper); } catch (all) { gs.println("subscribeJs failed"); gs.println(all); } ; } Socket.addSubscription = function(objectId, topic, success) { return (Socket.subscriptions[objectId]) = gs.map().add("objectId",objectId).add("success",success).add("topic",topic); } Socket.subscribeJs = function(objectId, subId, success) { console.log('subscribeJs:'+subId) return Socket.websocketClient.subscribe(subId, function(message){ success(Socket.doReceiveNative(message.body)) }, {id:objectId}) } Socket.doReceiveNative = function(message, compressed) { if (compressed === undefined) compressed = true; if (compressed) message = LZString.decompressFromBase64(message) var jsonMessage = JSON.parse(message, function(key, value) { if (typeof value === 'string') { //var a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); var a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})?\.(\d*)?Z$/.exec(value); if (a) { return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6], +a[7])); } } return value; } ) return gs.toGroovy(jsonMessage) } Socket.resubscribeAll = function(it) { gs.println("resubscribeAll"); gs.println(Socket.subscriptions); var oldSubscriptions = Socket.subscriptions; Socket.subscriptions = gs.map(); return gs.mc(oldSubscriptions,"each",[function(key, subscription) { return gs.mc(Socket,"subscribe",[gs.gp(subscription,"objectId"), gs.gp(subscription,"success"), gs.gp(subscription,"topic")]); }]); } Socket.unsubscribe = function(objectId, topic) { if (topic === undefined) topic = Socket.SOCKET_OBJECT_URL; gs.println(gs.plus("unsubscribe:", objectId)); try { gs.mc(gs.gp(Socket,"websocketClient"),"unsubscribe",[objectId]); gs.mc(Socket.subscriptions,"remove",[objectId]); } catch (all) { gs.println(all); } ; } Socket.post = function(file, parameter, objectName, id, callback) { var postUrl = "/post/upload"; var formData = new FormData(); formData.append('file', file); formData.append('id', id); formData.append('parameter', parameter); formData.append('objectName', objectName); $.ajax({ url : postUrl, type : 'POST', data : formData, processData: false, // tell jQuery not to process the data contentType: false, // tell jQuery not to set contentType success : function(data) { console.log(data); callback(data); } }); } Socket.SOCKET_URL = "/app/api4WebSocketForPublic"; Socket.SOCKET_USER_URL = "/topic/api4WebSocketForUser/"; Socket.SOCKET_OBJECT_URL = "/topic/api4WebSocketForObject/"; Socket.SOCKET_OVER_HTTP_SYNCHRONOUS_URL = "/api4WebSocket/synchronous"; Socket.SOCKET_OVER_HTTP_ASYNCHRONOUS_URL = "/api4WebSocket/asynchronous"; Socket.SESSION_REFRESH_MINS = 10; Socket.SOCKET_CHECK_MSG_RECEIVED_SEC = 7; Socket.SOCKET_RUNNER_RETRY_MS = 5000; Socket.SOCKET_QUEUE_TIMEOUT_MIN = 2; Socket.AUTH_TOKEN = "secToken2"; Socket.DEVICE_TOKEN = "deviceToken1"; Socket.window = null; Socket.navigator = null; Socket.sendProtocol = "http"; Socket.queue = gs.map(); Socket.socketHeaders = gs.map(); Socket.userDataPipe = function(data) { return gs.mc(Socket,"receive",[data]); }; Socket.session = gs.execStatic(Session,'instance', this,[]); Socket.connected = false; Socket.socket = null; Socket.websocketClient = gs.map().add("connected",false).add("disconnect",function(it) { }).add("subscriptions",function(it) { }); Socket.subscriptions = gs.map(); Socket.sessionRefresherThreads = gs.list([]); Socket.socketReadyQueue = gs.list([]); Socket.intervalRunner = null; Socket.reconnectMutex = false; Socket.SOCKET_PING_TIMEOUT_MS = 3000; Socket.websocketPingCount = 0; Socket.nextQueueClean = 0; function Utils() { var gSobject = gs.init('Utils'); gSobject.clazz = { name: 'Utils', simpleName: 'Utils'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'session', { get: function() { return Utils.session; }, set: function(gSval) { Utils.session = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'window', { get: function() { return Utils.window; }, set: function(gSval) { Utils.window = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'document', { get: function() { return Utils.document; }, set: function(gSval) { Utils.document = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'DeviceTypes', { get: function() { return Utils.DeviceTypes; }, set: function(gSval) { Utils.DeviceTypes = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'AUTH_FAILED', { get: function() { return Utils.AUTH_FAILED; }, set: function(gSval) { Utils.AUTH_FAILED = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'NO_AUTH', { get: function() { return Utils.NO_AUTH; }, set: function(gSval) { Utils.NO_AUTH = gSval; }, enumerable: true }); gSobject.getAuthToken = function() { return Utils.getAuthToken(); } gSobject.getDeviceToken = function() { return Utils.getDeviceToken(); } gSobject.setTimeout = function(x0,x1) { return Utils.setTimeout(x0,x1); } gSobject.setInterval = function(x0,x1) { return Utils.setInterval(x0,x1); } gSobject.clearInterval = function(x0) { return Utils.clearInterval(x0); } gSobject.documentReady = function(x0) { return Utils.documentReady(x0); } gSobject.uuid = function() { return Utils.uuid(); } gSobject.callChain = function(x0,x1,x2) { return Utils.callChain(x0,x1,x2); } gSobject.callObject = function(x0,x1,x2,x3,x4) { return Utils.callObject(x0,x1,x2,x3,x4); } gSobject.send = function(x0,x1,x2,x3) { return Utils.send(x0,x1,x2,x3); } gSobject.subscribe = function(x0,x1,x2) { return Utils.subscribe(x0,x1,x2); } gSobject.unsubscribe = function(x0) { return Utils.unsubscribe(x0); } gSobject.guid = function() { return Utils.guid(); } gSobject.tokenAuth = function(x0,x1) { return Utils.tokenAuth(x0,x1); } gSobject.userAgent = function() { return Utils.userAgent(); } gSobject.login = function(x0,x1,x2,x3) { return Utils.login(x0,x1,x2,x3); } gSobject.updateAuthTokenToSession = function(x0) { return Utils.updateAuthTokenToSession(x0); } gSobject.logout = function() { return Utils.logout(); } gSobject.loadPage = function(x0) { return Utils.loadPage(x0); } gSobject.reloadPage = function() { return Utils.reloadPage(); } gSobject.setCookie = function(x0,x1) { return Utils.setCookie(x0,x1); } gSobject.getCookie = function(x0) { return Utils.getCookie(x0); } gSobject.deviceType = function() { return Utils.deviceType(); } gSobject.isBrowser = function() { return Utils.isBrowser(); } gSobject.isAndroid = function() { return Utils.isAndroid(); } gSobject.isIos = function() { return Utils.isIos(); } gSobject.isCordova = function() { return Utils.isCordova(); } gSobject.cordovaDevice = function() { return Utils.cordovaDevice(); } gSobject.toast = function(x0,x1) { return Utils.toast(x0,x1); } gSobject.post = function(x0,x1,x2,x3,x4) { return Utils.post(x0,x1,x2,x3,x4); } gSobject.validateEmail = function(x0) { return Utils.validateEmail(x0); } gSobject.validateCellphone = function(x0) { return Utils.validateCellphone(x0); } gSobject.getType = function(x0) { return Utils.getType(x0); } gSobject.dateString = function(x0) { return Utils.dateString(x0); } gSobject.appendAppVersion = function(x0) { return Utils.appendAppVersion(x0); } gSobject.logExceptionStack = function(x0) { return Utils.logExceptionStack(x0); } gSobject.getIp = function(x0) { return Utils.getIp(x0); } gSobject.loadScript = function(x0,x1) { return Utils.loadScript(x0,x1); } gSobject.deepCopyMap = function(x0) { return Utils.deepCopyMap(x0); } gSobject.mapToJSON = function(x0) { return Utils.mapToJSON(x0); } gSobject.formatNumber = function(x0,x1,x2,x3) { return Utils.formatNumber(x0,x1,x2,x3); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; Utils.getAuthToken = function(it) { return gs.gp(Utils.session,"authToken"); } Utils.getDeviceToken = function(it) { return gs.gp(Utils.session,"deviceToken"); } Utils.setTimeout = function(callback, timeout) { return setTimeout(callback, timeout); } Utils.setInterval = function(callback, timeout) { return setInterval(callback, timeout); } Utils.clearInterval = function(interval) { return clearInterval(interval); } Utils.documentReady = function(callback) { if ((gs.gp(Utils.document,"readyState") === "complete") || ((gs.gp(Utils.document,"readyState") !== "loading") && (!gs.bool(gs.gp(gs.gp(Utils.document,"documentElement"),"doScroll"))))) { return gs.execCall(callback, this, []); } else { return gs.mc(Utils.document,"addEventListener",["DOMContentLoaded", callback]); }; } Utils.uuid = function(it) { return gs.mc(Utils.guid(),"replaceAll",["-", ""]); } Utils.callChain = function(callChain, success, fail) { if (success === undefined) success = null; if (fail === undefined) fail = null; return gs.execStatic(Socket,'callChain', this,[callChain, success, fail]); } Utils.callObject = function(self, method, args, success, fail) { if (fail === undefined) fail = null; return gs.execStatic(Socket,'callObject', this,[self, method, args, success, fail]); } Utils.send = function(call, data, success, fail) { if (fail === undefined) fail = null; return gs.execStatic(Socket,'send', this,[call, data, success, fail]); } Utils.subscribe = function(objectId, success, topic) { if (topic === undefined) topic = gs.gp(Socket,"SOCKET_OBJECT_URL"); return gs.execStatic(Socket,'subscribe', this,[objectId, success, topic]); } Utils.unsubscribe = function(objectId) { return gs.execStatic(Socket,'unsubscribe', this,[objectId]); } Utils.guid = function() { var d = new Date().getTime(); var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = (d + Math.random()*16)%16 | 0; d = Math.floor(d/16); return (c=='x' ? r : (r&0x3|0x8)).toString(16); }); return uuid; } Utils.tokenAuth = function(success, fail) { if (fail === undefined) fail = function(it) { }; gs.println(gs.plus("Utils:tokenAuth:", gs.gp(StartupParams,"doAuthToken"))); if (gs.bool(gs.gp(Utils.session,"zoner"))) { gs.println("Utils:tokenAuth:zoner cached"); gs.execCall(success, this, []); success = null; }; gs.println("Utils:tokenAuth:loading zoner"); var callback = function(authMap) { gs.println(gs.plus("tokenAuth:callback:authMap:", authMap)); if (gs.bool(gs.gp(authMap,"authenticated"))) { gs.mc(Utils,"updateAuthTokenToSession",[authMap]); if (gs.bool(success)) { gs.execCall(success, this, []); }; return null; }; return gs.execCall(fail, this, []); }; return gs.execStatic(Utils,'send', this,["authenticationToken", gs.map().add("deviceId",Utils.getDeviceToken()), callback]); } Utils.userAgent = function() { return navigator.userAgent.toLowerCase() } Utils.login = function(username, password, success, fail) { if (fail === undefined) fail = function(it) { }; var callback = function(authMap) { if (gs.bool(gs.gp(authMap,"authenticated"))) { gs.mc(Utils,"updateAuthTokenToSession",[authMap]); gs.execCall(success, this, []); return null; }; gs.sp(Utils.session,"zoner",null); gs.println("Login failed"); return gs.execCall(fail, this, []); }; return gs.execStatic(Utils,'send', this,["authentication", gs.map().add("username",username).add("password",password).add("deviceId",Utils.getDeviceToken()).add("userAgent",Utils.userAgent()), callback, fail]); } Utils.updateAuthTokenToSession = function(authMap) { Utils.setCookie(gs.gp(Socket,"AUTH_TOKEN"), gs.gp(gs.gp(authMap,"zoner"),"token")); gs.sp(gs.gp(authMap,"zoner"),"token",""); return gs.sp(Utils.session,"zoner",gs.gp(authMap,"zoner")); } Utils.logout = function(it) { gs.println("Utils.logout"); var authToken = Utils.getAuthToken(); gs.sp(Utils.session,"zoner",null); gs.sp(Utils.session,"redirectAfterLogin",null); gs.sp(Utils.session,"authToken",null); gs.sp(Utils.session,"deviceToken",null); gs.mc(Utils.session,"clear",[]); gs.execStatic(LocalDB,'getInstance', this,[function(it) { return gs.mc(gs.execStatic(LocalDB,'getInstance', this,[]),"dropDatabase",[]); }]); gs.println("Utils.logout:redirect to /login/logout"); return Utils.loadPage("/login/logout"); } Utils.loadPage = function(url) { window.location = url } Utils.reloadPage = function() { window.location.reload(true); } Utils.setCookie = function(name, value) { jQuery.cookie(name, JSON.stringify(value)); } Utils.getCookie = function(name) { try{ return gs.toGroovy(jQuery.parseJSON(jQuery.cookie(name))); }catch(all){ return null } } Utils.deviceType = function() { if (navigator.userAgent.indexOf('Electron') > 0) { return Utils.DeviceTypes.ELECTRON } if (((navigator.userAgent.indexOf("iPhone") > 0) || (navigator.userAgent.indexOf("iPad") > 0)) && ((navigator.userAgent.indexOf("monical") > 0 || navigator.userAgent.indexOf("cordova") > 0))) { return Utils.DeviceTypes.IOS } if ((navigator.userAgent.indexOf("cordova") > 0) && (navigator.userAgent.indexOf("Android") > 0)) { return Utils.DeviceTypes.ANDROID } return Utils.DeviceTypes.BROWSER } Utils.isBrowser = function(it) { return gs.equals(Utils.deviceType(), gs.gp(Utils.DeviceTypes,"BROWSER")); } Utils.isAndroid = function() { return navigator.userAgent.indexOf("Android") > 0 } Utils.isIos = function() { return (navigator.userAgent.indexOf("iPhone") > 0) || (navigator.userAgent.indexOf("iPad") > 0) } Utils.isCordova = function() { return navigator.userAgent.indexOf("cordova") > 0 } Utils.cordovaDevice = function(it) { var dt = Utils.deviceType(); if ((gs.equals(dt, gs.gp(gs.gp(Utils,"DeviceTypes"),"IOS"))) || (gs.equals(dt, gs.gp(gs.gp(Utils,"DeviceTypes"),"ANDROID")))) { return true; }; return false; } Utils.toast = function(message, showDuration) { if (showDuration === undefined) showDuration = 300; toastr.options = { "closeButton": false, "debug": false, "newestOnTop": false, "progressBar": false, "positionClass": "toast-bottom-center", "preventDuplicates": false, "onclick": null, "showDuration": showDuration, "hideDuration": "1000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": "fadeIn", "hideMethod": "fadeOut" } toastr.info(message); } Utils.post = function(file, parameter, objectName, id, callback) { return gs.execStatic(Socket,'post', this,[file, parameter, objectName, id, callback]); } Utils.validateEmail = function(text) { return gs.exactMatch(text,/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[A-Za-z.]{2,}$/); } Utils.validateCellphone = function(text) { return gs.exactMatch(text,/^(0|(\+[0-9]{1,5}))?([0-9]{10})$/); } Utils.getType = function(value) { return typeof value } Utils.dateString = function(date) { return gs.plus((gs.plus((gs.plus((gs.plus(gs.mc(date,"getDate",[]), "/")), (gs.plus(gs.mc(date,"getMonth",[]), 1)))), "/")), gs.mc(date,"getFullYear",[])); } Utils.appendAppVersion = function(url) { if (gs.bool(gs.gp(Utils.session,"branchRevision"))) { var appender = "?"; if (gs.mc(url,"contains",["?"])) { appender = "&"; }; url += (gs.plus((gs.plus(appender, "branchRevision=")), gs.gp(Utils.session,"branchRevision"))); }; return url; } Utils.logExceptionStack = function(msg) { console.log('%c ' + msg + ' ', 'color: #cc0000'); } Utils.getIp = function(callback) { Utils.documentReady(function () { $.getJSON("http://jsonip.com/?callback=?", function (data) { callback(data.ip) }); }); } Utils.loadScript = function(scriptUrl, callback) { if (callback === undefined) callback = function(it) { }; var script = document.createElement("script") script.type = "text/javascript"; if (script.readyState){ //IE script.onreadystatechange = function(){ if (script.readyState == "loaded" || script.readyState == "complete"){ script.onreadystatechange = null; callback(); } }; } else { //Others script.onload = function(){ callback(); }; } script.src = scriptUrl; document.getElementsByTagName("head")[0].appendChild(script); } Utils.deepCopyMap = function(map) { return gs.toGroovy(JSON.parse(JSON.stringify(map))) } Utils.mapToJSON = function(map) { return JSON.stringify(map) } Utils.formatNumber = function(number, decimals, dec, sep) { if (decimals === undefined) decimals = 0; if (dec === undefined) dec = "."; if (sep === undefined) sep = " "; var n = !isFinite(+number) ? 0 : +number, prec = Math.abs(decimals), toFixedFix = function (n, prec) { // Fix for IE parseFloat(0.55).toFixed(0) = 0; var k = Math.pow(10, prec); return Math.round(n * k) / k; }, s = (prec ? toFixedFix(n, prec) : Math.round(n)).toString().split('.'); if (s[0].length > 3) { s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); } if ((s[1] || '').length < prec) { s[1] = s[1] || ''; s[1] += new Array(prec - s[1].length + 1).join('0'); } return s.join(dec); } Utils.session = gs.execStatic(Session,'instance', this,[]); Utils.window = null; Utils.document = null; Utils.DeviceTypes = gs.map().add("ANDROID","android").add("IOS","ios").add("ELECTRON","electron").add("BROWSER","browser"); Utils.AUTH_FAILED = "AUTH_FAILED"; Utils.NO_AUTH = "NO_AUTH"; function ObjectRegistry() { var gSobject = gs.init('ObjectRegistry'); gSobject.clazz = { name: 'ObjectRegistry', simpleName: 'ObjectRegistry'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'objectRegistry', { get: function() { return ObjectRegistry.objectRegistry; }, set: function(gSval) { ObjectRegistry.objectRegistry = gSval; }, enumerable: true }); gSobject.register = function(x0) { return ObjectRegistry.register(x0); } gSobject.registerSingle = function(x0,x1) { return ObjectRegistry.registerSingle(x0,x1); } gSobject.isDatabaseObject = function(x0) { return ObjectRegistry.isDatabaseObject(x0); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; ObjectRegistry.register = function(objects) { if (gs.instanceOf(objects, "ArrayList")) { var oObjectList = gs.list([]); gs.mc(objects,"eachWithIndex",[function(object, index) { return gs.mc(oObjectList,"add",[gs.mc(ObjectRegistry,"registerSingle",[object])]); }]); return oObjectList; } else { return ObjectRegistry.registerSingle(objects); }; } ObjectRegistry.registerSingle = function(object, flatCopy) { if (flatCopy === undefined) flatCopy = true; if (!gs.bool(ObjectRegistry.isDatabaseObject(object))) { return object; }; var oObject = ObjectRegistry.objectRegistry[gs.gp(object,"_id")]; if (!gs.bool(oObject)) { oObject = OObject(object); (ObjectRegistry.objectRegistry[gs.gp(object,"_id")]) = oObject; } else { gs.mc(oObject,"merge",[object, flatCopy]); }; gs.mc(object,"each",[function(key, value) { if (gs.mc(ObjectRegistry,"isDatabaseObject",[value])) { var newValue = gs.mc(ObjectRegistry,"registerSingle",[value, false]); return (gs.gp(oObject,"internalMap")[key]) = gs.mc(newValue,"toJs",[]); } else { if ((value != null) && (gs.instanceOf(value, "ArrayList"))) { var oObjectList = gs.list([]); gs.mc(value,"eachWithIndex",[function(objectVal, index) { if (gs.mc(ObjectRegistry,"isDatabaseObject",[objectVal])) { return gs.mc(oObjectList,"add",[gs.mc(gs.mc(ObjectRegistry,"registerSingle",[objectVal]),"toJs",[])]); } else { return gs.mc(oObjectList,"add",[objectVal]); }; }]); return (gs.gp(oObject,"internalMap")[key]) = oObjectList; }; }; }]); gs.execStatic(Utils,'setTimeout', this,[function(it) { return gs.mc(gs.execStatic(LocalDB,'getInstance', this,[]),"updateIfExists",[oObject]); }, 100]); return oObject; } ObjectRegistry.isDatabaseObject = function(object) { return ((object != null) && (gs.instanceOf(object, "HashMap"))) && (gs.bool(gs.gp(object,"_id"))); } ObjectRegistry.objectRegistry = gs.map(); function OObject() { var gSobject = gs.init('OObject'); gSobject.clazz = { name: 'OObject', simpleName: 'OObject'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.internalMap = gs.map(); gSobject.methodMissingName = null; gSobject.methodMissingArgs = null; gs.astDelegate('OObject', 'internalMap'); gSobject.refresher = null; gSobject.updateCallback = function(it) { }; gSobject['subscribe'] = function(it) { return gs.execStatic(Utils,'subscribe', this,[gs.gp(gSobject.internalMap,"_id"), gSobject.updateCallback]); } gSobject['unsubscribe'] = function(it) { return gs.execStatic(Utils,'unsubscribe', this,[gs.gp(gSobject.internalMap,"_id")]); } gSobject['setRefresher'] = function(closure, update) { if (update === undefined) update = true; gs.mc(gSobject,"subscribe",[]); if ((!gs.bool(gSobject.refresher)) || ((gs.bool(gSobject.refresher)) && (gs.bool(update)))) { return gSobject.refresher = closure; }; } gSobject['merge'] = function(object, flatCopy) { if (flatCopy === undefined) flatCopy = true; if ((gs.bool(object)) && (gs.instanceOf(object, "OObject"))) { object = gs.gp(object,"internalMap"); }; gs.mc(object,"each",[function(key, value) { if (gs.bool(flatCopy)) { (gSobject.internalMap[key]) = value; return null; }; if (!gs.bool(((value != null) && (gs.instanceOf(value, "String"))) && (gs.execStatic(ObjectRegistry,'isDatabaseObject', this,[gSobject.internalMap[key]])))) { return (gSobject.internalMap[key]) = value; } else { gs.println("WARNING: skip overwrite of DatabaseObject with String"); gs.println(gs.plus("Key:", key)); gs.println(gs.plus("String:", value)); gs.println("internalMap[key]:"); gs.println(gSobject.internalMap[key]); gs.println("Object:"); return gs.println(gSobject.internalMap); }; }]); if (gs.bool(gSobject.refresher)) { return gs.mc(gSobject,"refresher",[this]); }; } gSobject['toJs'] = function(it) { return gSobject.internalMap; } gSobject['toString'] = function(it) { return gs.mc(gSobject.internalMap,"toString",[]); } gSobject['setProperty'] = function(name, value) { return (gSobject.internalMap[name]) = value; } gSobject['getProperty'] = function(name) { return gSobject.internalMap[name]; } gSobject['methodMissing'] = function(name, args) { gSobject.methodMissingName = name; gSobject.methodMissingArgs = args; if (gs.bool(args)) { var successClosure = gs.mc(args,"last",[]); if (gs.instanceOf(successClosure, "Closure")) { if (gs.equals(gs.mc(args,"size",[]), 1)) { args = null; } else { args = (gs.rangeFromList(args, 0, -2)); }; gSobject.methodMissingArgs = args; return gs.mc(gSobject,"then",[successClosure]); }; }; } gSobject['then'] = function(successClosure, fail) { if (successClosure === undefined) successClosure = function(it) { }; if (fail === undefined) fail = function(it) { }; return gs.execStatic(Utils,'callObject', this,[gSobject.internalMap, gSobject.methodMissingName, gSobject.methodMissingArgs, successClosure, fail]); } gSobject['do'] = function(success) { if (success === undefined) success = function(it) { }; return gs.mc(gSobject,"then",[success, null]); } gSobject['OObject1'] = function(self) { gs.mc(gSobject,"merge",[self]); return this; } if (arguments.length==1) {gSobject.OObject1(arguments[0]); } return gSobject; }; function ObjectFinder() { var gSobject = gs.init('ObjectFinder'); gSobject.clazz = { name: 'ObjectFinder', simpleName: 'ObjectFinder'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'singleO', { get: function() { return ObjectFinder.singleO; }, set: function(gSval) { ObjectFinder.singleO = gSval; }, enumerable: true }); gSobject.log = RemoteLog("Transmission"); gSobject.getInstance = function() { return ObjectFinder.getInstance(); } gSobject['propertyMissing'] = function(name) { var argList = gs.list([gs.map().add("property",name)]); return NestedO(argList, CacheCallTracker(0, false, false)); } gSobject['local'] = function(ttl, alsoCallRemote, remoteOnce) { if (alsoCallRemote === undefined) alsoCallRemote = false; if (remoteOnce === undefined) remoteOnce = false; var argList = gs.list([]); return NestedO(argList, CacheCallTracker(ttl, alsoCallRemote, remoteOnce)); } gSobject['localAndRemote'] = function(ttl) { if (ttl === undefined) ttl = -1; return gs.mc(gSobject,"local",[ttl, true]); } gSobject['localAndRemoteOnce'] = function(ttl) { if (ttl === undefined) ttl = -1; return gs.mc(gSobject,"local",[ttl, true, true]); } gSobject['post'] = function(file, parameter, objectName, id, callback) { if (objectName === undefined) objectName = null; if (id === undefined) id = null; if (callback === undefined) callback = null; if (!gs.bool(file)) { gs.println("No file selected"); return null; }; gs.println(gs.plus("file: ", file)); gs.println(gs.plus("parameter: ", parameter)); gs.println(gs.plus("objectName: ", objectName)); gs.println(gs.plus("id: ", id)); if (gs.equals(callback, null)) { callback = function(it) { }; }; return gs.execStatic(Utils,'post', this,[file, parameter, objectName, id, callback]); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; ObjectFinder.getInstance = function(it) { if (gs.bool(ObjectFinder.singleO)) { return ObjectFinder.singleO; }; ObjectFinder.singleO = ObjectFinder(); return ObjectFinder.singleO; } ObjectFinder.singleO = null; function RemoteLog() { var gSobject = gs.init('RemoteLog'); gSobject.clazz = { name: 'RemoteLog', simpleName: 'RemoteLog'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.className = null; gSobject['info'] = function(message) { return gs.mc(gSobject,"generic",["info", message]); } gSobject['debug'] = function(message) { return gs.mc(gSobject,"generic",["debug", message]); } gSobject['warn'] = function(message) { return gs.mc(gSobject,"generic",["warn", message]); } gSobject['error'] = function(message) { return gs.mc(gSobject,"generic",["error", message]); } gSobject['off'] = function(message) { return gs.mc(gSobject,"generic",["off", message]); } gSobject['trace'] = function(message) { return gs.mc(gSobject,"generic",["trace", message]); } gSobject['generic'] = function(callName, message) { try { gs.println(gs.plus((gs.plus(gSobject.className, ":")), message)); } catch (all) { } ; return gs.mc(gs.mc(gs.mc(gs.execStatic(ObjectFinder,'getInstance', this,[]),"propertyMissing",["log"]),"" + (callName) + "",[message, gSobject.className]),"do",[]); } gSobject['RemoteLog1'] = function(className) { gs.sp(this,"className",className); return this; } if (arguments.length==1) {gSobject.RemoteLog1(arguments[0]); } return gSobject; }; function NestedO() { var gSobject = gs.init('NestedO'); gSobject.clazz = { name: 'NestedO', simpleName: 'NestedO'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.cacheCallTracker = null; gSobject.successClosure = null; gSobject.argList = gs.list([]); gSobject['methodMissing'] = function(name, args) { if (gs.mc(gSobject.argList,"size",[]) > 16) { throw {message: "Maximum call stack size 16 exceeded"}; }; if (gs.bool(args)) { var successClosure = gs.mc(args,"last",[]); if (gs.instanceOf(successClosure, "Closure")) { if (gs.equals(gs.mc(args,"size",[]), 1)) { args = null; } else { args = (gs.rangeFromList(args, 0, -2)); }; gs.mc(gSobject.argList,"add",[gs.map().add("method",name).add("args",args)]); gs.sp(this,"successClosure",successClosure); gs.mc(gSobject,"then",[successClosure]); return null; }; }; gs.mc(gSobject.argList,"add",[gs.map().add("method",name).add("args",args)]); return NestedO(gSobject.argList, gSobject.cacheCallTracker); } gSobject.isUndefined = function(val) { return val === undefined } gSobject['propertyMissing'] = function(name) { if (gs.mc(gSobject.argList,"size",[]) > 16) { throw {message: "Maximum call stack size 16 exceeded"}; }; gs.mc(gSobject.argList,"add",[gs.map().add("property",name)]); return NestedO(gSobject.argList, gSobject.cacheCallTracker); } gSobject['then'] = function(success, fail) { if (fail === undefined) fail = function(it) { }; return gs.mc(gSobject.cacheCallTracker,"callAndCache",[gSobject.argList, success, fail]); } gSobject['do'] = function(it) { return gs.mc(gSobject,"then",[function(it) { }]); } gSobject['NestedO2'] = function(argList, cacheCallTracker) { gs.sp(this,"cacheCallTracker",cacheCallTracker); gs.sp(this,"argList",argList); return this; } if (arguments.length==2) {gSobject.NestedO2(arguments[0], arguments[1]); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function LocalDB() { var gSobject = gs.init('LocalDB'); gSobject.clazz = { name: 'LocalDB', simpleName: 'LocalDB'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'DB_VERSION_NO', { get: function() { return LocalDB.DB_VERSION_NO; }, set: function(gSval) { LocalDB.DB_VERSION_NO = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'DB_NAME', { get: function() { return LocalDB.DB_NAME; }, set: function(gSval) { LocalDB.DB_NAME = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'db', { get: function() { return LocalDB.db; }, set: function(gSval) { LocalDB.db = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'jsDbInstance', { get: function() { return LocalDB.jsDbInstance; }, set: function(gSval) { LocalDB.jsDbInstance = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'instance', { get: function() { return LocalDB.instance; }, set: function(gSval) { LocalDB.instance = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'checkVersion', { get: function() { return LocalDB.checkVersion; }, set: function(gSval) { LocalDB.checkVersion = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'cleanupStaleData', { get: function() { return LocalDB.cleanupStaleData; }, set: function(gSval) { LocalDB.cleanupStaleData = gSval; }, enumerable: true }); gSobject.getInstance = function(x0) { return LocalDB.getInstance(x0); } gSobject.initDb = function(x0,x1) { return LocalDB.initDb(x0,x1); } gSobject.dropDatabase = function(x0) { return LocalDB.dropDatabase(x0); } gSobject['cacheObjects'] = function(key, objectsIn, ttl) { var objects = objectsIn; var single = false; if (!gs.bool(gs.instanceOf(objects, "ArrayList"))) { objects = gs.list([objects]); single = true; }; var internalMaps = gs.list([]); gs.mc(objects,"each",[function(object) { if (gs.instanceOf(object, "OObject")) { gs.mc(LocalDB.db,"remove",[gs.map().add("_id",gs.gp(object,"_id"))]); return gs.mc(internalMaps,"add",[gs.mc(object,"toJs",[])]); }; }]); gs.println("upsert0"); gs.println(key); var ids = null; if (gs.bool(internalMaps)) { gs.println("upsert1"); gs.println(internalMaps); gs.mc(LocalDB.db,"insert",[internalMaps]); ids = internalMaps.collect(function(it) { return gs.gp(it, "_id",true)}); gs.println(ids); objects = null; }; var ttlInMs = (gs.equals(ttl, -1) ? null : gs.plus(gs.gp(gs.date(),"time"), (gs.multiply(ttl, 1000)))); gs.println("upsert2"); gs.println(objects); if (gs.bool(objects)) { objects = gs.toJavascript(objects); }; gs.mc(LocalDB.db,"remove",[gs.map().add("_id",key)]); gs.mc(LocalDB.db,"insert",[gs.map().add("_id",key).add("ids",ids).add("single",single).add("_ttl",ttlInMs).add("objects",objects)]); return gs.mc(LocalDB.db,"save",[]); } gSobject['readCache'] = function(key) { var keyObject = gs.mc(LocalDB.db,"find",[gs.map().add("_id",key)]); if (gs.gp(keyObject,"length") > 0) { keyObject = (keyObject[0]); if ((gs.bool(gs.gp(keyObject,"_ttl"))) && (gs.gp(keyObject,"_ttl") <= gs.gp(gs.date(),"time"))) { gs.println("db.remove"); gs.println(key); gs.mc(LocalDB.db,"remove",[gs.map().add("_id",key)]); gs.mc(LocalDB.db,"save",[]); return null; }; if (gs.bool(gs.gp(keyObject,"objects"))) { return gs.toGroovy(gs.gp(keyObject,"objects")[0]); }; var objects = gs.toGroovy(gs.mc(LocalDB.db,"find",[gs.toJavascript(gs.map().add("_id",gs.map().add("$in",gs.gp(keyObject,"ids"))))])); var objectList = gs.mc(objects,"collect",[function(it) { return OObject(it); }]); if (gs.bool(gs.gp(keyObject,"single"))) { return objectList[0]; }; return objectList; }; return null; } gSobject['insert'] = function(object) { gs.mc(LocalDB.db,"upsert",[gs.mc(object,"toJs",[])]); return gs.mc(LocalDB.db,"save",[]); } gSobject['updateIfExists'] = function(object) { var keyObject = gs.mc(LocalDB.db,"find",[gs.map().add("_id",gs.gp(object,"_id"))]); if (gs.bool(keyObject)) { return gs.mc(gSobject,"insert",[object]); }; } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; LocalDB.getInstance = function(callback) { if (callback === undefined) callback = function(it) { }; if (!gs.bool(LocalDB.instance)) { LocalDB.instance = LocalDB(); if (!gs.bool(LocalDB.db)) { LocalDB.initDb(LocalDB.DB_NAME, function(it) { return gs.mc(LocalDB,"checkVersion",[function(it) { return gs.mc(LocalDB,"cleanupStaleData",[callback]); }]); }); }; } else { gs.execCall(callback, this, []); }; return LocalDB.instance; } LocalDB.initDb = function(dbName, callback) { var fdb = new ForerunnerDB() var forerunnerdb = fdb.db(dbName); forerunnerdb.persist.addStep(new forerunnerdb.shared.plugins.FdbCompress()); forerunnerdb.persist.addStep(new forerunnerdb.shared.plugins.FdbCrypto({ pass: "dbStoreCode" })); var collection = forerunnerdb.collection("appCollection") collection.deferredCalls(false) collection.load(function (err, tableStats, metaStats) { if (err) { console.error('forerunnerdb error') }else{ console.log('forerunnerdb started') console.log(tableStats) console.log(metaStats) } LocalDB.jsDbInstance = forerunnerdb LocalDB.db = collection if (callback) callback() }); } LocalDB.dropDatabase = function(callback) { if (callback === undefined) callback = function(it) { }; return gs.mc(LocalDB.jsDbInstance,"drop",[true, function(it) { return gs.mc(LocalDB,"initDb",[LocalDB.DB_NAME, function(it) { gs.mc(LocalDB.db,"upsert",[gs.map().add("_id","dbVersionNumber").add("version",LocalDB.DB_VERSION_NO)]); gs.mc(LocalDB.db,"save",[]); return gs.execCall(callback, this, []); }]); }]); } LocalDB.DB_VERSION_NO = "1.1"; LocalDB.DB_NAME = "1"; LocalDB.db = null; LocalDB.jsDbInstance = null; LocalDB.instance = null; LocalDB.checkVersion = function(callback) { if (callback === undefined) callback = function(it) { }; gs.println("LocalDB.checkVersion"); var version = gs.mc(LocalDB.db,"find",[gs.map().add("_id","dbVersionNumber")]); if ((gs.equals(gs.gp(version,"length"), 0)) || (gs.gp(version[0],"version") != LocalDB.DB_VERSION_NO)) { gs.println("FOUND OLD DB:DROP DB"); gs.mc(LocalDB,"dropDatabase",[callback]); return null; }; return gs.execCall(callback, this, []); }; LocalDB.cleanupStaleData = function(callback) { if (callback === undefined) callback = function(it) { }; gs.println("LocalDB.cleanupStaleData"); var nowMs = gs.gp(gs.date(),"time"); gs.mc(LocalDB.db,"remove",[gs.map().add("_ttl",gs.map().add("$lte",nowMs))]); gs.mc(LocalDB.db,"save",[]); return gs.execCall(callback, this, []); }; function CacheCallTracker() { var gSobject = gs.init('CacheCallTracker'); gSobject.clazz = { name: 'CacheCallTracker', simpleName: 'CacheCallTracker'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'remoteOnceMap', { get: function() { return CacheCallTracker.remoteOnceMap; }, set: function(gSval) { CacheCallTracker.remoteOnceMap = gSval; }, enumerable: true }); gSobject.ttl = 0; gSobject.alsoCallRemote = false; gSobject.remoteOnce = false; gSobject['callAndCache'] = function(argList, successClosure, fail) { if (successClosure === undefined) successClosure = function(it) { }; if (fail === undefined) fail = null; var argListString = gs.mc(argList,"toString",[]); if (gs.bool(gSobject.ttl)) { var objects = gs.mc(gs.execStatic(LocalDB,'getInstance', this,[]),"readCache",[argListString]); gs.println("OBJECT FOUND"); gs.println(objects); if (gs.bool(objects)) { gs.execStatic(ObjectRegistry,'register', this,[objects]); gs.execCall(successClosure, this, [objects]); if (!gs.bool(gSobject.alsoCallRemote)) { return null; }; (CacheCallTracker.remoteOnceMap[argListString]) = (CacheCallTracker.remoteOnceMap[argListString] ? gs.plus((CacheCallTracker.remoteOnceMap[argListString]), 1) : 1); if ((gs.bool(gSobject.remoteOnce)) && ((CacheCallTracker.remoteOnceMap[argListString]) > 1)) { gs.println("SKIPPING"); return null; }; gs.println("RUNNING"); }; }; gs.println("RUNNING2"); return gs.execStatic(Socket,'callChain', this,[argList, function(objects) { gs.println("RUNNING3"); gs.println(argListString); gs.mc(gSobject,"syncCache",[argList, objects, argListString]); return gs.execCall(successClosure, this, [objects]); }, fail]); } gSobject['syncCache'] = function(argList, objects, argListString) { if (gs.bool(gSobject.ttl)) { gs.println("syncCache"); gs.println(objects); return gs.mc(gs.execStatic(LocalDB,'getInstance', this,[]),"cacheObjects",[argListString, objects, gSobject.ttl]); }; } gSobject['CacheCallTracker3'] = function(ttl, alsoCallRemote, remoteOnce) { gs.sp(this,"ttl",ttl); gs.sp(this,"alsoCallRemote",alsoCallRemote); gs.sp(this,"remoteOnce",remoteOnce); return this; } if (arguments.length==3) {gSobject.CacheCallTracker3(arguments[0], arguments[1], arguments[2]); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; CacheCallTracker.remoteOnceMap = gs.map(); function BookingToolController() { var gSobject = gs.init('BookingToolController'); gSobject.clazz = { name: 'BookingToolController', simpleName: 'BookingToolController'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.clazz.interfaces = [{ name: 'AngularController', simpleName: 'AngularController'}, { name: 'AngularModule', simpleName: 'AngularModule'}]; AngularController.$init$(gSobject); gSobject.angularInit = function(x1,x2) { return AngularController.angularInit(gSobject,x1,x2); } gSobject.makeGlobalScope = function(x1) { return AngularController.makeGlobalScope(gSobject,x1); } gSobject.applicationConfig = function() { return AngularController.applicationConfig(gSobject); } gSobject.defaultAuthState = function() { return AngularController.defaultAuthState(gSobject); } gSobject.logAllStates = function(x1) { return AngularController.logAllStates(gSobject,x1); } gSobject.domElement = function(x1) { return AngularController.domElement(gSobject,x1); } gSobject.init = function() { return AngularController.init(gSobject); } gSobject.setup = function() { return AngularController.setup(gSobject); } gSobject.destroy = function() { return AngularController.destroy(gSobject); } gSobject.stateChangeStart = function(x1,x2,x3,x4,x5) { return AngularController.stateChangeStart(gSobject,x1,x2,x3,x4,x5); } gSobject.continueToNextState = function() { return AngularController.continueToNextState(gSobject); } gSobject.checkRoles = function() { return AngularController.checkRoles(gSobject); } gSobject.setupControllerOnce = function(x1,x2,x3) { return AngularController.setupControllerOnce(gSobject,x1,x2,x3); } gSobject.injectAngularServices = function(x1,x2,x3) { return AngularController.injectAngularServices(gSobject,x1,x2,x3); } gSobject.getAngular = function() { return AngularController.getAngular(gSobject); } gSobject.refresh = function() { return AngularController.refresh(gSobject); } gSobject.openUrl = function(x1) { return AngularController.openUrl(gSobject,x1); } gSobject.controllerProperties = function(x1) { return AngularController.controllerProperties(gSobject,x1); } gSobject.controllerMethods = function(x1) { return AngularController.controllerMethods(gSobject,x1); } gSobject.testControllerForInvalidMethods = function(x1) { return AngularController.testControllerForInvalidMethods(gSobject,x1); } gSobject.getDefaultDependencies = function() { return AngularController.getDefaultDependencies(gSobject); } gSobject.setDefaultDependencies = function(x1) { return AngularController.setDefaultDependencies(gSobject,x1); } gSobject.getDefaultInjections = function() { return AngularController.getDefaultInjections(gSobject); } gSobject.setDefaultInjections = function(x1) { return AngularController.setDefaultInjections(gSobject,x1); } gSobject.getScope = function() { return AngularController.getScope(gSobject); } gSobject.setScope = function(x1) { return AngularController.setScope(gSobject,x1); } gSobject.getRootScope = function() { return AngularController.getRootScope(gSobject); } gSobject.setRootScope = function(x1) { return AngularController.setRootScope(gSobject,x1); } gSobject.getSession = function() { return AngularController.getSession(gSobject); } gSobject.setSession = function(x1) { return AngularController.setSession(gSobject,x1); } gSobject.getState = function() { return AngularController.getState(gSobject); } gSobject.setState = function(x1) { return AngularController.setState(gSobject,x1); } gSobject.states = gs.map().add("name","bookingTool").add("url","/bookingTool/:id").add("templateUrl","/statics/bookingToolController/bookingToolView"); gSobject.incomingUrl = gs.plus((gs.plus(gs.gp(gs.gp(window,"location"),"protocol"), "//")), gs.gp(gs.gp(window,"location"),"hostname")); gSobject.skipAutoScroll = true; Object.defineProperty(gSobject, 'MAP_ZOOM', { get: function() { return BookingToolController.MAP_ZOOM; }, set: function(gSval) { BookingToolController.MAP_ZOOM = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'MAP_MIN_ZOOM', { get: function() { return BookingToolController.MAP_MIN_ZOOM; }, set: function(gSval) { BookingToolController.MAP_MIN_ZOOM = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'map', { get: function() { return BookingToolController.map; }, set: function(gSval) { BookingToolController.map = gSval; }, enumerable: true }); gSobject.HOTEL_PIN_URL = gs.plus(gSobject.incomingUrl, "/statics/images/hotelPin.svg"); gSobject.VENUA_PIN_URL = gs.plus(gSobject.incomingUrl, "/statics/images/venuePin.svg"); gSobject.DEFAULT_LAT = -30.5522174; gSobject.DEFAULT_LON = 24.2347793; gSobject.VAT = 18; gSobject.legionUser = null; gSobject.quote = null; gSobject.event = null; gSobject.catagoryOptionsMap = gs.map(); gSobject.hotelViewState = gs.map().add("searchElem",false).add("mapElem",false).add("hotelListElem",false).add("hotelElem",false); gSobject.viewStates = gs.map().add("hotelSelect",gs.map().add("hotelSelectElem",true).add("bankingElem",false).add("paymentElem",false)).add("t&c",gs.map().add("hotelSelectElem",false).add("bankingElem",true).add("paymentElem",false)).add("payment",gs.map().add("hotelSelectElem",false).add("bankingElem",false).add("paymentElem",true)); gSobject.creditCardFeeEntry = gs.map().add("totalVat",true).add("description","Credit card fee").add("dateSelectionType","Qty"); gSobject.markers = gs.list([]); gSobject.hotelDetailsMap = null; gSobject.hotelDetailsmarkers = gs.list([]); gSobject.directionsRenderer = null; gSobject.cityCircles = gs.list([]); gSobject.selectedItems = gs.list([]); gSobject.selectedHotels = gs.map(); gSobject.selectedExtras = gs.list([]); gSobject.allSelectedOptionMap = gs.map().add("All",gs.list([gs.map().add("description","All").add("dateSelectionType","Range").add("data",gs.map().add("hotels",gSobject.selectedHotels).add("extras",gSobject.selectedExtras))])); gSobject.paymentProcessStarted = false; gSobject['init'] = function(it) { gs.println("BookingTool:init"); gs.mc(gSobject,"showReturnToEventBtn",[false]); gs.sp(gSobject.getScope(),"venueList",gs.list([])); gs.sp(gSobject.getScope(),"venueDistacneList",gs.list([5 , 15 , 25])); gs.sp(gSobject.getScope(),"venueDistance",15); gs.sp(gSobject.getScope(),"selectedVenue",gs.map()); gs.sp(gSobject.getScope(),"previewHotelData",gs.map().add("hotel",gs.map())); gs.sp(gSobject.getScope(),"previewHotel",gs.map()); gs.sp(gSobject.getScope(),"previewHotelUrl",""); gs.sp(gSobject.getScope(),"showOptionDetailPreviewPopup",false); gs.sp(gSobject.getScope(),"cityList",gs.mc(gs.fs('gs', this, gSobject),"toJavascript",[gs.list([gs.map().add("name","All").add("_id","all")])])); gs.sp(gSobject.getScope(),"selectedCity","all"); gs.sp(gSobject.getScope(),"selectedOptionMap",gs.map()); gs.sp(gSobject.getScope(),"acceptedTerms",false); gs.sp(gSobject.getScope(),"paymentType","payLater"); gs.sp(gSobject.getScope(),"totalItems",0); gs.sp(gSobject.getScope(),"totalPrice",0); gs.sp(gSobject.getScope(),"totalVat",0); gs.sp(gSobject.getScope(),"guests",gs.list([])); gs.mc(gSobject,"loadLegionUser",[]); gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingService"),"getVAT",[function(VATValue) { return gSobject.VAT = VATValue; }]); return gs.mc(gSobject,"loadEvent",[gs.gp(gs.fs('$stateParams', this, gSobject),"id")]); } gSobject['loadEvent'] = function(eventId) { gs.println("BookingTool:loadEvent"); return gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingToolService"),"loadBookingOptionsData",[eventId, function(data) { gs.println("updateEventData1"); gs.mc(gSobject,"updateEventData",[data]); if (((gs.bool(gs.gp(gs.gp(data,"event"),"bookingToolEnabled"))) && (!gs.bool(gs.gp(gs.gp(data,"event"),"venueListSearchEnabled")))) && (!gs.bool(gs.gp(gs.gp(data,"event"),"stockSearchEnabled")))) { return gs.execStatic(Utils,'setTimeout', this,[function(it) { return gs.mc(gSobject,"searchStock",[]); }, 10]); }; }]); } gSobject['searchStock'] = function(it) { return gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingToolService"),"searchStock",[gs.gp(gs.gp(gSobject.getScope(),"event"),"_id"), gs.gp(gSobject.getScope(),"stockSearchText"), gs.gp(gSobject.getScope(),"selectedCity"), gs.gp(gs.gp(gSobject.getScope(),"selectedVenue"),"_id"), gs.gp(gSobject.getScope(),"venueDistance"), function(data) { gs.println("updateEventData2"); return gs.mc(gSobject,"updateEventData",[data]); }]); } gSobject['searchVenue'] = function(it) { if (!gs.bool(gs.gp(gSobject.getScope(),"venueSearchText"))) { gs.sp(gSobject.getScope(),"venueList",gs.list([])); gs.sp(gSobject.getScope(),"selectedVenue",gs.map()); gs.mc(this,"refresh",[], gSobject); return null; }; return gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingToolService"),"searchVenues",[gs.gp(gs.gp(gSobject.getScope(),"event"),"_id"), gs.gp(gSobject.getScope(),"venueSearchText"), function(venueList) { gs.sp(gSobject.getScope(),"venueList",venueList.collect(function(it) { return gs.mc(it, 'toJs', []);})); return gs.mc(this,"refresh",[], gSobject); }]); } gSobject['updateEventData'] = function(data) { gs.println("BookingToolController:loadEvent"); gs.println(data); gs.sp(gSobject.getSession(),"bookingToolContactInfo",gs.elvis(gs.bool(gs.gp(gSobject.getSession(),"bookingToolContactInfo")) , gs.gp(gSobject.getSession(),"bookingToolContactInfo") , gs.map().add("name","").add("surname","").add("email","").add("phoneNumber","").add("companyName","").add("companyAddress",""))); gs.sp(gSobject.getScope(),"contactInfo",gs.gp(gSobject.getSession(),"bookingToolContactInfo")); gs.sp(gs.gp(gSobject.getScope(),"contactInfo"),"request",""); gSobject.event = gs.gp(data,"event"); gs.sp(gSobject.getScope(),"event",gs.gp(data,"event")); gSobject.quote = gs.gp(data,"quote"); gs.sp(gSobject.getScope(),"quote",gs.gp(data,"quote")); gs.mc(gSobject,"findSelected",[]); gSobject.catagoryOptionsMap = gs.gp(data,"catagoryOptions"); gs.sp(gSobject.getScope(),"catagoryOptionsMap",gSobject.catagoryOptionsMap); if (gs.bool(gs.gp(data,"cityList"))) { var all = gs.map().add("name","All").add("_id","all"); gs.mc(gs.gp(data,"cityList"),"add",[0, all]); gs.sp(gSobject.getScope(),"cityList",gs.mc(gs.fs('gs', this, gSobject),"toJavascript",[gs.gp(data,"cityList")])); } else { gs.sp(gSobject.getScope(),"cityList",gs.mc(gs.fs('gs', this, gSobject),"toJavascript",[gs.list([gs.map().add("name","All").add("_id","all")])])); gs.sp(gSobject.getScope(),"selectedCity","all"); }; gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingToolService"),"loadBankingDetails",[gs.gp(gs.gp(data,"quote"),"_id"), gSobject.incomingUrl, function(html) { gs.sp(gSobject.getScope(),"bankingDetailsHtml",gs.gp(html,"bankingDetailsHtml")); return gs.mc(this,"refresh",[], gSobject); }]); gs.mc(gSobject,"setHotelViewState",[]); return gs.mc(gSobject,"updateMap",[]); } gSobject['setHotelViewState'] = function(it) { gs.sp(gSobject.hotelViewState,"hotelListElem",true); gs.sp(gSobject.hotelViewState,"hotelElem",false); gs.sp(gSobject.hotelViewState,"searchElem",((gs.bool(gs.gp(gSobject.event,"stockSearchEnabled"))) || (gs.bool(gs.gp(gSobject.event,"venueListSearchEnabled"))))); gs.sp(gSobject.hotelViewState,"mapElem",gs.gp(gSobject.event,"mapSearchEnabled")); if (gs.bool(gs.gp(gSobject.event,"hidePayNowBtn"))) { gs.sp(gSobject.getScope(),"paymentType","payLater"); }; gs.mc(gSobject,"showState",["hotelSelect"]); return gs.mc(this,"refresh",[], gSobject); } gSobject['updateMap'] = function(it) { if (gs.bool(gs.gp(gSobject.hotelViewState,"mapElem"))) { gs.mc(gSobject,"clearAllMarkers",[gSobject.markers]); gs.mc(this,"refresh",[], gSobject); var coordinates = gs.map().add("lat",gSobject.DEFAULT_LAT).add("lng",gSobject.DEFAULT_LON); if (gs.bool(gs.gp(gSobject.getScope(),"selectedVenue"))) { coordinates = gs.map().add("lat",gs.gp(gs.gp(gSobject.getScope(),"selectedVenue"),"lat")).add("lng",gs.gp(gs.gp(gSobject.getScope(),"selectedVenue"),"lon")); }; if (!gs.bool(gs.gp(gs.fs('bookingToolController', this, gSobject),"map"))) { gs.sp(gs.fs('bookingToolController', this, gSobject),"map",gs.mc(gSobject,"initGoogleMap",[coordinates, "googleMapSearch"])); } else { if (gs.bool(gs.gp(gSobject.getScope(),"selectedVenue"))) { gs.mc(gSobject,"posisionGoogleMap",[BookingToolController.map, gs.gp(gs.gp(gSobject.getScope(),"selectedVenue"),"lat"), gs.gp(gs.gp(gSobject.getScope(),"selectedVenue"),"lon")]); } else { gs.mc(gSobject,"posisionGoogleMap",[BookingToolController.map, gSobject.DEFAULT_LAT, gSobject.DEFAULT_LON]); }; }; if (gs.bool(gs.gp(gSobject.getScope(),"selectedVenue"))) { gs.mc(gSobject,"drawCircles",[coordinates]); gs.mc(gSobject.markers,"add",[gs.mc(gSobject,"addMarker",[BookingToolController.map, coordinates, gs.gp(gs.gp(gSobject.getScope(),"selectedVenue"),"name"), gSobject.VENUA_PIN_URL])]); }; gs.mc(gSobject.markers,"addAll",[gs.mc(gSobject,"addHotelMarkers",[])]); return gs.execStatic(Utils,'setTimeout', this,[function(it) { return gs.mc(gSobject,"fitMap",[BookingToolController.map, gSobject.markers]); }, 200]); }; } gSobject['addHotelMarkers'] = function(it) { var markers = gs.list([]); if (gs.bool(gs.gp(gs.fs('bookingToolController', this, gSobject),"map"))) { gs.mc(gSobject.catagoryOptionsMap,"each",[function(optionName, catagoryOptions) { return gs.mc(catagoryOptions,"each",[function(optionMap) { return gs.mc(gs.gp(gs.gp(optionMap,"data"),"hotels"),"each",[function(hotelId, hoteldData) { try { var hotel = gs.gp(hoteldData,"hotel"); var coordinates = gs.map().add("lat",gs.gp(hotel,"lat")).add("lng",gs.gp(hotel,"lon")); var marker = gs.mc(gSobject,"addMarker",[BookingToolController.map, coordinates, null, gSobject.HOTEL_PIN_URL]); gs.mc(markers,"add",[marker]); gs.mc(marker,"addListener",["click", function(it) { return gs.mc(gSobject,"showOptionDetail",[hoteldData]); }]); gs.mc(marker,"addListener",["mouseover", function(ev) { if (!gs.bool(gs.gp(gSobject.getScope(),"showOptionDetailPreviewPopup"))) { gs.mc(gSobject,"showOptionDetailPreview",[hotel, ev]); return gs.mc(this,"refresh",[], gSobject); }; }]); gs.mc(marker,"addListener",["mouseout", function(it) { gs.sp(gSobject.getScope(),"showOptionDetailPreviewPopup",false); return gs.mc(this,"refresh",[], gSobject); }]); } catch (e) { gs.println("ERROR WITH HOTEL MARKER"); gs.println(hoteldData); gs.println(gs.fs('e', this, gSobject)); } ; }]); }]); }]); }; return markers; } gSobject['showOptionDetailPreview'] = function(hotel, ev) { gs.sp(gSobject.getScope(),"previewHotel",hotel); gs.sp(gSobject.getScope(),"previewHotelUrl",(gs.plus((gs.plus("/home/cHotelImage/", (gs.gp(hotel,"images")[0]))), "/file"))); gs.sp(gSobject.getScope(),"showOptionDetailPreviewPopup",true); return gs.mc(gSobject,"positionOptionDetailModal",[ev]); } gSobject.positionOptionDetailModal = function(ev) { $('#showOptionDetailPreviewPopup').css('left',ev.tb.pageX+5); // <<< use pageX and pageY $('#showOptionDetailPreviewPopup').css('top',ev.tb.pageY); $('#showOptionDetailPreviewPopup').css('display','inline'); $("#showOptionDetailPreviewPopup").css("position", "absolute"); // <<< also make it absolute! } gSobject['showOptionDetail'] = function(hotelData) { gs.println("showOptionDetail"); gs.println(gSobject.showOptionDetail); gs.mc(gSobject,"clearAllMarkers",[gSobject.hotelDetailsmarkers]); if (gs.bool(gSobject.directionsRenderer)) { gs.mc(gSobject.directionsRenderer,"setMap",[null]); }; gs.sp(gSobject.getScope(),"previewHotelData",hotelData); gs.sp(gSobject.getScope(),"previewHotelDistance","N/A"); gs.sp(gSobject.getScope(),"previewHotelDuration","N/A"); gs.sp(gSobject.hotelViewState,"hotelListElem",false); gs.sp(gSobject.hotelViewState,"hotelElem",true); var hotelCoordinates = gs.map().add("lat",gs.gp(gs.gp(hotelData,"hotel"),"lat")).add("lng",gs.gp(gs.gp(hotelData,"hotel"),"lon")); var venueCoordinates = hotelCoordinates; if (gs.bool(gs.gp(gSobject.getScope(),"selectedVenue"))) { venueCoordinates = gs.map().add("lat",gs.gp(gs.gp(gSobject.getScope(),"selectedVenue"),"lat")).add("lng",gs.gp(gs.gp(gSobject.getScope(),"selectedVenue"),"lon")); }; gs.println("venueCoordinates"); gs.println(venueCoordinates); gs.println(hotelCoordinates); if (!gs.bool(gSobject.hotelDetailsMap)) { gSobject.hotelDetailsMap = gs.mc(gSobject,"initGoogleMap",[venueCoordinates, "hotelDetailsGoogleMaps", true]); }; if (gs.bool(gs.gp(gSobject.getScope(),"selectedVenue"))) { var start = gs.mc(gSobject,"addMarker",[gSobject.hotelDetailsMap, venueCoordinates, gs.gp(gs.gp(gSobject.getScope(),"selectedVenue"),"name"), gSobject.VENUA_PIN_URL]); gs.mc(gSobject.hotelDetailsmarkers,"add",[start]); }; var end = gs.mc(gSobject,"addMarker",[gSobject.hotelDetailsMap, hotelCoordinates, gs.gp(gs.gp(hotelData,"hotel"),"name"), gSobject.HOTEL_PIN_URL]); gs.mc(gSobject.hotelDetailsmarkers,"add",[end]); gs.mc(gSobject,"showState",["hotelSelect"]); if (gs.bool(gs.gp(gSobject.getScope(),"selectedVenue"))) { gSobject.directionsRenderer = gs.mc(gSobject,"paintDirections",[gSobject.hotelDetailsMap, start, end]); }; gs.execStatic(Utils,'setTimeout', this,[function(it) { return gs.mc(gSobject,"fitMap",[gSobject.hotelDetailsMap, gSobject.hotelDetailsmarkers]); }, 200]); return gs.execStatic(Utils,'setTimeout', this,[function(it) { return gs.mc(gSobject,"activateSlider",[]); }, 100]); } gSobject.paintDirections = function(map, start, end) { var directionsService = new google.maps.DirectionsService() var directionsRenderer = new google.maps.DirectionsRenderer() directionsRenderer.setOptions( { suppressMarkers: true } ); directionsRenderer.setMap(map); directionsService.route({ origin : start.getPosition(), destination : end.getPosition(), travelMode : google.maps.TravelMode.DRIVING }, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsRenderer.setDirections(response); console.log(response) bookingToolController.getScope().previewHotelDistance = response.routes[0].legs[0].distance.text bookingToolController.getScope().previewHotelDuration = response.routes[0].legs[0].duration.text bookingToolController.refresh() } // else { // window.alert('Directions request failed due to ' + status); // } }); return directionsRenderer; } gSobject.activateSlider = function() { new Swiper('.swiper-container', { slidesPerView: 1, paginationClickable: true, pagination: '.swiper-pagination', grabCursor: true, loop: true, nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', }); } gSobject['selectVenue'] = function(venueItem) { gs.sp(gSobject.getScope(),"selectedVenue",venueItem); gs.sp(gSobject.getScope(),"venueSearchText",gs.gp(venueItem,"name")); gs.sp(gSobject.getScope(),"venueList",gs.list([])); return gs.mc(gSobject,"searchStock",[]); } gSobject['switchMap'] = function(it) { gs.sp(gSobject.hotelViewState,"mapElem",!gs.gp(gSobject.hotelViewState,"mapElem")); gs.mc(gSobject,"showState",["hotelSelect"]); return gs.mc(gSobject,"updateMap",[]); } gSobject['backToHoteList'] = function(it) { gs.sp(gSobject.hotelViewState,"hotelElem",false); gs.sp(gSobject.hotelViewState,"hotelListElem",true); return gs.mc(gSobject,"showState",["hotelSelect"]); } gSobject['showHotelDetails'] = function(it) { return (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"viewState"),"hotelElem",true))) && (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"previewHotelData"),"hotel",true))); } gSobject['showHotelDetailsImages'] = function(it) { return gs.mc(gs.gp(gs.gp(gs.gp(gSobject.getScope(),"previewHotelData"),"hotel",true),"images",true),"size",[], null, true) > 0; } gSobject['showHotelDetailsMap'] = function(it) { return (gs.bool(gs.gp(gs.gp(gs.gp(gSobject.getScope(),"previewHotelData"),"hotel",true),"latitude",true))) && (gs.bool(gs.gp(gs.gp(gs.gp(gSobject.getScope(),"previewHotelData"),"hotel",true),"longitude",true))); } gSobject['showHotelDetailsMapUrl'] = function(it) { if (!gs.bool(gs.mc(gSobject,"showHotelDetailsMap",[]))) { return null; }; return gs.mc(gs.fs('$sce', this, gSobject),"trustAsResourceUrl",[gs.plus((gs.plus((gs.plus("https://www.google.com/maps/embed/v1/place?key=AIzaSyBTHGkVJDxyL64ZEzffcu1ecO7exysvEFA&q=", gs.gp(gs.gp(gs.gp(gSobject.getScope(),"previewHotelData"),"hotel"),"latitude"))), ",")), gs.gp(gs.gp(gs.gp(gSobject.getScope(),"previewHotelData"),"hotel"),"longitude"))]); } gSobject['clearAllMarkers'] = function(markers) { gs.mc(markers,"each",[function(it) { return gs.mc(it,"setMap",[null]); }]); return gs.mc(markers,"clear",[]); } gSobject['fitMap'] = function(map, markers) { gs.println("fitMap:markers"); gs.println(markers); var bounds = new google.maps.LatLngBounds(); gs.mc(markers,"each",[function(it) { try { gs.mc(bounds,"extend",[gs.mc(it,"getPosition",[])]); } catch (e) { } ; }]); gs.mc(map,"fitBounds",[bounds]); var zoom = gs.mc(map,"getZoom",[]); return gs.mc(map,"setZoom",[(zoom > BookingToolController.MAP_MIN_ZOOM ? BookingToolController.MAP_MIN_ZOOM : zoom)]); } gSobject['drawCircles'] = function(coordinates) { gs.mc(gSobject.cityCircles,"each",[function(it) { return gs.mc(it,"setMap",[null]); }]); gSobject.cityCircles = gs.list([]); return gs.mc(gs.gp(gSobject.getScope(),"venueDistacneList"),"each",[function(it) { var cicleMap = gs.map().add("strokeColor","#71bf45").add("strokeOpacity",0.8).add("strokeWeight",0.5).add("fillColor","rgba(0, 128, 0, 0.2)").add("map",BookingToolController.map).add("center",coordinates).add("radius",gs.multiply(it, 1000)); return gs.mc(gSobject.cityCircles,"add",[new google.maps.Circle(cicleMap)]); }]); } gSobject.initGoogleMap = function(latlng, elementId, disableDefaultUI) { if (disableDefaultUI === undefined) disableDefaultUI = false; console.log('elementId:'+elementId) var mapStyles = [ { "featureType": "administrative", "stylers": [ { "visibility": "off" } ] },{ "featureType": "transit", "stylers": [ { "visibility": "off" } ] },{ "featureType": "poi.attraction", "stylers": [ { "visibility": "off" } ] },{ "featureType": "poi.business", "stylers": [ { "visibility": "off" } ] },{ "featureType": "poi.government", "stylers": [ { "visibility": "off" } ] },{ "featureType": "poi.medical", "stylers": [ { "visibility": "off" } ] },{ "featureType": "poi.park", "elementType": "labels", "stylers": [ { "visibility": "off" } ] },{ "featureType": "poi.place_of_worship", "stylers": [ { "visibility": "off" } ] } ]; return new google.maps.Map(document.getElementById(elementId), { disableDefaultUI : disableDefaultUI, zoom: bookingToolController.MAP_ZOOM, center: latlng, styles: mapStyles }); } gSobject.posisionGoogleMap = function(map, lat, lon) { map.panTo(new google.maps.LatLng(lat,lon)); map.setZoom(bookingToolController.MAP_ZOOM); } gSobject.addMarker = function(map, position, title, imageUrl) { if (!map) return; var marker = new google.maps.Marker({ map : map, title : title, position : position, animation : google.maps.Animation.DROP, icon : {url:imageUrl} }); return marker; } gSobject['startDateDialog'] = function(state) { gs.sp(gSobject.getScope(),"startDateDialogStatus",state); return gs.mc(this,"refresh",[], gSobject); } gSobject['endDateDialog'] = function(state) { gs.sp(gSobject.getScope(),"endDateDialogStatus",state); return gs.mc(this,"refresh",[], gSobject); } gSobject['showState'] = function(state) { gs.sp(gSobject.getScope(),"viewState",(gs.mc(gs.map(),'leftShift', gs.list([(gSobject.viewStates[state])])))); gs.mc(gs.gp(gSobject.getScope(),"viewState"),"putAll",[gSobject.hotelViewState]); gs.sp(gSobject.getScope(),"selectedOptionMap",gSobject.allSelectedOptionMap); if (gs.equals(state, "hotelSelect")) { BookingToolController.jqueryShow(".campaignTopInfo"); }; if (gs.equals(state, "t&c")) { gs.sp(gSobject.getScope(),"selectedOptionMap",gSobject.allSelectedOptionMap); gs.mc(gSobject,"showReturnToEventBtn",[false]); BookingToolController.jqueryHide(".campaignTopInfo"); }; if (gs.equals(state, "payment")) { gs.mc(gSobject,"showReturnToEventBtn",[false]); BookingToolController.jqueryHide(".campaignTopInfo"); }; gs.mc(gSobject,"focusHtmlElem",["topOffForm"]); return gs.mc(this,"refresh",[], gSobject); } gSobject['focusHtmlElem'] = function(htmlElmName) { if (gs.bool(gSobject.skipAutoScroll)) { gSobject.skipAutoScroll = false; return null; }; return gs.execStatic(Utils,'setTimeout', this,[function(it) { return document.getElementById(htmlElmName).scrollIntoView();; }, 100]); } gSobject['checkSelection'] = function(callback) { var canContinue = false; gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentOptionMap"),"rooms",true),"each",[function(room) { if (gs.gp(room,"amount") > 0) { return canContinue = true; }; }], null, true); if (gs.bool(canContinue)) { gs.println("=====canContinue====="); return callback; }; return gs.sp(gSobject.getScope(),"continueError","Please make at least one selection."); } gSobject.showReturnToEventBtn = function(show) { if (show){ document.getElementById("returnToEventBtn").style.display = "inline-block"; } else { document.getElementById("returnToEventBtn").style.display = "none"; } } gSobject['addGuest'] = function(it) { var newGuest = gs.map().add("name","New User"); gs.mc(gs.gp(gSobject.getScope(),"guests"),"add",[newGuest]); return gs.mc(this,"refresh",[], gSobject); } gSobject.range = function(count) { console.log(count) var ranges = [] console.log('range here') for (var i = 0; i < count; i++) { ranges.push(i) } console.log(ranges) return ranges } gSobject.jqueryShow = function(x0) { return BookingToolController.jqueryShow(x0); } gSobject.jqueryHide = function(x0) { return BookingToolController.jqueryHide(x0); } gSobject['initOptionMap'] = function(optionMap) { return gs.mc(gSobject,"checkRsvp",[optionMap, gs.gp(optionMap,"rsvpEntry")]); } gSobject['addRoom'] = function(room) { gs.println("addRoom"); gs.println(gs.gp(room,"saRoom")); gs.println(room); gs.sp(room,"itemType","room"); gs.sp(room,"amount",0); gs.sp(room,"quantity",0); gs.sp(room,"dateSelectionType",gs.elvis(gs.bool(gs.gp(room,"dateSelectionType")) , gs.gp(room,"dateSelectionType") , "Range+Qty")); gs.sp(room,"nightsLabel",gs.elvis(gs.bool(gs.gp(room,"nightsLabel")) , gs.gp(room,"nightsLabel") , gs.gp(room,"nightsLabel"))); if (gs.bool(gs.gp(room,"saRoom"))) { gs.sp(room,"roomDetails",gs.map().add("adultsPerRoomRange",gs.list([])).add("childrenPerRoomRange",gs.list([])).add("childrenPerRoom",0)); gs.mc(gs.gp(gs.fs('o', this, gSobject),"saRoom"),"getOne",[gs.gp(room,"saRoom"), function(roomDetail) { gs.sp(room,"roomDetails",gs.mc(roomDetail,"toJs",[])); gs.sp(gs.gp(room,"roomDetails"),"adultsPerRoomRange",gs.toJavascript(gs.range(1, gs.gp(roomDetail,"adultsPerRoom"), true))); gs.sp(gs.gp(room,"roomDetails"),"childrenPerRoomRange",gs.toJavascript(gs.range(1, gs.gp(roomDetail,"childrenPerRoom"), true))); if (gs.bool(gs.gp(roomDetail,"labelOverride"))) { gs.sp(room,"nightsLabel",gs.gp(roomDetail,"labelOverride")); }; gs.mc(this,"refresh",[], gSobject); if (!gs.bool(gs.gp(room,"saRoomStock"))) { return gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingToolService"),"findRoomstockForRoom",[gs.gp(gs.fs('$stateParams', this, gSobject),"id"), gs.gp(room,"saRoom"), function(data) { gs.println("findRoomstockForRoom"); gs.println(data); gs.sp(room,"saRoomStock",gs.gp(gs.gp(data,"saRoomStock"),"_id")); return gs.mc(gSobject,"loadRoomPrice",[room]); }]); }; }]); }; gs.mc(gSobject,"checkDates",[room, false]); gs.mc(gSobject,"loadRoomPrice",[room]); return gs.mc(gSobject,"checkRsvp",[room, gs.gp(room,"rsvpEntry")]); } gSobject['clearRoomInfo'] = function(room) { gs.sp(room,"nights",0); gs.sp(room,"amount",0); gs.sp(room,"quantity",0); gs.sp(room,"totalVat",null); gs.sp(room,"totalPrice",null); gs.mc(gSobject,"hideBookingDetailsPopup",[]); gs.mc(gSobject,"removeSelectedRoom",[room]); return gs.mc(gSobject,"updateTotal",[]); } gSobject['updateRoomQuantity'] = function(it) { var direction = ""; if (gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity") > gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity")) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity",gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity")); direction = "more"; }; if (gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity") < gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity")) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity",gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity")); direction = "less"; }; if (gs.equals(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"itemType"), "room")) { if (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"saRoom"))) { return gs.mc(gs.gp(gs.fs('o', this, gSobject),"saRoom"),"getOne",[gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"saRoom"), function(roomDetail) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"rooomName",gs.gp(roomDetail,"labelOverride")); return gs.mc(this,"refresh",[], gSobject); }]); }; } else { gs.println("here2"); gs.println("direction"); gs.println(direction); if (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"collectNames"))) { if (!gs.bool(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"guests"))) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"guests",gs.list([])); for (i = 0 ; i < gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity") ; i++) { gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"guests"),"add",[gs.map().add("name","")]); }; }; if (gs.equals(direction, "more")) { gs.println("more"); gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"guests"),"add",[gs.map().add("name","")]); }; if (gs.equals(direction, "less")) { gs.println("less"); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"guests",gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"guests"),"findAll",[function(it) { return it != (gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"guests")[(gs.minus(gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"guests"),"size",[]), 1))]); }])); }; gs.mc(this,"refresh",[], gSobject); gs.println("guests"); return gs.println(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"guests")); }; }; } gSobject['calcRoomPrice'] = function(room) { if (!gs.bool(gs.gp(room,"available"))) { gs.sp(room,"amount",0); }; if (!gs.bool(gs.gp(room,"amount"))) { gs.sp(room,"amount",1); }; gs.mc(gSobject,"checkDates",[room]); gs.sp(room,"nights",gs.mc(gSobject,"daysInDateRange",[gs.gp(room,"startDate"), gs.gp(room,"endDate")])); gs.sp(room,"totalPrice",(gs.multiply((gs.multiply(gs.gp(room,"payablePrice"), gs.gp(room,"amount"))), gs.gp(room,"nights")))); gs.sp(room,"totalVat",0); if (gs.bool(gs.gp(room,"useVat"))) { return gs.sp(room,"totalVat",(gs.div(gs.gp(room,"totalPrice"), (gs.plus(100, gSobject.VAT))))); }; } gSobject['checkRsvp'] = function(item, rsvpEntry) { gs.println("checkRsvp"); if (gs.bool(gs.gp(item,"rsvpEntry"))) { return gs.mc(gSobject,"loadLegionUser",[function(user) { gs.println("checkRsvp1"); gs.println(user); return gs.mc(gs.gp(gs.fs('o', this, gSobject),"rsvpInviteEntry"),"findOne",[gs.map().add("user",gs.gp(user,"_id")).add("rsvpEntry",rsvpEntry), function(rsvpInviteEntry) { gs.println("rsvpInviteEntry"); gs.println(rsvpInviteEntry); gs.sp(item,"names",gs.elvis(gs.bool(gs.gp(rsvpInviteEntry,"names")) , gs.gp(rsvpInviteEntry,"names") , gs.list([]))); return gs.sp(item,"rsvpDeclined",(gs.equals(gs.gp(rsvpInviteEntry,"state"), false))); }]); }]); }; } gSobject['addExtra'] = function(extra) { gs.sp(extra,"itemType","extra"); gs.sp(extra,"quantity",0); return gs.mc(gSobject,"checkRsvp",[extra, gs.gp(extra,"rsvpEntry")]); } gSobject['updateExtraTotals'] = function(extra, optionMap) { if (optionMap === undefined) optionMap = null; gs.println("updateExtraTotals"); var dateSelectionType = gs.gp(extra,"dateSelectionType"); if (gs.mc(dateSelectionType,"contains",["Single"])) { if (!gs.bool(gs.gp(extra,"quantity"))) { gs.sp(extra,"quantity",1); }; gs.sp(extra,"nights",1); gs.sp(extra,"endDate",null); } else { if (gs.mc(dateSelectionType,"contains",["Range"])) { gs.mc(gSobject,"checkDates",[extra]); gs.sp(extra,"nights",gs.mc(gSobject,"daysInDateRange",[gs.gp(extra,"startDate"), gs.gp(extra,"endDate")])); if (!gs.bool(gs.gp(extra,"quantity"))) { gs.sp(extra,"quantity",1); }; } else { if (gs.mc(dateSelectionType,"contains",["Qty"])) { gs.sp(extra,"nights",1); gs.sp(extra,"startDate",null); gs.sp(extra,"endDate",null); }; }; }; gs.sp(extra,"totalPrice",(gs.multiply((gs.multiply(gs.gp(extra,"payablePrice"), gs.gp(extra,"quantity"))), gs.gp(extra,"nights")))); gs.sp(extra,"totalVat",0); if (gs.bool(gs.gp(extra,"useVat"))) { gs.sp(extra,"totalVat",(gs.div(gs.gp(extra,"totalPrice"), (gs.plus(100, gSobject.VAT))))); }; return gs.mc(gSobject,"findSelected",[]); } gSobject['daysInDateRange'] = function(startDate, endDate) { var differenceInTime = gs.minus(gs.mc(gs.date(endDate),"clearTime",[]), gs.mc(gs.date(startDate),"clearTime",[])); return gs.div(differenceInTime, (gs.multiply((gs.multiply(1000, 3600)), 24))); } gSobject['removeSelectedRoom'] = function(room) { gs.println("removeSelectedRoom"); gs.println("scope.viewState"); gs.println(gs.gp(gSobject.getScope(),"viewState")); if (gs.equals(gs.gp(gSobject.getScope(),"viewState"), "payment")) { return null; }; gs.mc(gSobject.selectedHotels,"each",[function(key, hotelData) { gs.println(key); gs.println(hotelData); gs.mc(gs.gp(gs.gp(hotelData,"rooms"),"date-range"),"remove",[room]); return gs.mc(gs.gp(hotelData,"extras"),"remove",[room]); }]); return gs.mc(gSobject.selectedExtras,"remove",[room]); } gSobject['updateTotal'] = function(it) { gs.mc(gSobject,"internalUpdateTotal",[]); gs.mc(gSobject,"updatePaymnetTypeValues",[]); return gs.mc(gSobject,"internalUpdateTotal",[]); } gSobject['internalUpdateTotal'] = function(it) { gs.println("internalUpdateTotal"); gs.println(gSobject.selectedHotels); gs.println(gSobject.selectedExtras); var selectedItems = gs.list([]); gs.mc(gSobject.selectedHotels,"each",[function(key, hotelData) { gs.mc(gs.gp(gs.gp(hotelData,"rooms"),"date-range"),"each",[function(it) { return gs.mc(selectedItems,"add",[it]); }]); return gs.mc(gs.gp(hotelData,"extras"),"each",[function(it) { return gs.mc(selectedItems,"add",[it]); }]); }]); gs.mc(gSobject.selectedExtras,"each",[function(it) { return gs.mc(selectedItems,"add",[it]); }]); gs.println("selectedItems"); gs.println(selectedItems); gs.sp(gSobject.getScope(),"totalVat",0); gs.mc(selectedItems,"each",[function(it) { if (gs.bool(gs.gp(it,"totalVat"))) { return gs.sp(gSobject.getScope(),"totalVat",gs.gp(gSobject.getScope(),"totalVat") + gs.gp(it,"totalVat")); }; }]); gs.println("it.totalPrice:START"); gs.sp(gSobject.getScope(),"totalItems",gs.mc(selectedItems,"size",[])); gs.sp(gSobject.getScope(),"totalPrice",0); gs.mc(selectedItems,"each",[function(it) { gs.println(gs.plus("selectedItems.it.totalPrice:", gs.gp(it,"totalPrice"))); if (gs.bool(gs.gp(it,"totalPrice"))) { return gs.sp(gSobject.getScope(),"totalPrice",gs.gp(gSobject.getScope(),"totalPrice") + gs.gp(it,"totalPrice")); }; }]); gs.println(gs.gp(gSobject.getScope(),"totalPrice")); gs.println("it.totalPrice:END"); return gs.execStatic(Utils,'setTimeout', this,[function(it) { return gs.mc(this,"refresh",[], gSobject); }, 100]); } gSobject['showBookingDetailsPopup'] = function(room) { gs.println("showBookingDetailsPopupsss"); gs.println(room); var itemType = gs.gp(room,"itemType"); if (gs.bool(gs.gp(room,"saRoom"))) { return gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingToolService"),"loadRoomStockFromRoomId",[gs.gp(room,"saRoomStock"), function(roomStock) { return gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingToolService"),"stockAvailableForRoomStockDates",[gs.gp(roomStock,"_id"), gs.gp(gs.gp(gSobject.getScope(),"event"),"start"), gs.gp(gs.gp(gSobject.getScope(),"event"),"end"), function(roomAvailabilityList) { gs.println("roomAvailabilityList"); gs.println(roomAvailabilityList); gs.sp(gSobject.getScope(),"roomAvailabilityList",roomAvailabilityList); roomStock = gs.mc(roomStock,"toJs",[]); gs.sp(gSobject.getScope(),"roomStock",roomStock); gs.sp(gSobject.getScope(),"currentRoom",room); if (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"selectedRooms"))) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity",gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"selectedRooms"),"size",[])); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity",gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"selectedRooms"),"size",[])); } else { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity",gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"amount")); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity",gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"amount")); }; if (gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity") < 1) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity",1); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity",1); }; gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"itemType",itemType); gs.println(gs.plus("scope.event.defaultDates:", gs.gp(gs.gp(gSobject.getScope(),"event"),"defaultDates"))); if (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"event"),"defaultDates"))) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"startDate",(gs.gp(gs.gp(gSobject.getScope(),"event"),"start") < gs.gp(roomStock,"start") ? gs.gp(roomStock,"start") : gs.gp(gs.gp(gSobject.getScope(),"event"),"start"))); gs.println(gs.plus("scope.currentRoom.startDate:", gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"startDate"))); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"endDate",(gs.gp(gs.gp(gSobject.getScope(),"event"),"end") > gs.gp(roomStock,"end") ? gs.gp(roomStock,"end") : gs.gp(gs.gp(gSobject.getScope(),"event"),"end"))); gs.println(gs.plus("scope.currentRoom.endDate:", gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"endDate"))); }; gs.mc(gSobject,"checkDates",[gs.gp(gSobject.getScope(),"currentRoom")]); gs.sp(gSobject.getScope(),"datePickerOptions",gs.map().add("customClass",gSobject.getDateClass).add("dateDisabled",gSobject.getDisabledDate).add("minDate",gs.gp(gs.gp(gSobject.getScope(),"event"),"start")).add("maxDate",gs.gp(gs.gp(gSobject.getScope(),"event"),"end")).add("showWeeks",false)); gs.execStatic(Modals,'showModal', this,["#bookingToolModal"]); gs.println("Does this update??????????"); gs.println("scope.currentRoom"); gs.println(gs.gp(gSobject.getScope(),"currentRoom")); gs.mc(gSobject,"updateRoomQuantity",[]); return gs.mc(this,"refresh",[], gSobject); }]); }]); } else { gs.sp(gSobject.getScope(),"currentRoom",room); if (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"selectedRooms"))) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity",gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"selectedRooms"),"size",[])); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity",gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"selectedRooms"),"size",[])); } else { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity",gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"amount")); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity",gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"amount")); }; gs.println("scope.currentRoom.quantity"); gs.println(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity")); if ((!gs.bool(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity"))) || (gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity") < 1)) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity",1); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"oldQuantity",1); }; gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"dateSelectionType",gs.gp(room,"dateSelectionType")); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"itemType",itemType); gs.println(gs.plus("scope.event.defaultDates:", gs.gp(gs.gp(gSobject.getScope(),"event"),"defaultDates"))); if (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"event"),"defaultDates"))) { gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"startDate",gs.gp(gs.gp(gSobject.getScope(),"event"),"start")); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"endDate",gs.gp(gs.gp(gSobject.getScope(),"event"),"end")); }; gs.mc(gSobject,"checkDates",[gs.gp(gSobject.getScope(),"currentRoom")]); gs.sp(gSobject.getScope(),"datePickerOptions",gs.map().add("minDate",gs.gp(gs.gp(gSobject.getScope(),"event"),"start")).add("maxDate",gs.gp(gs.gp(gSobject.getScope(),"event"),"end")).add("showWeeks",false)); gs.execStatic(Modals,'showModal', this,["#bookingToolModal"]); gs.println("scope.currentRoom"); gs.println(gs.gp(gSobject.getScope(),"currentRoom")); if (gs.bool(gs.gp(room,"collectNames"))) { gs.mc(gSobject,"updateRoomQuantity",[]); }; return gs.mc(this,"refresh",[], gSobject); }; } gSobject['showAvailabilityModal'] = function(it) { return gs.execStatic(Modals,'showModal', this,["#availabilityQueryModal"]); } gSobject['closeAvailabilityModal'] = function(it) { return gs.execStatic(Modals,'hideModal', this,["#availabilityQueryModal"]); } gSobject['getDateClass'] = function(data) { if (gs.mc(gSobject,"getDisabledDate",[data])) { return "cross"; }; return false; } gSobject['getDisabledDate'] = function(data) { for (_i81 = 0, day = gs.gp(gSobject.getScope(),"roomAvailabilityList")[0]; _i81 < gs.gp(gSobject.getScope(),"roomAvailabilityList").length; day = gs.gp(gSobject.getScope(),"roomAvailabilityList")[++_i81]) { if ((gs.equals(gs.mc(gs.mc(gs.date(gs.gp(day,"date")),"clearTime",[]),"toString",[], null, true), gs.mc(gs.mc(gs.date(gs.gp(data,"date")),"clearTime",[]),"toString",[], null, true))) && (gs.gp(day,"count") < 1)) { gs.println(gs.multiply(" disabled\n", 20)); return true; }; }; return false; } gSobject['updateGuestListCount'] = function(it) { gs.println("updateGuestListCount"); if ((gs.bool(gs.gp(gs.gp(gSobject.getScope(),"currentOptionMap"),"quantity"))) && (gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"nights") < gs.gp(gs.gp(gSobject.getScope(),"currentOptionMap"),"quantity"))) { gs.println("11111"); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"nights",gs.gp(gs.gp(gSobject.getScope(),"currentOptionMap"),"quantity")); }; if ((gs.bool(gs.gp(gs.gp(gSobject.getScope(),"currentOptionMap"),"quantityMax"))) && (gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"nights") > gs.gp(gs.gp(gSobject.getScope(),"currentOptionMap"),"quantityMax"))) { gs.println("22222"); gs.sp(gs.gp(gSobject.getScope(),"currentRoom"),"nights",gs.gp(gs.gp(gSobject.getScope(),"currentOptionMap"),"quantityMax")); }; var room = gs.gp(gSobject.getScope(),"currentRoom"); if (!gs.bool(gs.gp(room,"guestNames"))) { gs.sp(room,"guestNames",gs.list([])); }; if (!gs.bool(gs.gp(room,"paxAmount"))) { gs.sp(room,"paxAmount",1); }; gs.println("room:"); gs.println(room); gs.println(gs.plus("room.amount:", gs.gp(room,"amount"))); gs.println(gs.plus("room.paxAmount:", gs.gp(room,"paxAmount"))); gs.println(gs.plus("room.amount * room.paxAmount:", (gs.multiply(gs.gp(room,"amount"), gs.gp(room,"paxAmount"))))); gs.println(gs.plus("room.guestNames.size():", gs.mc(gs.gp(room,"guestNames"),"size",[]))); while (gs.mc(gs.gp(room,"guestNames"),"size",[]) < (gs.multiply(gs.gp(room,"amount"), gs.gp(room,"paxAmount")))) { gs.mc(gs.gp(room,"guestNames"),"add",[""]); }; gs.println(room); return gs.mc(this,"refresh",[], gSobject); } gSobject['checkDates'] = function(data, refreshScreen) { if (refreshScreen === undefined) refreshScreen = true; if ((gs.mc(gs.gp(data,"dateSelectionType"),"contains",["Single"])) || (gs.mc(gs.gp(data,"dateSelectionType"),"contains",["Range"]))) { if (!gs.bool(gs.gp(data,"startDate"))) { gs.sp(data,"startDate",gs.date()); gs.mc(gs.gp(data,"startDate"),"setHours",[gs.plus(gs.mc(gs.gp(data,"startDate"),"getHours",[]), 24)]); }; if (gs.gp(data,"startDate") < gs.gp(gs.gp(gSobject.getScope(),"event"),"start")) { gs.sp(data,"startDate",gs.date(gs.gp(gs.gp(gs.gp(gSobject.getScope(),"event"),"start"),"time"))); }; }; if (gs.mc(gs.gp(data,"dateSelectionType"),"contains",["Range"])) { if (!gs.bool(gs.gp(data,"endDate"))) { gs.sp(data,"endDate",gs.date()); }; if (gs.gp(data,"endDate") < gs.gp(data,"startDate")) { gs.sp(data,"endDate",gs.date(gs.gp(gs.gp(data,"startDate"),"time"))); gs.mc(gs.gp(data,"endDate"),"setHours",[gs.plus(gs.mc(gs.gp(data,"endDate"),"getHours",[]), 24)]); }; if (gs.gp(data,"endDate") > gs.gp(gs.gp(gSobject.getScope(),"event"),"end")) { gs.sp(data,"endDate",gs.date(gs.gp(gs.gp(gs.gp(gSobject.getScope(),"event"),"end"),"time"))); }; }; if (gs.bool(refreshScreen)) { return gs.mc(this,"refresh",[], gSobject); }; } gSobject['hideBookingDetailsPopup'] = function(it) { return gs.execStatic(Modals,'hideModal', this,["#bookingToolModal"]); } gSobject['findSelected'] = function(it) { if (!gs.bool(gSobject.catagoryOptionsMap)) { return gs.map(); }; if (gs.equals(gs.gp(gSobject.getScope(),"viewState"), "payment")) { gs.mc(gSobject,"updateTotal",[]); return null; }; gs.mc(gSobject.catagoryOptionsMap,"each",[function(optionName, catagoryOptions) { gs.println(optionName); gs.mc(catagoryOptions,"each",[function(optionMap) { gs.println(optionMap); var hotelSelected = false; var selectedHotel = gs.map(); gs.mc(gs.gp(gs.gp(optionMap,"data"),"hotels"),"each",[function(hotelId, hoteldData) { gs.println(hotelId); gs.println(gs.gp(gs.gp(hoteldData,"hotel"),"name")); gs.println(hoteldData); var rooms = gs.list([]); var extras = gs.list([]); gs.mc(selectedHotel,"putAll",[gs.map().add("" + (hotelId) + "",gs.map().add("hotel",gs.gp(hoteldData,"hotel")).add("rooms",gs.map().add("date-range",rooms)).add("extras",extras))]); gs.println("selectedHotel"); gs.println(selectedHotel); gs.mc(gs.gp(hoteldData,"rooms"),"each",[function(dateRange, dateRangeRooms) { gs.println(dateRangeRooms); return gs.mc(dateRangeRooms,"each",[function(room) { gs.println(room); if (gs.gp(room,"quantity") > 0) { gs.println("SELECTED---------------------------"); hotelSelected = true; gs.mc(rooms,"add",[room]); gs.mc(gSobject.selectedItems,"add",[room]); }; return gs.mc(gs.gp(room,"extras"),"each",[function(extra) { gs.println(extra); if (gs.gp(extra,"quantity") > 0) { gs.println("SELECTED---------------------------"); hotelSelected = true; gs.mc(extras,"add",[extra]); return gs.mc(gSobject.selectedItems,"add",[extra]); }; }], null, true); }]); }], null, true); gs.mc(gs.gp(hoteldData,"extras"),"each",[function(extra) { gs.println(extra); if (gs.gp(extra,"quantity") > 0) { gs.println("SELECTED---------------------------"); hotelSelected = true; gs.mc(extras,"add",[extra]); return gs.mc(gSobject.selectedItems,"add",[extra]); }; }], null, true); return gs.mc(gs.gp(gs.gp(hoteldData,"hotel"),"extras"),"each",[function(extra) { gs.println(extra); if (gs.gp(extra,"quantity") > 0) { gs.println("SELECTED---------------------------"); hotelSelected = true; gs.mc(extras,"add",[extra]); return gs.mc(gSobject.selectedItems,"add",[extra]); }; }], null, true); }]); if (gs.bool(hotelSelected)) { gs.mc(gSobject.selectedHotels,"putAll",[selectedHotel]); gs.println("selectedHotels---------------------------"); return gs.println(gSobject.selectedHotels); }; }]); return gs.mc(gs.gp(catagoryOptions,"data"),"extras",[function(extra) { gs.println(extra); if (gs.gp(extra,"quantity") > 0) { gs.mc(gSobject.selectedExtras,"add",[extra]); gs.mc(gSobject.selectedItems,"add",[extra]); return gs.println("SELECTED---------------------------"); }; }], null, true); }]); return gs.mc(gSobject,"updateTotal",[]); } gSobject['updateBookingDetails'] = function(it) { gs.println("updateBookingDetails"); if (gs.equals(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"quantity"), 0)) { gs.mc(gSobject,"clearRoomInfo",[gs.gp(gSobject.getScope(),"currentRoom")]); return null; }; if (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"saRoom"))) { gs.println("scope.currentRoom"); gs.println(gs.gp(gSobject.getScope(),"currentRoom")); return gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingToolService"),"loadRoomStockFromRoomId",[gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"saRoomStock"), function(roomStock) { gs.println("updateBookingDetails"); var error = ""; gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"selectedRooms",true),"each",[function(room) { gs.println(gs.gp(gs.gp(room,"guests")[0],"name",true)); if ((!gs.bool(gs.gp(gs.gp(room,"guests")[0],"name",true))) || (gs.equals(gs.gp(gs.gp(room,"guests")[0],"name",true), ""))) { return error = "At least one guest name needs to be added per room."; }; }], null, true); var dateDifference = gs.div((gs.div((gs.div((gs.div((gs.minus(gs.mc(gs.date(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"endDate")),"clearTime",[]), gs.mc(gs.date(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"startDate")),"clearTime",[]))), 1000)), 60)), 60)), 24); if (gs.bool(gs.gp(roomStock,"minNights"))) { if (dateDifference < gs.gp(roomStock,"minNights")) { error = (gs.plus((gs.plus("At least ", gs.gp(roomStock,"minNights"))), " nights must be selected.")); }; }; if (gs.bool(gs.gp(roomStock,"maxNights"))) { if (dateDifference > gs.gp(roomStock,"maxNights")) { if (gs.equals(gs.gp(roomStock,"maxNights"), 1)) { error = (gs.plus((gs.plus("Can't select more than ", gs.gp(roomStock,"maxNights"))), " night.")); } else { error = (gs.plus((gs.plus("Can't select more than ", gs.gp(roomStock,"maxNights"))), " nights.")); }; }; }; if (gs.bool(error)) { gs.sp(gSobject.getScope(),"errorMessage",error); gs.mc(this,"refresh",[], gSobject); return null; } else { gs.sp(gSobject.getScope(),"errorMessage",""); var room = gs.gp(gSobject.getScope(),"currentRoom"); var currentOptionMap = gs.gp(gSobject.getScope(),"currentOptionMap"); var itemType = gs.gp(room,"itemType"); gs.mc(gSobject,"checkDates",[room]); if (gs.equals(itemType, "extra")) { gs.mc(gSobject,"updateExtraTotals",[room, currentOptionMap]); gs.mc(gSobject,"hideBookingDetailsPopup",[]); }; if (gs.equals(itemType, "room")) { gs.sp(room,"amount",gs.gp(room,"quantity")); return gs.mc(gs.gp(gs.fs('o', this, gSobject),"customPropertyService"),"checkStockForDates",[gs.gp(room,"saRoomStock"), gs.gp(room,"startDate"), gs.gp(room,"endDate"), gs.gp(room,"amount"), function(available) { gs.println(gs.plus("available:", available)); if (gs.bool(available)) { gs.println("scope.currentRoom"); gs.println(gs.gp(gSobject.getScope(),"currentRoom")); gs.mc(gSobject,"loadRoomPrice",[gs.gp(gSobject.getScope(),"currentRoom"), function(it) { gs.mc(gSobject,"calcRoomPrice",[gs.gp(gSobject.getScope(),"currentRoom")]); return gs.mc(gSobject,"findSelected",[]); }]); return gs.mc(gSobject,"hideBookingDetailsPopup",[]); } else { gs.sp(gSobject.getScope(),"errorMessage","Available room quantity exceeded."); return gs.mc(this,"refresh",[], gSobject); }; }]); }; }; }]); } else { gs.println("updateBookingDetails"); var error = ""; gs.mc(gs.gp(gs.gp(gSobject.getScope(),"currentRoom"),"guests",true),"each",[function(guest) { if ((!gs.bool(gs.gp(guest,"name"))) || (gs.equals(gs.gp(guest,"name"), ""))) { return error = "Guest names are required."; }; }], null, true); if (gs.bool(error)) { gs.sp(gSobject.getScope(),"errorMessage",error); return gs.mc(this,"refresh",[], gSobject); } else { gs.sp(gSobject.getScope(),"errorMessage",""); var room = gs.gp(gSobject.getScope(),"currentRoom"); var currentOptionMap = gs.gp(gSobject.getScope(),"currentOptionMap"); var itemType = gs.gp(room,"itemType"); gs.mc(gSobject,"checkDates",[room]); if (gs.equals(itemType, "extra")) { gs.mc(gSobject,"updateExtraTotals",[room, currentOptionMap]); gs.mc(gSobject,"hideBookingDetailsPopup",[]); }; if (gs.equals(itemType, "room")) { gs.sp(room,"amount",gs.gp(room,"quantity")); return gs.mc(gs.gp(gs.fs('o', this, gSobject),"customPropertyService"),"checkStockForDates",[gs.gp(room,"saRoomStock"), gs.gp(room,"startDate"), gs.gp(room,"endDate"), gs.gp(room,"amount"), function(available) { gs.println(gs.plus("available:", available)); if (gs.bool(available)) { gs.println("scope.currentRoom"); gs.println(gs.gp(gSobject.getScope(),"currentRoom")); return gs.mc(gSobject,"loadRoomPrice",[gs.gp(gSobject.getScope(),"currentRoom"), function(it) { gs.mc(gSobject,"calcRoomPrice",[gs.gp(gSobject.getScope(),"currentRoom")]); gs.mc(gSobject,"findSelected",[]); return gs.mc(gSobject,"hideBookingDetailsPopup",[]); }]); } else { gs.sp(gSobject.getScope(),"errorMessage","Available room quantity exceeded."); return gs.mc(this,"refresh",[], gSobject); }; }]); }; }; }; } gSobject['loadRoomPrice'] = function(room, callback) { if (callback === undefined) callback = function(it) { }; gs.println("loadRoomPrice"); if (gs.bool(gs.gp(room,"saRoomStock"))) { return gs.mc(gs.gp(gs.fs('o', this, gSobject),"customPropertyService"),"getAvgSellingPrice",[gs.gp(room,"saRoomStock"), gs.gp(room,"startDate"), gs.gp(room,"endDate"), function(avgSellingPriceData) { gs.println("avgSellingPriceData"); gs.println(avgSellingPriceData); gs.sp(room,"available",(gs.gp(avgSellingPriceData,"size") > 0)); gs.sp(room,"payablePrice",gs.gp(avgSellingPriceData,"payablePrice")); gs.sp(room,"price",gs.gp(avgSellingPriceData,"price")); gs.execCall(callback, this, []); return gs.mc(this,"refresh",[], gSobject); }]); }; } gSobject['payLater'] = function(it) { return gs.mc(gSobject,"createBooking",[function(data) { return gs.sp(gs.fs('window', this, gSobject),"location",(gs.plus((gs.plus(gSobject.incomingUrl, "/bookingTool/success/")), gs.gp(data,"success")))); }]); } gSobject['loadLegionUser'] = function(callback, failCallback, resetCache) { if (callback === undefined) callback = function(it) { }; if (failCallback === undefined) failCallback = function(it) { }; if (resetCache === undefined) resetCache = false; gs.println("LoadLegionUser Start"); if (gs.bool(gSobject.legionUser)) { return gs.execCall(callback, this, [gSobject.legionUser]); }; gs.println("LoadLegionUser Loaded"); gs.execStatic(Utils,'tokenAuth', this,[function(it) { gs.println("Utils.tokenAuth"); gs.println(gSobject.legionUser); if (gs.bool(gs.gp(gs.gp(gSobject.getSession(),"zoner",true),"id",true))) { var callbackWrapper = function(data) { gSobject.legionUser = gs.gp(data,"legionUser"); return gs.execCall(callback, this, [gSobject.legionUser]); }; gs.mc(gs.gp(gs.fs('o', this, gSobject),"legionService"),"legionUserFromZoner",[gs.gp(gs.gp(gSobject.getSession(),"zoner",true),"id",true), callbackWrapper]); return null; }; }]); gs.println("failCallback"); return gs.execCall(failCallback, this, []); } gSobject['selectPaymentType'] = function(it) { gs.mc(gSobject,"updatePaymnetTypeValues",[]); return gs.mc(gSobject,"updateTotal",[]); } gSobject['updatePaymnetTypeValues'] = function(it) { gs.println("updatePaymnetTypeValues"); gs.println(gs.gp(gSobject.getScope(),"paymentType")); if (gs.equals(gs.gp(gSobject.getScope(),"paymentType"), "creditCard")) { return gs.mc(gSobject,"payWithCreditCard",[]); } else { return gs.mc(gSobject.selectedExtras,"remove",[gSobject.creditCardFeeEntry]); }; } gSobject['payWithCreditCard'] = function(it) { gs.println("payWithCreditCard"); var price = gs.div(Math.round(gs.multiply(gs.gp(gSobject.getScope(),"totalPrice"), 5)), 100); gs.sp(gSobject.creditCardFeeEntry,"quantity",1); gs.sp(gSobject.creditCardFeeEntry,"nights",1); gs.sp(gSobject.creditCardFeeEntry,"payablePrice",price); gs.sp(gSobject.creditCardFeeEntry,"price",price); gs.sp(gSobject.creditCardFeeEntry,"totalPrice",price); if (!gs.bool(gs.gSin(gSobject.creditCardFeeEntry, gSobject.selectedExtras))) { return gs.mc(gSobject.selectedExtras,"add",[gSobject.creditCardFeeEntry]); }; } gSobject['canCreateBooking'] = function(it) { if ((gs.bool(gs.gp(gSobject.getScope(),"event"))) && (gs.bool(gs.gp(gs.gp(gSobject.getScope(),"event"),"collectUserAndCompanyInfo")))) { if (!gs.bool(gs.gp(gSobject.getScope(),"contactInfo"))) { return false; }; var allEntered = true; gs.mc(gs.gp(gSobject.getScope(),"contactInfo"),"each",[function(key, value) { if ((key != "request") && (!gs.bool(value))) { return allEntered = false; }; }]); if (!gs.bool(allEntered)) { return false; }; }; return gs.gp(gSobject.getScope(),"totalPrice") != 0; } gSobject['createBooking'] = function(callback) { gs.println("createBooking: Start"); gs.println(gs.plus("createBooking: contat info: ", gs.gp(gSobject.getScope(),"contactInfo"))); gs.sp(gSobject.getSession(),"bookingToolContactInfo",gs.gp(gSobject.getScope(),"contactInfo")); return gs.mc(gs.gp(gs.fs('o', this, gSobject),"bookingToolService"),"createBooking",[gs.gp(gs.gp(gSobject.getScope(),"quote"),"_id"), gs.map().add("wrapper",gSobject.allSelectedOptionMap).add("timestamp",gs.gp(gs.date(),"time")).add("contactInfo",gs.gp(gSobject.getScope(),"contactInfo")), function(data) { gs.println("createBooking:o.bookingToolService.createBooking"); gs.println(data); return gs.execCall(callback, this, [data]); }]); } gSobject['continuePayment'] = function(it) { gs.println("continuePayment"); gs.println(gs.plus("scope.paymentType:", gs.gp(gSobject.getScope(),"paymentType"))); gs.execStatic(Modals,'showModal', this,["#loader"]); if (!gs.bool(gSobject.paymentProcessStarted)) { gSobject.paymentProcessStarted = true; if ((gs.equals(gs.gp(gSobject.getScope(),"paymentType"), "creditCard")) || (gs.equals(gs.gp(gSobject.getScope(),"paymentType"), "instantEft"))) { gs.println("Instant payment"); return gs.mc(gSobject,"startPayment",[]); } else { if (gs.equals(gs.gp(gSobject.getScope(),"paymentType"), "payLater")) { gs.println("payLater payment"); return gs.mc(gSobject,"payLater",[]); } else { return gs.println("Unknown payment"); }; }; }; } gSobject['startPayment'] = function(it) { return gs.mc(gSobject,"createBooking",[function(data) { var bookingId = gs.gp(data,"success"); return gs.sp(gs.fs('window', this, gSobject),"location",(gs.plus((gs.plus((gs.plus(gSobject.incomingUrl, "/bookings/payment/")), bookingId)), "?autoSubmit=true"))); }]); } gSobject['closeGroupBookingRequestPopup'] = function(it) { return gs.execStatic(Modals,'hideModal', this,["#groupBookingModal"]); } gSobject['showGroupBookingRequestPopup'] = function(it) { return gs.execStatic(Modals,'showModal', this,["#groupBookingModal"]); } gSobject['loadPartnerPage'] = function(it) { return gs.mc(gs.gp(gs.fs('o', this, gSobject),"saCampaign"),"findOne",[gs.map().add("partnerCode",gs.gp(gSobject.getScope(),"partnerCode")), function(event) { if (gs.bool(event)) { return gs.sp(gs.fs('window', this, gSobject),"location",(gs.plus((gs.plus(gSobject.incomingUrl, "/event/")), gs.gp(event,"_id")))); } else { return gs.execStatic(Utils,'toast', this,["Partner Code not found"]); }; }]); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; BookingToolController.jqueryShow = function(name) { jQuery(name).show() } BookingToolController.jqueryHide = function(name) { jQuery(name).hide() } BookingToolController.MAP_ZOOM = 13; BookingToolController.MAP_MIN_ZOOM = 16; BookingToolController.map = null; BookingToolController.setupControllerOnce = function() { return AngularController.setupControllerOnce.apply(BookingToolController, [BookingToolController].concat(Array.prototype.slice.call(arguments)));} BookingToolController.injectAngularServices = function() { return AngularController.injectAngularServices.apply(BookingToolController, [BookingToolController].concat(Array.prototype.slice.call(arguments)));} BookingToolController.testControllerForInvalidMethods = function() { return AngularController.testControllerForInvalidMethods.apply(BookingToolController, [BookingToolController].concat(Array.prototype.slice.call(arguments)));} BookingToolController.checkRoles = function() { return AngularController.checkRoles.apply(BookingToolController, [BookingToolController].concat(Array.prototype.slice.call(arguments)));} BookingToolController.controllerProperties = function() { return AngularController.controllerProperties.apply(BookingToolController, [BookingToolController].concat(Array.prototype.slice.call(arguments)));} BookingToolController.controllerMethods = function() { return AngularController.controllerMethods.apply(BookingToolController, [BookingToolController].concat(Array.prototype.slice.call(arguments)));} function AngularFilter() { var gSobject = gs.init('AngularFilter'); gSobject.clazz = { name: 'AngularFilter', simpleName: 'AngularFilter'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.filterLoader = function() { return gSobject['filter'] } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function AngularDirective() { var gSobject = gs.init('AngularDirective'); gSobject.clazz = { name: 'AngularDirective', simpleName: 'AngularDirective'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.name = null; gSobject.directive = null; gSobject.directiveLoader = function() { return gSobject['directive'] } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function AngularService() { var gSobject = gs.init('AngularService'); gSobject.clazz = { name: 'AngularService', simpleName: 'AngularService'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.clazz.interfaces = [{ name: 'AngularModule', simpleName: 'AngularModule'}]; gSobject.getAngular = function() { return AngularModule.getAngular(gSobject); } gSobject.rootScope = null; gSobject.state = null; gSobject.session = null; gSobject.location = null; gSobject.self = null; Object.defineProperty(gSobject, 'serviceList', { get: function() { return AngularService.serviceList; }, set: function(gSval) { AngularService.serviceList = gSval; }, enumerable: true }); gSobject['initService'] = function(rootScope, angularState, angularLocation) { gs.sp(this,"rootScope",rootScope); gs.sp(this,"state",angularState); gs.sp(this,"location",angularLocation); gs.sp(this,"session",gs.execStatic(Session,'instance', this,[])); if (!gs.bool(gs.gp(rootScope,"session"))) { gs.sp(rootScope,"session",gSobject.session); }; if (!gs.bool(gs.gp(rootScope,"Utils"))) { gs.sp(rootScope,"Utils",Utils); }; var serviceName = gs.mc(gs.mc(this,"getClass",[], gSobject),"getSimpleName",[]); var newServiceName = gs.plus(gs.mc(serviceName[0],"toLowerCase",[]), (gs.rangeFromList(serviceName, 1, gs.minus(gs.mc(serviceName,"size",[]), 1)))); gs.println(gs.plus("AngularService.initService:", newServiceName)); gs.sp(rootScope,"" + (newServiceName) + "",this); if (gs.mc(gs.gp(this,"methods"),"find",[function(it) { return gs.equals(gs.gp(it,"name"),"init"); }])) { gs.println(gs.plus("AngularService.init():", newServiceName)); return gs.mc(gSobject.self,"init",[]); }; } gSobject['refresh'] = function(it) { if (!gs.bool(gs.gp(gSobject.rootScope,"$$phase"))) { return gs.mc(gSobject.rootScope,"$apply",[]); }; } gSobject['AngularService0'] = function(it) { gs.mc(AngularService.serviceList,"add",[this]); gSobject.self = this; return this; } if (arguments.length==0) {gSobject.AngularService0(); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; AngularService.serviceList = gs.list([]); function Application() { var gSobject = gs.init('Application'); gSobject.clazz = { name: 'Application', simpleName: 'Application'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; gSobject.clazz.interfaces = [{ name: 'AngularModule', simpleName: 'AngularModule'}]; gSobject.getAngular = function() { return AngularModule.getAngular(gSobject); } gSobject.app = null; gSobject.config = null; gSobject.appName = "application"; gSobject.stateList = gs.list([]); gSobject['init'] = function(config) { gs.sp(this,"config",config); if (gs.bool(gs.gp(config,"name"))) { gSobject.appName = gs.gp(config,"name"); }; var dependencies = gs.list(["ui.router"]); if (gs.bool(gs.gp(config,"dependencies"))) { gs.mc(dependencies,"addAll",[gs.gp(config,"dependencies")]); }; gSobject.app = gs.mc(gs.fs('angular', this, gSobject),"module",[gSobject.appName, dependencies]); gs.mc(gSobject.app,"config",[function($stateProvider, $urlRouterProvider, $locationProvider, $injector, $rootScopeProvider) { gs.mc(gSobject.stateList,"each",[function(state) { if (gs.bool(gs.gp(state,"templateUrl"))) { gs.sp(state,"templateUrl",gs.execStatic(Utils,'appendAppVersion', this,[gs.gp(state,"templateUrl")])); gs.mc(gSobject,"cacheTemplate",[gs.gp(state,"templateUrl")]); }; if (gs.bool(gs.gp(config,"defaultUrl"))) { gs.mc($urlRouterProvider,"when",["", gs.gp(config,"defaultUrl")]); gs.mc($urlRouterProvider,"when",["/", gs.gp(config,"defaultUrl")]); } else { if (gs.bool(gs.gp(state,"default"))) { gs.mc($urlRouterProvider,"when",["", gs.gp(state,"url")]); gs.mc($urlRouterProvider,"when",["/", gs.gp(state,"url")]); }; }; if (gs.bool(gs.gp(state,"when"))) { return gs.mc($urlRouterProvider,"when",[gs.gp(state,"when")[0], gs.gp(state,"when")[1]]); } else { if (gs.bool(gs.gp(state,"otherwise"))) { return gs.mc($urlRouterProvider,"otherwise",[gs.gp(state,"otherwise")]); } else { return gs.mc($stateProvider,"state",[gs.gp(state,"name"), state]); }; }; }]); if (gs.bool(gs.gp(config,"html5"))) { gs.mc($locationProvider,"html5Mode",[gs.map().add("enabled",true).add("requireBase",true)]); }; return gs.mc($urlRouterProvider,"when",["", "/"]); }]); if (!gs.bool(gs.gp(config,"disableBackListener"))) { return gs.mc(gSobject.app,"run",[function($rootScope, $location, $window) { gs.mc($rootScope,"$on",["$locationChangeStart", function(event, next, current) { return gs.execStatic(BackButtonService,'manageBackButtonPressed', this,[$location]); }]); return gs.mc($rootScope,"$watch",[function(it) { return gs.mc($location,"path",[]); }, function(next, current) { return gs.execStatic(BackButtonService,'manageBackButtonWatch', this,[next, current, config, $window, $location]); }]); }]); }; } gSobject.cacheTemplate = function(templateUrl) { setTimeout(function(){ var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", templateUrl, true); xmlhttp.setRequestHeader('cache-control', 'no-cache, must-revalidate, post-check=0, pre-check=0'); xmlhttp.setRequestHeader('cache-control', 'max-age=0'); xmlhttp.setRequestHeader('expires', '0'); xmlhttp.setRequestHeader('expires', 'Tue, 01 Jan 1980 1:00:00 GMT'); xmlhttp.setRequestHeader('pragma', 'no-cache'); xmlhttp.send(); }, 10000); } gSobject['buildControllerName'] = function(controller) { var name = gs.gp(controller,"name"); if (!gs.bool(name)) { name = gs.mc(gs.mc(controller,"getClass",[]),"getSimpleName",[]); }; return name; } gSobject['addController'] = function(controller, dependencies, injections) { if (dependencies === undefined) dependencies = gs.list([]); if (injections === undefined) injections = gs.list([]); var controllerName = gs.elvis(gs.bool(gs.gp(controller,"controllerName")) , gs.gp(controller,"controllerName") , gs.mc(gSobject,"buildControllerName",[controller])); if ((gs.bool(gs.gp(gSobject.config,"restrictedControllers"))) && (!gs.bool(gs.mc(gs.gp(gSobject.config,"restrictedControllers"),"contains",[controllerName])))) { return null; }; if ((gs.bool(gs.gp(gSobject.config,"exludeControllers"))) && (gs.mc(gs.gp(gSobject.config,"exludeControllers"),"contains",[controllerName]))) { return null; }; gs.sp(controller,"controllerName",controllerName); gs.mc(gSobject.app,"controller",[controllerName, gs.list(["$scope" , "$injector" , "$rootScope" , "$state" , "$location" , gs.mc(controller,"angularInit",[dependencies, injections])])]); if (gs.bool(gs.gp(controller,"states"))) { if (gs.instanceOf(gs.gp(controller,"states"), "HashMap")) { gs.sp(controller,"states",gs.list([gs.gp(controller,"states")])); }; gs.mc(gs.gp(controller,"states"),"each",[function(state) { if (gs.bool(gs.gp(state,"resolve"))) { return gs.sp(state,"resolve",gs.toJsObj(gs.gp(state,"resolve"))); }; }]); gs.mc(gs.gp(controller,"states"),"each",[function(state) { if (!gs.bool(gs.gp(state,"controller"))) { return gs.sp(state,"controller",controllerName); }; }]); return gs.mc(gSobject.stateList,"addAll",[gs.gp(controller,"states")]); }; } gSobject['addFilter'] = function(filter) { return gs.mc(gSobject.app,"filter",[gs.gp(filter,"name"), gs.gp(filter,"filterLoader")]); } gSobject['addDirective'] = function(directive) { return gs.mc(gSobject.app,"directive",[gs.gp(directive,"name"), gs.gp(directive,"directiveLoader")]); } gSobject['addComponent'] = function(component) { return gs.mc(gSobject.app,"component",[gs.gp(component,"name"), gs.toJavascript(gs.gp(component,"component"))]); } gSobject['setExitApplicationCallback'] = function(callback) { return gs.sp(gs.gp(gs.thisOrObject(this,gSobject),"config"),"exitApplicationCallback",callback); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function BackButtonService() { var gSobject = gs.init('BackButtonService'); gSobject.clazz = { name: 'BackButtonService', simpleName: 'BackButtonService'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'previousUrl', { get: function() { return BackButtonService.previousUrl; }, set: function(gSval) { BackButtonService.previousUrl = gSval; }, enumerable: true }); gSobject.manageBackButtonPressed = function(x0) { return BackButtonService.manageBackButtonPressed(x0); } gSobject.manageBackButtonWatch = function(x0,x1,x2,x3,x4) { return BackButtonService.manageBackButtonWatch(x0,x1,x2,x3,x4); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; BackButtonService.manageBackButtonPressed = function(location) { gs.println("manageBackButtonPressed"); if (gs.execStatic(Utils,'cordovaDevice', this,[])) { return BackButtonService.previousUrl = gs.mc(location,"path",[]); }; } BackButtonService.manageBackButtonWatch = function(next, current, applicationConfig, window, location) { gs.println("manageBackButtonWatch"); if (gs.execStatic(Utils,'cordovaDevice', this,[])) { if (gs.equals(BackButtonService.previousUrl, next)) { gs.mc(gs.mc(location,"path",[gs.gp(applicationConfig,"defaultUrl")]),"replace",[]); gs.println((gs.equals(gs.gp(applicationConfig,"defaultUrl"), current)) && (gs.bool(gs.gp(applicationConfig,"exitApplicationCallback")))); if ((gs.equals(gs.gp(applicationConfig,"defaultUrl"), current)) && (gs.bool(gs.gp(applicationConfig,"exitApplicationCallback")))) { return gs.mc(applicationConfig,"exitApplicationCallback",[]); }; }; }; } BackButtonService.previousUrl = ""; function LanguageFilter() { var gSobject = AngularFilter(); gSobject.clazz = { name: 'LanguageFilter', simpleName: 'LanguageFilter'}; gSobject.clazz.superclass = { name: 'AngularFilter', simpleName: 'AngularFilter'}; gSobject.name = "lang"; gSobject.currentLang = "eng"; gSobject.languages = gs.map(); gSobject['setLanguage'] = function(lang) { return gSobject.currentLang = lang; } gSobject['filter'] = function(key) { gs.println("LanguageFilter"); gs.println(key); var lang = gSobject.currentLang; if (!gs.bool(gSobject.languages[lang])) { return "LANGAUGE_NOT_FOUND"; }; var string = (gSobject.languages[lang])[key]; if (!gs.bool(string)) { return "KEY_NOT_FOUND"; }; return string; } gSobject['add'] = function(lang, map) { if (gSobject.languages[lang]) { return gs.mc(gSobject.languages[lang],"putAll",[map]); } else { return (gSobject.languages[lang]) = map; }; } gSobject['init'] = function(it) { var eng = gs.map(); gs.sp(eng,"TITLE_BLANK",""); gs.sp(eng,"TITLE_SEARCH","Search"); gs.sp(eng,"All","All"); gs.sp(eng,"Archived","Archived"); gs.sp(eng,"Unarchived","Unarchived"); gs.sp(eng,"TITLE_LANGUAGE","Language"); gs.sp(eng,"Active","Active"); gs.sp(eng,"TITLE_BACK","Back"); gs.sp(eng,"TITLE_DATE","Date"); gs.sp(eng,"TITLE_ARCHIVE","Archive"); gs.sp(eng,"TITLE_ARCHIVED","Archived"); gs.sp(eng,"TITLE_CONFIRM_ARCHIVE","Confirm Archive"); gs.sp(eng,"TITLE_RESTORE","Restore"); gs.sp(eng,"TITLE_CONFIRM_RESTORE","Confirm Restore"); gs.sp(eng,"TITLE_TOAST_UPDATE","Updated"); gs.sp(eng,"TITLE_SAVE","Save"); gs.sp(eng,"TITLE_CANCEL","Cancel"); gs.sp(eng,"TITLE_CONFIRM","Confirm"); return gs.mc(gSobject,"add",["eng", eng]); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function CheckValueFilter() { var gSobject = AngularFilter(); gSobject.clazz = { name: 'CheckValueFilter', simpleName: 'CheckValueFilter'}; gSobject.clazz.superclass = { name: 'AngularFilter', simpleName: 'AngularFilter'}; gSobject.name = "isEmpty"; gSobject['filter'] = function(input) { if (!gs.bool(input)) { return true; }; return gs.equals(gs.mc(input,"size",[], null, true), 0); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function RouterBoolean() { var gSobject = AngularFilter(); gSobject.clazz = { name: 'RouterBoolean', simpleName: 'RouterBoolean'}; gSobject.clazz.superclass = { name: 'AngularFilter', simpleName: 'AngularFilter'}; gSobject.name = "routerBoolean"; gSobject['filter'] = function(input) { if (gs.equals(input, false)) { return false; } else { return true; }; } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function ShortenString() { var gSobject = AngularFilter(); gSobject.clazz = { name: 'ShortenString', simpleName: 'ShortenString'}; gSobject.clazz.superclass = { name: 'AngularFilter', simpleName: 'AngularFilter'}; gSobject.name = "shorten"; gSobject['filter'] = function(input, length) { if ((gs.bool(input)) && (gs.mc(input,"size",[]) > length)) { return gs.plus(gs.mc(input,"substring",[0, length]), " ..."); } else { return input; }; } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function NumberRound() { var gSobject = AngularFilter(); gSobject.clazz = { name: 'NumberRound', simpleName: 'NumberRound'}; gSobject.clazz.superclass = { name: 'AngularFilter', simpleName: 'AngularFilter'}; gSobject.name = "round"; gSobject.filter = function(input) { return Number(Math.round(input+'e'+decimals)+'e-'+2); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function IsImage() { var gSobject = AngularFilter(); gSobject.clazz = { name: 'IsImage', simpleName: 'IsImage'}; gSobject.clazz.superclass = { name: 'AngularFilter', simpleName: 'AngularFilter'}; gSobject.name = "isImage"; gSobject['filter'] = function(input) { if (!gs.bool(input)) { return null; }; var parts = gs.mc(input,"tokenize",["."]); var ext = parts[(gs.minus(gs.mc(parts,"size",[]), 1))]; var isImage = false; var gSswitch0 = gs.mc(ext,"toLowerCase",[]); if (gs.equals(gSswitch0, "jpg")) { isImage = true; ; } else if (gs.equals(gSswitch0, "jpeg")) { isImage = true; ; } else if (gs.equals(gSswitch0, "gif")) { isImage = true; ; } else if (gs.equals(gSswitch0, "bmp")) { isImage = true; ; } else if (gs.equals(gSswitch0, "png")) { isImage = true; ; } else { }; return isImage; } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function PeriscopeValidation() { var gSobject = AngularDirective(); gSobject.clazz = { name: 'PeriscopeValidation', simpleName: 'PeriscopeValidation'}; gSobject.clazz.superclass = { name: 'AngularDirective', simpleName: 'AngularDirective'}; gSobject.name = "periValidation"; gSobject.directive = gs.map().add("restrict","A").add("replace",false).add("terminal",true).add("priority",1000).add("compile",compile = function(element, attrs) { return gs.mc(element,"attr",["tooltip", "{{dt()}}"]); }); if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; function PeriscopeAngularBootstrap() { var gSobject = gs.init('PeriscopeAngularBootstrap'); gSobject.clazz = { name: 'PeriscopeAngularBootstrap', simpleName: 'PeriscopeAngularBootstrap'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'angular', { get: function() { return PeriscopeAngularBootstrap.angular; }, set: function(gSval) { PeriscopeAngularBootstrap.angular = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'angularAppInjector', { get: function() { return PeriscopeAngularBootstrap.angularAppInjector; }, set: function(gSval) { PeriscopeAngularBootstrap.angularAppInjector = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'document', { get: function() { return PeriscopeAngularBootstrap.document; }, set: function(gSval) { PeriscopeAngularBootstrap.document = gSval; }, enumerable: true }); gSobject.init = function(it) { return gs.mc(gSobject,"startAngularApp",[]); }; gSobject.startAngularApp = function(it) { return gs.execStatic(Utils,'documentReady', this,[function(it) { gs.println("startAngularApp-------------------"); if (!gs.bool(PeriscopeAngularBootstrap.angularAppInjector)) { PeriscopeAngularBootstrap.angularAppInjector = gs.mc(PeriscopeAngularBootstrap.angular,"bootstrap",[PeriscopeAngularBootstrap.document, gs.list(["application"])]); return gs.println("angular started"); } else { return gs.println("angular already started"); }; }]); }; if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; PeriscopeAngularBootstrap.angular = null; PeriscopeAngularBootstrap.angularAppInjector = null; PeriscopeAngularBootstrap.document = null; function PeriscopeService() { var gSobject = AngularService(); gSobject.clazz = { name: 'PeriscopeService', simpleName: 'PeriscopeService'}; gSobject.clazz.superclass = { name: 'AngularService', simpleName: 'AngularService'}; gSobject.validationMetasCache = gs.map(); gSobject['validationMetas'] = function(obj, callback) { if (gSobject.validationMetasCache[obj]) { if (gs.bool(callback)) { return gs.execCall(callback, this, []); }; } else { return gs.mc(gs.gp(gs.fs('o', this, gSobject),"periscopeGroovyService"),"getObjMetas",[obj, function(objectDef) { (gSobject.validationMetasCache[obj]) = objectDef; if (gs.bool(callback)) { return gs.execCall(callback, this, []); }; }]); }; } gSobject['clearValidationMetas'] = function(obj, callback) { (gSobject.validationMetasCache[obj]) = null; if (gs.bool(callback)) { return gs.execCall(callback, this, []); }; } gSobject.isDefined = function(x0) { return PeriscopeService.isDefined(x0); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; PeriscopeService.isDefined = function(object) { if ( typeof object !== 'undefined' ) { return true } return false } function TransmissionBootstrapEnd() { var gSobject = gs.init('TransmissionBootstrapEnd'); gSobject.clazz = { name: 'TransmissionBootstrapEnd', simpleName: 'TransmissionBootstrapEnd'}; gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'}; Object.defineProperty(gSobject, 'session', { get: function() { return TransmissionBootstrapEnd.session; }, set: function(gSval) { TransmissionBootstrapEnd.session = gSval; }, enumerable: true }); Object.defineProperty(gSobject, 'transmissionReadyCallbackList', { get: function() { return TransmissionBootstrapEnd.transmissionReadyCallbackList; }, set: function(gSval) { TransmissionBootstrapEnd.transmissionReadyCallbackList = gSval; }, enumerable: true }); gSobject['startApp'] = function(it) { gs.println("startApp"); return gs.execStatic(Utils,'documentReady', this,[function(it) { gs.println("Utils.documentReady"); return gs.execStatic(LocalDB,'getInstance', this,[function(it) { gs.println("LocalDB.getInstance"); gs.mc(gs.fs('startupParams', this, gSobject),"beforeSocketInit",[]); gs.execStatic(Socket,'initSocket', this,[gs.gp(gs.fs('startupParams', this, gSobject),"afterSocketInit")]); return gs.mc(gs.gp(gs.fs('transmission', this, gSobject),"onReady"),"runCallbacks",[]); }]); }]); } gSobject['TransmissionBootstrapEnd0'] = function(it) { gs.println("TransmissionBootstrapEnd:start"); if (gs.execStatic(Socket,'isDymicoSystemUpdating', this,[])) { return null; }; gs.mc(gSobject,"startApp",[]); gs.println("TransmissionBootstrapEnd:end"); return this; } if (arguments.length==0) {gSobject.TransmissionBootstrapEnd0(); } if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);}; return gSobject; }; TransmissionBootstrapEnd.session = gs.execStatic(Session,'instance', this,[]); TransmissionBootstrapEnd.transmissionReadyCallbackList = gs.list([]); AngularModule = function() {}; AngularModule.gSaT = function(target) { target.getAngular = function(x0) { return AngularModule.getAngular(target, x0); }; }; AngularModule.$init$ = function($self) { } function AngularModule$static$init$($static$self){ }; AngularModule.getAngular = function($self) { return window.angular; } AngularController = function() {}; AngularController.gSaT = function(target) { AngularController.$init$(target); target.angularInit = function(x0, x1, x2) { return AngularController.angularInit(target, x0, x1, x2); }; target.makeGlobalScope = function(x0, x1) { return AngularController.makeGlobalScope(target, x0, x1); }; target.applicationConfig = function(x0) { return AngularController.applicationConfig(target, x0); }; target.defaultAuthState = function(x0) { return AngularController.defaultAuthState(target, x0); }; target.logAllStates = function(x0, x1) { return AngularController.logAllStates(target, x0, x1); }; target.domElement = function(x0, x1) { return AngularController.domElement(target, x0, x1); }; target.init = function(x0) { return AngularController.init(target, x0); }; target.setup = function(x0) { return AngularController.setup(target, x0); }; target.destroy = function(x0) { return AngularController.destroy(target, x0); }; target.stateChangeStart = function(x0, x1, x2, x3, x4, x5) { return AngularController.stateChangeStart(target, x0, x1, x2, x3, x4, x5); }; target.continueToNextState = function(x0) { return AngularController.continueToNextState(target, x0); }; target.checkRoles = function(x0) { return AngularController.checkRoles(target, x0); }; target.setupControllerOnce = function(x0, x1, x2, x3) { return AngularController.setupControllerOnce(target, x0, x1, x2, x3); }; target.injectAngularServices = function(x0, x1, x2, x3) { return AngularController.injectAngularServices(target, x0, x1, x2, x3); }; target.getAngular = function(x0) { return AngularController.getAngular(target, x0); }; target.refresh = function(x0) { return AngularController.refresh(target, x0); }; target.openUrl = function(x0, x1) { return AngularController.openUrl(target, x0, x1); }; target.controllerProperties = function(x0, x1) { return AngularController.controllerProperties(target, x0, x1); }; target.controllerMethods = function(x0, x1) { return AngularController.controllerMethods(target, x0, x1); }; target.testControllerForInvalidMethods = function(x0, x1) { return AngularController.testControllerForInvalidMethods(target, x0, x1); }; target.getDefaultDependencies = function(x0) { return AngularController.getDefaultDependencies(target, x0); }; target.setDefaultDependencies = function(x0, x1) { return AngularController.setDefaultDependencies(target, x0, x1); }; target.getDefaultInjections = function(x0) { return AngularController.getDefaultInjections(target, x0); }; target.setDefaultInjections = function(x0, x1) { return AngularController.setDefaultInjections(target, x0, x1); }; target.getScope = function(x0) { return AngularController.getScope(target, x0); }; target.setScope = function(x0, x1) { return AngularController.setScope(target, x0, x1); }; target.getRootScope = function(x0) { return AngularController.getRootScope(target, x0); }; target.setRootScope = function(x0, x1) { return AngularController.setRootScope(target, x0, x1); }; target.getSession = function(x0) { return AngularController.getSession(target, x0); }; target.setSession = function(x0, x1) { return AngularController.setSession(target, x0, x1); }; target.getState = function(x0) { return AngularController.getState(target, x0); }; target.setState = function(x0, x1) { return AngularController.setState(target, x0, x1); }; }; AngularController.$init$ = function($self) { $self.AngularController__defaultDependencies = gs.list(["ng" , "ui.router" , "ngMock" , "ngResource"]); $self.AngularController__defaultInjections = gs.list(["$location" , "$state" , "$window" , "$stateParams" , "$http" , "$timeout" , "$sce" , "$interpolate" , "$interval" , "$compile"]); $self.AngularController__destroyString = "$destroy"; $self.AngularController__stateChangeStartString = "$stateChangeStart"; $self.AngularController__stateChangeStartDeregister = null; return $self.AngularController__setupDone = false; } function AngularController$static$init$($static$self){ }; AngularController.angularInit = function($self, dependencies, injections) { var angularInitClosure = gs.mc(function(controller, angularScope, angularInjector, angularRootScope, angularState, angularLocation) { gs.sp(controller,"session",gs.execStatic(Session,'instance', this,[])); gs.sp(controller,"o",gs.gp($self,"o")); gs.sp(controller,"scope",angularScope); gs.sp(controller,"rootScope",angularRootScope); gs.sp(gs.gp(controller,"scope"),"o",gs.gp($self,"o")); gs.sp(gs.gp(controller,"scope"),"session",$self.AngularController__session); gs.sp(controller,"state",angularState); gs.sp(controller,"$location",angularLocation); if (!gs.bool(gs.gp(gs.gp(controller,"rootScope"),"Utils"))) { gs.sp(gs.gp(controller,"rootScope"),"Utils",Utils); }; gs.sp(gs.gp(controller,"scope"),"hasRole",function(roles) { return gs.mc(gs.gp(controller,"session"),"hasRole",[roles]); }); if (!gs.bool(dependencies)) { dependencies = gs.list([]); }; if (!gs.bool(injections)) { injections = gs.list([]); }; gs.mc($self.AngularController__defaultDependencies,"addAll",[dependencies]); var injector = gs.mc(gs.gp($self,"angular"),"injector",[$self.AngularController__defaultDependencies]); gs.mc(injections,"addAll",[$self.AngularController__defaultInjections]); gs.mc(injections,"each",[function(injection) { return gs.sp(controller,"" + (injection) + "",gs.mc(angularInjector,"get",[injection])); }]); gs.mc($self,"testControllerForInvalidMethods",[controller]); gs.mc(gs.mc($self,"controllerProperties",[controller]),"each",[function(nameProperty) { return gs.sp(angularScope,"" + (nameProperty) + "",gs.gp(controller,"" + (nameProperty) + "")); }]); gs.mc(gs.mc($self,"controllerMethods",[controller]),"each",[function(nameMethod) { return gs.sp(angularScope,"" + (nameMethod) + "",controller["" + (nameMethod) + ""]); }]); gs.mc($self,"setupControllerOnce",[angularRootScope, angularState, angularLocation]); if (!gs.bool(gs.mc($self,"checkRoles",[]))) { gs.sp($self.AngularController__session,"redirectAfterLogin",gs.mc(gs.gp($self,"$location"),"url",[])); gs.mc(gs.gp($self,"$state"),"go",[gs.mc($self,"defaultAuthState",[])]); } else { gs.mc(gs.gp(controller,"$window"),"scrollTo",[0, 0]); var contName = gs.mc(gs.mc($self,"getClass",[]),"getSimpleName",[]); gs.println(gs.plus(contName, ".init()")); gs.mc($self,"init",[]); }; gs.mc($self.AngularController__scope,"$on",[$self.AngularController__destroyString, function(it) { gs.mc($self,"destroy",[]); return gs.mc(controller,"stateChangeStartDeregister",[]); }]); return gs.sp(controller,"stateChangeStartDeregister",gs.mc(angularRootScope,"$on",[$self.AngularController__stateChangeStartString, function(event, toState, toParams, fromState, fromParams) { gs.sp(gs.gp(controller,"scope"),"nextStateMap",gs.map().add("toStateName",gs.gp(toState,"name")).add("toParams",toParams)); return gs.mc($self,"stateChangeStart",[event, toState, toParams, fromState, fromParams]); }])); },"curry",[$self]); return angularInitClosure; } AngularController.makeGlobalScope = function($self, s) { globalScope = s; } AngularController.applicationConfig = function($self) { return application.config } AngularController.defaultAuthState = function($self) { return application.config.defaultAuthState } AngularController.logAllStates = function($self, state) { console.table(state.get()) } AngularController.domElement = function($self, element) { return $(element) } AngularController.init = function($self) { return gs.println(gs.plus("AngularController:init:", gs.gp($self,"name"))); } AngularController.setup = function($self) { return gs.println(gs.plus("AngularController:setup:", gs.gp($self,"name"))); } AngularController.destroy = function($self) { return gs.println("AngularController:destroy"); } AngularController.stateChangeStart = function($self, event, toState, toParams, fromState, fromParams) { return gs.println("AngularController:stateChangeStart"); } AngularController.continueToNextState = function($self) { if (gs.bool(gs.gp($self.AngularController__scope,"nextStateMap"))) { return gs.mc($self.AngularController__state,"go",[gs.gp(gs.gp($self.AngularController__scope,"nextStateMap"),"toStateName"), gs.gp(gs.gp($self.AngularController__scope,"nextStateMap"),"toParams")]); }; } AngularController.checkRoles = function($self) { if (!gs.bool(gs.gp($self,"roles"))) { return true; }; var testHasRole = gs.mc($self.AngularController__session,"hasRole",[gs.gp($self,"roles")]); if (!gs.bool(testHasRole)) { gs.println(gs.plus("DOES NOT HAVE ROLES:", gs.gp($self,"roles"))); }; return testHasRole; } AngularController.setupControllerOnce = function($self, angularRootScope, angularState, angularLocation) { if (!gs.bool($self.AngularController__setupDone)) { $self.AngularController__setupDone = true; gs.mc($self,"injectAngularServices",[angularRootScope, angularState, angularLocation]); if (gs.bool(gs.gp($self,"setup"))) { return gs.mc($self,"setup",[]); }; }; } AngularController.injectAngularServices = function($self, angularRootScope, angularState, angularLocation) { var config = gs.mc($self,"applicationConfig",[]); return gs.mc(gs.gp(AngularService,"serviceList"),"each",[function(service) { if (!gs.bool(gs.gp(service,"rootScope"))) { var serviceName = gs.mc(gs.mc(service,"getClass",[]),"getSimpleName",[]); if ((gs.bool(gs.gp(config,"restrictedServices"))) && (!gs.bool(gs.mc(gs.gp(config,"restrictedServices"),"contains",[serviceName])))) { return null; }; if ((gs.bool(gs.gp(config,"excludeServices"))) && (gs.mc(gs.gp(config,"excludeServices"),"contains",[serviceName]))) { return null; }; return gs.mc(service,"initService",[angularRootScope, angularState, angularLocation]); }; }]); } AngularController.getAngular = function($self) { return window.angular; } AngularController.refresh = function($self) { if (!gs.bool(gs.gp($self.AngularController__scope,"$$phase"))) { return gs.mc($self.AngularController__scope,"$apply",[]); }; } AngularController.openUrl = function($self, url) { var win = window.open(url, '_blank'); win.focus(); } AngularController.controllerProperties = function($static$self, controller) { return gs.mc(gs.mc(gs.gp(controller,"properties"),"findAll",[function(key, value) { return !gs.gSin(key, gs.list(["class" , "scope" , "o" , "name" , "roles" , "states" , "construct" , "init"])); }]),"collect",[function(key, value) { return key; }]); } AngularController.controllerMethods = function($static$self, controller) { return gs.mc(gs.mc(gs.gp((controller = gs.metaClass(controller)),"methods"),"findAll",[function(method) { return (((!gs.bool(gs.mc(gs.gp(method,"name"),"startsWith",["set"]))) && (!gs.bool(gs.mc(gs.gp(method,"name"),"startsWith",["get"])))) && (!gs.bool(gs.mc(gs.gp(method,"name"),"contains",["$"])))) && (!gs.bool(gs.gSin(gs.gp(method,"name"), gs.list(["equals" , "hashCode" , "notify" , "notifyAll" , "toString" , "wait" , "controllerMethods" , "controllerProperties" , "init" , "invokeMethod"])))); }]),"collect",[function(it) { return gs.gp(it,"name"); }]); } AngularController.testControllerForInvalidMethods = function($static$self, controller) { var exludeNames = gs.list(["setup" , "setupControllerOnce" , "getAngular" , "getDefaultDependencies" , "setDefaultDependencies" , "getDefaultInjections" , "setDefaultInjections" , "getScope" , "setScope" , "getRootScope" , "setRootScope" , "getSession" , "setSession" , "getState" , "setState" , "getSupportAngularOfflineStart" , "setSupportAngularOfflineStart"]); var methods = gs.mc(gs.mc(gs.gp((controller = gs.metaClass(controller)),"methods"),"findAll",[function(method) { return ((gs.mc(gs.gp(method,"name"),"startsWith",["set"])) || (gs.mc(gs.gp(method,"name"),"startsWith",["get"]))) && (!gs.bool(gs.mc(exludeNames,"contains",[gs.gp(method,"name")]))); }]),"collect",[function(it) { return gs.gp(it,"name"); }]); return gs.mc(methods,"each",[function(it) { return gs.execStatic(Utils,'logExceptionStack', this,[gs.plus((gs.plus((gs.plus("INVALID METHOD NAME: ", gs.gp(controller,"controllerName"))), ":")), it)]); }]); } AngularController.getDefaultDependencies = function($self) { return $self.AngularController__defaultDependencies; } AngularController.setDefaultDependencies = function($self, value) { $self.AngularController__defaultDependencies = value; } AngularController.getDefaultInjections = function($self) { return $self.AngularController__defaultInjections; } AngularController.setDefaultInjections = function($self, value) { $self.AngularController__defaultInjections = value; } AngularController.getScope = function($self) { return $self.AngularController__scope; } AngularController.setScope = function($self, value) { $self.AngularController__scope = value; } AngularController.getRootScope = function($self) { return $self.AngularController__rootScope; } AngularController.setRootScope = function($self, value) { $self.AngularController__rootScope = value; } AngularController.getSession = function($self) { return $self.AngularController__session; } AngularController.setSession = function($self, value) { $self.AngularController__session = value; } AngularController.getState = function($self) { return $self.AngularController__state; } AngularController.setState = function($self, value) { $self.AngularController__state = value; } gs.println("GROOSCRIPT START : TransmissionBootstrapStart"); var transmission = Transmission; var startupParams = StartupParams(); gs.mc(startupParams,"checkStartupAuth",[]); gs.toGroovy = function(obj, objClass) { var result = obj; if (obj !== undefined && !(typeof(obj) === "function") && !(obj instanceof Date)) { if (obj instanceof Array) { result = gs.list([]); var i; for (i = 0; i < obj.length; i++) { result.add(gs.toGroovy(obj[i], objClass)); } } else if (obj instanceof Date) { // console.log(obj); } else if (obj instanceof Object) { var ob; result = (objClass ? objClass() : gs.map()); for (ob in obj) { result[ob] = gs.toGroovy(obj[ob]); } } } return result; }; ; Array.prototype.add = function(pos, element) { if (element === undefined) { this.push(pos); } else { this.splice(pos, 0, element); } return this; }; ; var session = gs.execStatic(Session,'instance', this,[]); gs.sp(Socket,"window",window); gs.sp(Socket,"navigator",navigator); gs.execStatic(Socket,'init', this,[]); gs.mc(window,"addEventListener",["online", function(it) { gs.println("ONLINE"); return gs.execStatic(Socket,'reconnect', this,[]); }]); gs.sp(Utils,"window",window); gs.sp(Utils,"document",document); gs.execStatic(Utils,'loadScript', this,["/statics/transmission/lz-string.min.js"]); gs.execStatic(Utils,'loadScript', this,["https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"]); var o = ObjectFinder(); var bookingToolController = null; gs.execStatic(Utils,'setTimeout', this,[function(it) { bookingToolController = BookingToolController(); return gs.mc(gs.fs('application', this),"addController",[bookingToolController]); }, 100]); gs.sp(StartupParams,"doAuthToken",false); var angularConfig = gs.map().add("name","application").add("defaultUrl",gs.plus("/bookingTool/", bookingToolControllerEventId)).add("dependencies",gs.list(["ui.bootstrap" , "ngAnimate" , "ui.bootstrap.datetimepicker"])); var application = Application(); gs.mc(application,"init",[angularConfig]); var languageFilter = LanguageFilter(); gs.mc(languageFilter,"init",[]); gs.mc(application,"addFilter",[languageFilter]); gs.mc(application,"addFilter",[CheckValueFilter()]); gs.mc(application,"addFilter",[RouterBoolean()]); gs.mc(application,"addFilter",[ShortenString()]); gs.mc(application,"addFilter",[NumberRound()]); gs.mc(application,"addFilter",[IsImage()]); // console.log('ADDING viewInclude') // application.addDirective('viewInclude', [function() { // return { // replace: true, // scope: { // viewInclude: '@' // }, // template: '
', // link: function($scope) { // console.log('viewInclude viewInclude viewInclude viewInclude viewInclude viewInclude viewInclude'); // console.log($scope.viewInclude) // console.log(Utils.appendAppVersion($scope.viewInclude)); // $scope.link = Utils.appendAppVersion($scope.viewInclude); // } // }; // }]); ; gs.mc(application,"addDirective",[PeriscopeValidation()]); var periscopeAngularBootstrap = PeriscopeAngularBootstrap(); gs.sp(periscopeAngularBootstrap,"angular",angular); gs.sp(periscopeAngularBootstrap,"document",document); gs.sp(startupParams,"offlineStartFunction",gs.gp(periscopeAngularBootstrap,"init")); gs.sp(startupParams,"onlineStartNoAuthFunction",gs.gp(periscopeAngularBootstrap,"init")); gs.sp(startupParams,"onlineStartAuthSuccessFunction",gs.gp(periscopeAngularBootstrap,"init")); var periscopeService = PeriscopeService(); TransmissionBootstrapEnd(); gs.println("GROOSCRIPT END");