Passed
Push — master ( 4d8691...f8c985 )
by Michael
02:38
created

ajaxUtil.js ➔ showAjaxMessages   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 21
rs 9.0534

1 Function

Rating   Name   Duplication   Size   Complexity  
A ajaxUtil.js ➔ ... ➔ printMessagesToMessageArea 0 3 1
1
window.magicMatcherUtil = window.magicMatcherUtil || {};
2
3
window.magicMatcherUtil.showAjaxMessages = function showAjaxMessages(response) {
4
    'use strict';
5
6
    let $msgArea;
7
    if (jQuery('body.tpl_sprintdoc').length) {
8
        $msgArea = jQuery('#dokuwiki__content').find('.msg-area');
9
    } else {
10
        $msgArea = jQuery('#dokuwiki__content').find('> div').first();
11
    }
12
    if (!Object.prototype.hasOwnProperty.call(response, 'msg')) {
13
        $msgArea.prepend(jQuery('<div>').addClass('error').html(response));
14
        return;
15
    }
16
    const messages = response.msg;
17
    if (!messages) {
18
        return;
19
    }
20
    messages.forEach(function printMessagesToMessageArea(msg) {
21
        $msgArea.prepend(jQuery('<div>').addClass(msg.lvl).html(msg.msg));
22
    });
23
};
24
25
window.magicMatcherUtil.handleFailedAjax = function handleFailedAjax(jqXHR) {
26
    'use strict';
27
28
    var HIGHEST_OK_STATUS = 206;
29
    window.magicMatcherUtil.showAjaxMessages(jqXHR.responseJSON);
30
    if (jqXHR.status && jqXHR.status > HIGHEST_OK_STATUS) {
31
        console.error(jqXHR.status + ' ' + jqXHR.statusText);
32
    }
33
};
34
35