added global script/ajax error handling.

This commit is contained in:
kay.one 2013-01-26 13:07:34 -08:00
parent 4cca5d21b1
commit b393c11b27
10 changed files with 109 additions and 17 deletions

View File

@ -194,7 +194,7 @@
<Content Include="_backboneApp\AddSeries\SearchResultModel.js" /> <Content Include="_backboneApp\AddSeries\SearchResultModel.js" />
<Content Include="_backboneApp\AddSeries\SearchResultCollection.js" /> <Content Include="_backboneApp\AddSeries\SearchResultCollection.js" />
<Content Include="_backboneApp\Content\Intelisense\bootstrap.css" /> <Content Include="_backboneApp\Content\Intelisense\bootstrap.css" />
<Content Include="_backboneApp\errorHandler.js" /> <Content Include="_backboneApp\nzbdrone.logging.js" />
<Content Include="_backboneApp\JsLibraries\backbone.marionette.extend.js" /> <Content Include="_backboneApp\JsLibraries\backbone.marionette.extend.js" />
<Compile Include="_backboneApp\CassetteConfiguration.cs" /> <Compile Include="_backboneApp\CassetteConfiguration.cs" />
<Compile Include="Controllers\ImageController.cs" /> <Compile Include="Controllers\ImageController.cs" />
@ -385,6 +385,9 @@
<Content Include="_backboneApp\JsLibraries\backbone.js" /> <Content Include="_backboneApp\JsLibraries\backbone.js" />
<Content Include="_backboneApp\JsLibraries\backbone.marionette.js" /> <Content Include="_backboneApp\JsLibraries\backbone.marionette.js" />
<Content Include="_backboneApp\AddSeries\addSeriesLayoutTemplate.html" /> <Content Include="_backboneApp\AddSeries\addSeriesLayoutTemplate.html" />
<Content Include="_backboneApp\Shared\ErrorModel.js" />
<Content Include="_backboneApp\Shared\ErrorTemplate.html" />
<Content Include="_backboneApp\Shared\ErrorView.js" />
<Content Include="_backboneApp\Shared\SpinnerTemplate.html" /> <Content Include="_backboneApp\Shared\SpinnerTemplate.html" />
<Content Include="_backboneApp\Shared\SpinnerView.js" /> <Content Include="_backboneApp\Shared\SpinnerView.js" />
<None Include="_backboneApp\JsLibraries\jquery-1.8.2.intellisense.js" /> <None Include="_backboneApp\JsLibraries\jquery-1.8.2.intellisense.js" />

View File

@ -50,6 +50,8 @@
</div> </div>
<div id="content" class="row"> <div id="content" class="row">
<div class="span20"> <div class="span20">
<div id="error-region" class="row">
</div>
<div id="sub-menu-region" class="row"> <div id="sub-menu-region" class="row">
</div> </div>
<div class="row"> <div class="row">

View File

@ -31,6 +31,7 @@ namespace NzbDrone.Web.Backbone.NzbDrone
bundles.Add<ScriptBundle>(NZBDRONE, new[]{ bundles.Add<ScriptBundle>(NZBDRONE, new[]{
APP_PATH + "\\AddSeries\\AddSeriesLayout.js", APP_PATH + "\\AddSeries\\AddSeriesLayout.js",
APP_PATH + "\\Shared\\ErrorView.js",
}); });

View File

@ -58,3 +58,12 @@ body {
text-align: center; text-align: center;
padding: 30px; padding: 30px;
} }
#error-region .alert {
margin: 10px;
}
#error-region .alert .icon-warning-sign {
padding-right: 10px;
}

View File

@ -0,0 +1,16 @@
/// <reference path="../app.js" />
NzbDrone.Shared.ErrorCollection = Backbone.Collection.extend({
model: NzbDrone.Shared.ErrorModel,
});
NzbDrone.Shared.ErrorModel = Backbone.Model.extend({
defaults: {
"title": "NO_TITLE",
"message": "NO_MESSAGE",
}
});

