From 12874b5f7af6d84ea84987ab09b5419a6e28139c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 3 Aug 2013 14:05:08 +0200 Subject: [PATCH] Small improvements submit of data on window close. --- .../app/lib/app_init/track.js.coffee | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_init/track.js.coffee b/app/assets/javascripts/app/lib/app_init/track.js.coffee index 46604baf3..a94c1cc92 100644 --- a/app/assets/javascripts/app/lib/app_init/track.js.coffee +++ b/app/assets/javascripts/app/lib/app_init/track.js.coffee @@ -25,6 +25,7 @@ class _trackSingleton @browser = App.Browser.detection() @data = [] @url = 'https://portal.znuny.com/api/ui' +# @url = 'api/ui' @log( 'start', 'notice', {} ) @@ -59,7 +60,7 @@ class _trackSingleton if settings.url.substr(0,length) isnt @url && settings.url.substr(0,6) isnt 'api/ui' level = 'notice' responseText = '' - if request.status > 200 + if request.status >= 400 level = 'error' responseText = request.responseText @log( @@ -68,6 +69,7 @@ class _trackSingleton { type: settings.type dataType: settings.dataType + async: settings.async url: settings.url data: settings.data status: request.status @@ -80,7 +82,8 @@ class _trackSingleton 'beforeunload' => @log( 'end', 'notice', {} ) - @send() + @send(false) + return ) @@ -93,7 +96,7 @@ class _trackSingleton data: args @data.push info - send: => + send: (async = true) => return if _.isEmpty @data newData = _.clone( @data ) @data = [] @@ -109,10 +112,11 @@ class _trackSingleton newDataNew.push itemNew catch e # nothing - + App.Com.ajax( - type: 'POST' - url: @url + type: 'POST' + url: @url + async: async data: JSON.stringify( track_id: @trackId log: newDataNew @@ -132,6 +136,9 @@ class _trackSingleton @data ` +window.onerror = function(errorMsg, url, lineNumber) { + console.error(errorMsg + " - in " + url + ", line " + lineNumber); +}; (function() { var console = window.console