Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/**
2
 * A dialogue type designed to display an appropriate error when an error
3
 * thrown in the Moodle codebase was reported during an AJAX request.
4
 *
5
 * @module moodle-core-notification
6
 * @submodule moodle-core-notification-ajaxexception
7
 */
8
 
9
var AJAXEXCEPTION_NAME = 'Moodle AJAX exception',
10
    AJAXEXCEPTION;
11
 
12
/**
13
 * Extends core Dialogue to show the exception dialogue.
14
 *
15
 * @param {Object} config Object literal specifying the dialogue configuration properties.
16
 * @constructor
17
 * @class M.core.ajaxException
18
 * @extends M.core.dialogue
19
 */
20
AJAXEXCEPTION = function(config) {
21
    config.name = config.name || M.util.get_string('error', 'moodle');
22
    config.closeButton = true;
23
    AJAXEXCEPTION.superclass.constructor.apply(this, [config]);
24
};
25
Y.extend(AJAXEXCEPTION, M.core.notification.info, {
26
    _keypress: null,
27
    initializer: function(config) {
28
        var content,
29
            self = this,
30
            delay = this.get('hideTimeoutDelay'),
31
            labelsep = M.util.get_string('labelsep', 'langconfig');
32
        this.get(BASE).addClass('moodle-dialogue-exception');
33
        this.setStdModContent(Y.WidgetStdMod.HEADER,
34
                '<h5 id="moodle-dialogue-' + this.get('COUNT') + '-wrap-header-text">'
35
                    + Y.Escape.html(config.name) + '</h5>',
36
                Y.WidgetStdMod.REPLACE);
37
        content = Y.Node.create('<div class="moodle-ajaxexception" data-rel="fatalerror"></div>')
38
                .append(Y.Node.create('<div class="moodle-exception-message">' + Y.Escape.html(this.get('error')) + '</div>'))
39
                .append(Y.Node.create('<div class="moodle-exception-param hidden param-debuginfo"><label>' +
40
                        M.util.get_string('url', 'moodle') + labelsep + '</label> ' +
41
                        this.get('reproductionlink') + '</div>'))
42
                .append(Y.Node.create('<div class="moodle-exception-param hidden param-debuginfo"><label>' +
43
                        M.util.get_string('debuginfo', 'debug') + labelsep + '</label> ' +
44
                        Y.Escape.html(this.get('debuginfo')) + '</div>'))
45
                .append(Y.Node.create('<div class="moodle-exception-param hidden param-stacktrace"><label>' +
46
                        M.util.get_string('stacktrace', 'debug') + labelsep + '</label> <pre>' +
47
                        Y.Escape.html(this.get('stacktrace')) + '</pre></div>'));
48
        if (M.cfg.developerdebug) {
49
            content.all('.moodle-exception-param').removeClass('hidden');
50
        }
51
        this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
52
 
53
        if (delay) {
54
            this._hideTimeout = setTimeout(function() {
55
                self.hide();
56
            }, delay);
57
        }
58
        this.after('visibleChange', this.visibilityChanged, this);
59
        this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this);
60
        this.centerDialogue();
61
    },
62
    visibilityChanged: function(e) {
63
        if (e.attrName === 'visible' && e.prevVal && !e.newVal) {
64
            var self = this;
65
            this._keypress.detach();
66
            setTimeout(function() {
67
                self.destroy();
68
            }, 1000);
69
        }
70
    }
71
}, {
72
    NAME: AJAXEXCEPTION_NAME,
73
    CSS_PREFIX: DIALOGUE_PREFIX,
74
    ATTRS: {
75
 
76
        /**
77
         * The error message given in the exception.
78
         *
79
         * @attribute error
80
         * @type String
81
         * @default 'Unknown error'
82
         * @optional
83
         */
84
        error: {
85
            validator: Y.Lang.isString,
86
            value: M.util.get_string('unknownerror', 'moodle')
87
        },
88
 
89
        /**
90
         * Any additional debug information given in the exception.
91
         *
92
         * @attribute stacktrace
93
         * @type String|null
94
         * @default null
95
         * @optional
96
         */
97
        debuginfo: {
98
            value: null
99
        },
100
 
101
        /**
102
         * The complete stack trace provided in the exception.
103
         *
104
         * @attribute stacktrace
105
         * @type String|null
106
         * @default null
107
         * @optional
108
         */
109
        stacktrace: {
110
            value: null
111
        },
112
 
113
        /**
114
         * A link which may be used by support staff to replicate the issue.
115
         *
116
         * @attribute reproductionlink
117
         * @type String
118
         * @default null
119
         * @optional
120
         */
121
        reproductionlink: {
122
            setter: function(link) {
123
                if (link !== null) {
124
                    link = Y.Escape.html(link);
125
                    link = '<a href="' + link + '">' + link.replace(M.cfg.wwwroot, '') + '</a>';
126
                }
127
                return link;
128
            },
129
            value: null
130
        },
131
 
132
        /**
133
         * If set, the dialogue is hidden after the specified timeout period.
134
         *
135
         * @attribute hideTimeoutDelay
136
         * @type Number
137
         * @default null
138
         * @optional
139
         */
140
        hideTimeoutDelay: {
141
            validator: Y.Lang.isNumber,
142
            value: null
143
        }
144
    }
145
});
146
 
147
M.core.ajaxException = AJAXEXCEPTION;