View File

@ -0,0 +1,4 @@
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="icon-warning-sign" /><strong>{{title}}</strong> {{message}}
</div>

View File

@ -0,0 +1,68 @@
/// <reference path="../app.js" />
/// <reference path="ErrorModel.js" />
NzbDrone.Shared.ErrorItemView = Backbone.Marionette.ItemView.extend({
template: "Shared/ErrorTemplate",
});
NzbDrone.Shared.ErrorView = Backbone.Marionette.CollectionView.extend({
itemView: NzbDrone.Shared.ErrorItemView,
initialize: function () {
this.collection = new NzbDrone.Shared.ErrorCollection();
this.listenTo(this.collection, 'reset', this.render);
},
});
NzbDrone.addInitializer(function (options) {
console.log("initializing error handler");
NzbDrone.Shared.ErrorView.instance = new NzbDrone.Shared.ErrorView();
NzbDrone.errorRegion.show(NzbDrone.Shared.ErrorView.instance);
});
window.onerror = function (msg, url, line) {
var errorView = NzbDrone.Shared.ErrorView.instance;
if (errorView) {
var model = new NzbDrone.Shared.ErrorModel();
var a = document.createElement('a');
a.href = url;
model.set('title', a.pathname.split('/').pop() + " : " + line);
model.set('message', msg);
errorView.collection.add(model);
} else {
alert("Error: " + msg + "\nurl: " + url + "\nline #: " + line);
}
var suppressErrorAlert = false;
// If you return true, then error alerts (like in older versions of
// Internet Explorer) will be suppressed.
return suppressErrorAlert;
};
$(document).ajaxError(function (event, XMLHttpRequest, ajaxOptionsa) {
var errorView = NzbDrone.Shared.ErrorView.instance;
var model = new NzbDrone.Shared.ErrorModel();
model.set('title', ajaxOptionsa.url + " : " + XMLHttpRequest.statusText);
model.set('message', XMLHttpRequest.responseText);
errorView.collection.add(model);
var suppressErrorAlert = false;
// If you return true, then error alerts (like in older versions of
// Internet Explorer) will be suppressed.
return suppressErrorAlert;
});

View File

@ -10,7 +10,7 @@
/// <reference path="JsLibraries/backbone.marionette.extend.js" /> /// <reference path="JsLibraries/backbone.marionette.extend.js" />
/// <reference path="JsLibraries/backbone.modelbinder.js" /> /// <reference path="JsLibraries/backbone.modelbinder.js" />
/// <reference path="JsLibraries/bootstrap.js" /> /// <reference path="JsLibraries/bootstrap.js" />
/// <reference path="errorHandler.js" /> /// <reference path="nzbdrone.logging.js" />
if (typeof console == "undefined") { if (typeof console == "undefined") {
window.console = { log: function () { } }; window.console = { log: function () { } };
@ -74,6 +74,7 @@ NzbDrone.addInitializer(function (options) {
NzbDrone.addRegions({ NzbDrone.addRegions({
mainRegion: "#main-region", mainRegion: "#main-region",
errorRegion: "#error-region",
}); });
NzbDrone.Router = new NzbDrone.Router(); NzbDrone.Router = new NzbDrone.Router();

View File

@ -1,15 +0,0 @@
/// <reference path="JsLibraries/jquery.js" />
window.onerror = function (msg, url, line) {
alert("Error: " + msg + "\nurl: " + url + "\nline #: " + line);
var suppressErrorAlert = false;
// If you return true, then error alerts (like in older versions of
// Internet Explorer) will be suppressed.
return suppressErrorAlert;
};
$(document).ajaxSuccess(function (event, XMLHttpRequest, ajaxOptionsa) {
console.log(ajaxOptionsa);
});

View File

@ -0,0 +1,3 @@
$(document).ajaxSuccess(function (event, XMLHttpRequest, ajaxOptionsa) {
console.log(ajaxOptionsa);
});