2013-04-19 08:38:26 +02:00
|
|
|
|
"use strict";
|
|
|
|
|
define(['app', 'Shared/NotificationModel'], function () {
|
2013-02-14 18:18:29 +01:00
|
|
|
|
|
2013-04-19 17:33:55 +02:00
|
|
|
|
var notificationCollection = Backbone.Collection.extend({
|
2013-02-14 18:18:29 +01:00
|
|
|
|
|
|
|
|
|
model: NzbDrone.Shared.NotificationModel,
|
2013-03-30 00:28:58 +01:00
|
|
|
|
|
2013-02-14 18:18:29 +01:00
|
|
|
|
initialize: function () {
|
|
|
|
|
|
2013-03-30 00:28:58 +01:00
|
|
|
|
/* var model = new NzbDrone.Shared.NotificationModel();
|
|
|
|
|
model.set('title','test notification');
|
|
|
|
|
model.set('message','test message');
|
|
|
|
|
model.set('level', 'error');
|
|
|
|
|
this.push(model);
|
|
|
|
|
*/
|
2013-02-16 01:49:25 +01:00
|
|
|
|
|
2013-02-14 18:18:29 +01:00
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
window.onerror = function (msg, url, line) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var model = new NzbDrone.Shared.NotificationModel();
|
|
|
|
|
|
|
|
|
|
var a = document.createElement('a');
|
|
|
|
|
a.href = url;
|
|
|
|
|
|
|
|
|
|
model.set('title', a.pathname.split('/').pop() + ' : ' + line);
|
|
|
|
|
model.set('message', msg);
|
|
|
|
|
model.set('level', 'error');
|
2013-02-15 03:40:29 +01:00
|
|
|
|
self.push(model);
|
2013-02-14 18:18:29 +01:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
|
|
console.log("An error occurred while reporting error. " + error);
|
|
|
|
|
console.log(msg);
|
2013-04-19 08:38:26 +02:00
|
|
|
|
window.alert('Couldn\'t report JS error. ' + msg);
|
2013-02-14 18:18:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false; //don't suppress default alerts and logs.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) {
|
|
|
|
|
|
|
|
|
|
//don't report 200 error codes
|
|
|
|
|
if (xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-19 17:33:55 +02:00
|
|
|
|
//don't report aborted requests
|
2013-02-14 18:18:29 +01:00
|
|
|
|
if (xmlHttpRequest.statusText === 'abort') {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-19 17:33:55 +02:00
|
|
|
|
var model = new NzbDrone.Shared.NotificationModel();
|
|
|
|
|
model.set('level', 'error');
|
2013-02-14 18:18:29 +01:00
|
|
|
|
|
2013-04-19 17:33:55 +02:00
|
|
|
|
if (xmlHttpRequest.status === 0 && xmlHttpRequest.readyState === 0) {
|
|
|
|
|
model.set('title', "Connection Failed");
|
|
|
|
|
model.set('message', "NzbDrone Server Not Reachable. make sure NzbDrone is running.");
|
|
|
|
|
} else {
|
|
|
|
|
model.set('title', ajaxOptions.type + " " + ajaxOptions.url + " : " + xmlHttpRequest.statusText);
|
|
|
|
|
model.set('message', xmlHttpRequest.responseText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.push(model);
|
2013-02-14 18:18:29 +01:00
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2013-04-19 17:33:55 +02:00
|
|
|
|
return new notificationCollection();
|
2013-02-14 18:18:29 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|