root / ui / static / snf / js / ui / web / ui_error_view.js @ b15a0cc4
History | View | Annotate | Download (6.5 kB)
1 |
;(function(root){
|
---|---|
2 |
|
3 |
// root
|
4 |
var root = root;
|
5 |
|
6 |
// setup namepsaces
|
7 |
var snf = root.synnefo = root.synnefo || {};
|
8 |
var models = snf.models = snf.models || {}
|
9 |
var storage = snf.storage = snf.storage || {};
|
10 |
var ui = snf.ui = snf.ui || {};
|
11 |
var util = snf.util = snf.util || {};
|
12 |
|
13 |
var views = snf.views = snf.views || {}
|
14 |
|
15 |
// shortcuts
|
16 |
var bb = root.Backbone;
|
17 |
|
18 |
views.ErrorView = views.Overlay.extend({ |
19 |
|
20 |
view_id: "error_view", |
21 |
content_selector: "#error-overlay-content", |
22 |
css_class: 'overlay-error', |
23 |
overlay_id: "error-overlay", |
24 |
error_stack: {},
|
25 |
|
26 |
initialize: function() { |
27 |
views.ErrorView.__super__.initialize.apply(this, arguments); |
28 |
var self = this; |
29 |
|
30 |
this.error_state = false; |
31 |
|
32 |
this.$(".actions .show-details, .actions .hide-details").click(function() { |
33 |
self.$(".error-details").toggle(); |
34 |
self.$(".show-details").toggle(); |
35 |
self.$(".hide-details").toggle(); |
36 |
}); |
37 |
|
38 |
this.$(".key.details").click(function() { |
39 |
$(this).next().toggle(); |
40 |
if (!$(this).next().is(":visible")) { |
41 |
$(this).addClass("expand"); |
42 |
} else {
|
43 |
$(this).removeClass("expand"); |
44 |
} |
45 |
}) |
46 |
|
47 |
this.$(".actions .report-error").click(_.bind(function() { |
48 |
this.report_error();
|
49 |
}, this));
|
50 |
|
51 |
this.$(".actions .hide-details").hide(); |
52 |
|
53 |
this.$(".reload-app").click(function(){ |
54 |
window.location.reload(true);
|
55 |
}) |
56 |
}, |
57 |
|
58 |
error_object: function() { |
59 |
return {ns:this.ns, code:this.code, message:this.message, details:this.details}; |
60 |
}, |
61 |
|
62 |
report_error: function() { |
63 |
this.feedback_view = this.feedback_view || ui.main.feedback_view; |
64 |
this.hide(false); |
65 |
window.setTimeout(_.bind(function() {
|
66 |
this.feedback_view.show(this.get_report_message(), true, {error: this.error_object()}); |
67 |
}, this), 400); |
68 |
}, |
69 |
|
70 |
get_report_message: function() { |
71 |
var fdb_msg = "Error report\n" + |
72 |
"-------------------" + "\n" + |
73 |
"Code: " + this.code + "\n" + |
74 |
"Type: " + this.type + "\n" + |
75 |
"Message: " + this.message + "\n" + |
76 |
"Module: " + this.ns + "\n" + |
77 |
"Details: " + this.details + "\n\n" + |
78 |
"Please describe the actions that triggered the error:\n"
|
79 |
|
80 |
return fdb_msg;
|
81 |
}, |
82 |
|
83 |
show_error: function(ns, code, message, type, details, error_options) { |
84 |
if (!snf.api.error_state) { this.error_stack = {} }; |
85 |
|
86 |
if (error_options.fatal_error) {
|
87 |
snf.api.error_state = true;
|
88 |
snf.api.trigger("change:error_state", true); |
89 |
} else {
|
90 |
snf.api.error_state = false;
|
91 |
snf.api.trigger("change:error_state", false); |
92 |
} |
93 |
|
94 |
var error_entry = [ns, code, message, type, details, error_options];
|
95 |
this.error_stack[new Date()] = error_entry; |
96 |
this.display_error.apply(this, error_entry); |
97 |
this.show();
|
98 |
}, |
99 |
|
100 |
display_error: function(ns, code, message, type, details, error_options) { |
101 |
this.error_options = {'allow_report': true, 'allow_reload': true, 'extra_details': {}, 'non_critical': false, 'allow_details': false }; |
102 |
|
103 |
if (error_options) {
|
104 |
this.error_options = _.extend(this.error_options, error_options); |
105 |
} |
106 |
|
107 |
this.code = code;
|
108 |
this.ns = ns;
|
109 |
this.type = type;
|
110 |
this.details = details ? (details.toString ? details.toString() : details) : undefined; |
111 |
this.message = message;
|
112 |
|
113 |
this.update_details();
|
114 |
|
115 |
if (error_options.non_critical) {
|
116 |
this.el.addClass("non-critical"); |
117 |
this.error_options.allow_details = false; |
118 |
} else {
|
119 |
this.el.removeClass("non-critical"); |
120 |
this.error_options.allow_details = true; |
121 |
} |
122 |
|
123 |
//if (APP_DEBUG) {
|
124 |
//this.error_options.allow_details = true;
|
125 |
//}
|
126 |
|
127 |
this.$(".actions .show-details").click(); |
128 |
this.$(".key.details").click(); |
129 |
this.$(".error-more-details").hide(); |
130 |
}, |
131 |
|
132 |
update_details: function() { |
133 |
var title = "Application error"; |
134 |
if (this.ns && this.type) { |
135 |
title = this.title || this.type + " Error"; |
136 |
} |
137 |
this.$(".header .title").text(title); |
138 |
this.$(".error-code").text(this.code || ""); |
139 |
this.$(".error-type").text(this.type || ""); |
140 |
this.$(".error-module").text(this.ns || ""); |
141 |
this.$(".message p").text(this.message || ""); |
142 |
this.$(".error-more-details p").html(this.details || "no info"); |
143 |
|
144 |
this.$(".extra-details").remove(); |
145 |
_.each(this.error_options.extra_details, function(value, key){ |
146 |
var opt = $(('<span class="extra-details key">{0}</span>' + |
147 |
'<span class="extra-details value">{1}</span>').format(key, value))
|
148 |
this.$(".value.error-type").after(opt); |
149 |
}) |
150 |
|
151 |
}, |
152 |
|
153 |
beforeOpen: function() { |
154 |
this.$(".error-details").hide(); |
155 |
this.$(".show-details").show(); |
156 |
this.$(".hide-details").hide(); |
157 |
|
158 |
if (this.error_options.allow_details) { |
159 |
this.$(".show-details").show(); |
160 |
} else {
|
161 |
this.$(".show-details").hide(); |
162 |
} |
163 |
|
164 |
if (this.error_options.allow_report) { |
165 |
this.$(".report-error").show(); |
166 |
} else {
|
167 |
this.$(".report-error").hide(); |
168 |
} |
169 |
|
170 |
if (this.error_options.allow_reload) { |
171 |
this.$(".reload-app").show(); |
172 |
} else {
|
173 |
this.$(".reload-app").hide(); |
174 |
} |
175 |
}, |
176 |
|
177 |
hide: function(reset_state) { |
178 |
if (reset_state === undefined) { reset_state = true }; |
179 |
if (reset_state) {
|
180 |
snf.api.error_state = false;
|
181 |
snf.api.trigger("change:error_state", snf.api.error_state);
|
182 |
} |
183 |
views.ErrorView.__super__.hide.apply(this);
|
184 |
}, |
185 |
|
186 |
onClose: function(reset_state) { |
187 |
this.trigger("close", this); |
188 |
} |
189 |
}); |
190 |
|
191 |
})(this);
|