Revision dc020cf6 ui/static/snf/js/ui/web/ui_main_view.js

b/ui/static/snf/js/ui/web/ui_main_view.js
15 15
    var bb = root.Backbone;
16 16
    var util = snf.util;
17 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

  
25
        initialize: function() {
26
            views.ErrorView.__super__.initialize.apply(this, arguments);
27
            var self = this;
28

  
29
            this.error_state = false;
30

  
31
            this.$(".actions .show-details, .actions .hide-details").click(function() {
32
                self.$(".error-details").toggle();
33
                self.$(".show-details").toggle();
34
                self.$(".hide-details").toggle();
35
            });
36

  
37
            this.$(".key.details").click(function() {
38
                $(this).next().toggle();
39
                if (!$(this).next().is(":visible")) {
40
                    $(this).addClass("expand");
41
                } else {
42
                    $(this).removeClass("expand");
43
                }
44
            })
45

  
46
            this.$(".actions .report-error").click(_.bind(function() {
47
                this.report_error();
48
            }, this));
49

  
50
            this.$(".actions .hide-details").hide();
51

  
52
            this.$(".reload-app").click(function(){
53
                window.location.reload(true);
54
            })
55
        },
56

  
57
        error_object: function() {
58
            return {ns:this.ns, code:this.code, message:this.message, details:this.details};
59
        },
60

  
61
        report_error: function() {
62
            this.feedback_view = this.feedback_view || ui.main.feedback_view;
63
            this.feedback_view.show(this.get_report_message(), true, {error: this.error_object()});
64
        },
65

  
66
        get_report_message: function() {
67
            var fdb_msg =   "Error report\n" +
68
                "-------------------" + "\n" +
69
                "Code: " + this.code + "\n" + 
70
                "Type: " + this.type + "\n" +
71
                "Message: " + this.message + "\n" +
72
                "Module: " + this.ns + "\n" +
73
                "Details: " + this.details + "\n\n" +
74
                "Please describe the actions that triggered the error:\n"
75
            
76
            return fdb_msg;
77
        },
78

  
79
        show_error: function(ns, code, message, type, details, error_options) {
80
            this.error_options = {'allow_report': true, 'allow_reload': true, 'extra_details': {}, 'non_critical': false};
81

  
82
            if (error_options) {
83
                this.error_options = _.extend(this.error_options, error_options);
84
            }
85

  
86
            this.hide();
87

  
88
            this.code = code;
89
            this.ns = ns;
90
            this.type = type;
91
            this.details = details ? (details.toString ? details.toString() : details) : undefined;
92
            this.message = message;
93

  
94
            this.update_details();
95
            
96
            if (error_options.non_critical) {
97
                this.el.addClass("non-critical");
98
            } else {
99
                this.el.removeClass("non-critical");
100
            }
101

  
102
            this.show();
103
            
104
            this.$(".actions .show-details").click();
105
            this.$(".key.details").click();
106
            this.$(".error-more-details").hide();
107
        },
108

  
109
        update_details: function() {
110
            var title = "Application error";
111
            if (this.ns && this.type) {
112
                title = this.type + ": " + this.message;
113
            }
114
            this.$(".header .title").text(title);
115
            this.$(".error-code").text(this.code || "");
116
            this.$(".error-type").text(this.type || "");
117
            this.$(".error-module").text(this.ns || "");
118
            this.$(".message p").text(this.message || "");
119
            this.$(".error-more-details p").html(this.details || "no info");
120

  
121
            this.$(".extra-details").remove();
122
            _.each(this.error_options.extra_details, function(value, key){
123
                var opt = $(('<span class="extra-details key">{0}</span>' +
124
                            '<span class="extra-details value">{1}</span>').format(key, value))
125
                this.$(".value.error-type").after(opt);
126
            })
127

  
128
        },
129

  
130
        beforeOpen: function() {
131
            this.$(".error-details").hide();
132
            this.$(".show-details").show();
133
            this.$(".hide-details").hide();
134

  
135
            if (this.error_options.allow_report) {
136
                this.$(".report-error").show();
137
            } else {
138
                this.$(".report-error").hide();
139
            }
140

  
141
            if (this.error_options.allow_reload) {
142
                this.$(".reload-app").show();
143
            } else {
144
                this.$(".reload-app").hide();
145
            }
146
        },
147

  
148
        onClose: function() {
149
            this.trigger("close", this);
150
        }
151
    });
152

  
153
    views.NoticeView = views.Overlay.extend({
154
    
155
    });
18
    // TODO: implement me
19
    views.NoticeView = views.Overlay.extend({});
156 20

  
157 21
    views.MultipleActionsView = views.View.extend({
158 22
        view_id: "multiple_actions",
......
476 340
            snf.api.stop_calls = false;
477 341
            this.update_intervals();
478 342
        },
343
        
344
        error_stack: [],
479 345

  
480 346
        handle_api_error: function(xhr, type, message) {
347
            this.stop_intervals();
348

  
481 349
            this.error_state = true;
482 350
            this.log.error("API ERRROR", arguments);
483 351
            
484 352
            var xhr = arguments[0];
485 353
            var args = util.parse_api_error(arguments);
486 354
            
487
            this.stop_intervals();
488 355
            snf.api.stop_calls = true;
489
            this.error_view.show_error(args.ns, args.code, args.message, args.type, args.details, args);
356
            
357
            var error_entry = [args.ns, args.code, args.message, args.type, args.details, args];
358

  
359
            this.error_stack.push(error_entry);
360
            this.error_view.show_error.apply(this.error_view, error_entry);
490 361
        },
491 362

  
492 363
        handle_ui_error: function(error) {

Also available in: Unified diff