Completed
Push — master ( 388b89...cbc64f )
by Florian
06:14
created

payolution.js ➔ switchInstallmentPlan   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
rs 9.3142
cc 1
nc 1
nop 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A payolution.js ➔ ... ➔ $$.each 0 3 1
1
function displayPayolutionOverlay() {
2
    document.getElementById('payolution_overlay').style.display = "";
3
}
4
function removePayolutionOverlay() {
5
    document.getElementById('payolution_overlay').style.display = "none";
6
}
7
8
function switchVisibility(aIds, blShow) {
9
    for(var i = 0; i < aIds.length; i++) {
10
        var oElement = $(aIds[i]);
11
        if(oElement) {
12
            if(blShow == true) {
13
                oElement.show();
14
            } else {
15
                oElement.hide();
16
            }
17
        }
18
    }
19
}
20
21
function payoneSwitchPayolution(oSelect, sCode) {
22
    if (oSelect == undefined) {
23
        return;
24
    }
25
26
    if(oSelect.value == 'PYV') {
27
        var aHide = [
28
            sCode + '_debit_wrap',
29
            sCode + '_debit_wrap2',
30
            sCode + '_installment_wrap1',
31
            sCode + '_installment_wrap2'
32
        ];
33
        var aShow = [
34
            sCode + '_b2b_wrap',
35
            sCode + '_birthday_wrap',
36
            sCode + '_acceptance_wrap'
37
        ];
38
        switchVisibility(aHide, false);
39
        switchVisibility(aShow, true);
40
        $(sCode + '_selected_installmentplan').value = '0';
41
    } else if(oSelect.value == 'PYD') {
42
        var aHide = [
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable aHide already seems to be declared on line 27. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
43
            sCode + '_installment_wrap1',
44
            sCode + '_installment_wrap2',
45
            sCode + '_debit_subwrap'
46
        ];
47
        var aShow = [
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable aShow already seems to be declared on line 33. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
48
            sCode + '_debit_wrap',
49
            sCode + '_debit_wrap2',
50
            sCode + '_b2b_wrap',
51
            sCode + '_birthday_wrap',
52
            sCode + '_acceptance_wrap'
53
        ];
54
        switchVisibility(aHide, false);
55
        switchVisibility(aShow, true);
56
        $(sCode + '_selected_installmentplan').value = '0';
57
    } else if(oSelect.value == 'PYS') {
58
        if(!$(sCode + '_installment_wrap2').visible()) {// reset installment init state
59
            var aHide = [
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable aHide already seems to be declared on line 27. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
60
                sCode + '_debit_wrap',
61
                sCode + '_debit_wrap2',
62
                sCode + '_debit_subwrap'
63
            ];
64
            var aShow = [
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable aShow already seems to be declared on line 33. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
65
                sCode + '_installment_wrap1'
66
            ];
67
            switchVisibility(aHide, false);
68
            switchVisibility(aShow, true);
69
            $(sCode + '_selected_installmentplan').value = '';
70
        }
71
    }
72
    
73
    if(oSelect.value == '') {
74
        $(sCode + '_main_block').hide();
75
    } else {
76
        $(sCode + '_main_block').show();
77
    }
78
}
79
80
function handleInstallmentAllowed(response) {
81
    $(response.code + '_installment_wrap2').update(response.update_section.html);
82
    
83
    var aHide = [
84
        response.code + '_b2b_wrap',
85
        response.code + '_birthday_wrap',
86
        response.code + '_acceptance_wrap',
87
        response.code + '_installment_wrap1'
88
    ];
89
    var aShow = [
90
        response.code + '_installment_wrap2'
91
    ];
92
    switchVisibility(aHide, false);
93
    switchVisibility(aShow, true);
94
}
95
96
function handleInstallment(sCode, sUrl) {
97
    if (checkout.loadWaiting!=false) return;
0 ignored issues
show
Bug introduced by
The variable checkout seems to be never declared. If this is a global, consider adding a /** global: checkout */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
98
    
99
    var validator = new Validation(payment.form);
0 ignored issues
show
Bug introduced by
The variable payment seems to be never declared. If this is a global, consider adding a /** global: payment */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable Validation seems to be never declared. If this is a global, consider adding a /** global: Validation */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
100
    if (payment.validate() && validator.validate()) {
101
        checkout.setLoadWaiting('payment');
102
        
103
        var sDob = $(sCode + '_additional_fields_customer_dob_full').value;
104
        var sType = $(sCode + '_type_select').value;
105
        var sPaymentMethodId = $(sCode + '_payment_method_id').value;
106
107
        new Ajax.Request(sUrl, {
0 ignored issues
show
Unused Code Best Practice introduced by
The object created with new Ajax.Request(sUrl, {...alse,false,None,None)}) is not used but discarded. Consider invoking another function instead of a constructor if you are doing this purely for side effects.
Loading history...
Bug introduced by
The variable Ajax seems to be never declared. If this is a global, consider adding a /** global: Ajax */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
108
            method: 'Post',
109
            parameters: {
110
                payone_payolution_type : sType,
111
                payone_customer_dob : sDob,
112
                payone_config_payment_method_id : sPaymentMethodId,
113
                code : sCode
114
            },
115
            onComplete: function(transport) {
116
                checkout.setLoadWaiting(false);
0 ignored issues
show
Bug introduced by
The variable checkout seems to be never declared. If this is a global, consider adding a /** global: checkout */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
117
                if(transport.responseText) {
118
                    response = JSON.parse(transport.responseText);
0 ignored issues
show
Bug introduced by
The variable response seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.response.
Loading history...
119
                    if(response.success == true) {
120
                        handleInstallmentAllowed(response);
121
                        return;
122
                    }
123
                }
124
                alert(Translator.translate("The installment calculation failed. Please choose another payment type."));
0 ignored issues
show
Bug introduced by
The variable Translator seems to be never declared. If this is a global, consider adding a /** global: Translator */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
125
            }
126
        });
127
    }
128
}
129
130
function switchInstallmentPlan(sKey, sCode, iInstallments) {
131
    $$('.payolution_installmentplans').each(
132
       function (e) {
133
          e.hide(); 
134
       } 
135
    );
136
    $$('.payolution_installment_overview').each(
137
       function (e) {
138
          e.hide(); 
139
       } 
140
    );
141
    
142
    var aShow = [
143
        'payolution_installmentplan_' + sKey,
144
        'payolution_installment_overview_' + sKey,
145
        sCode + '_debit_wrap',
146
        sCode + '_debit_subwrap'
147
    ];
148
    switchVisibility(aShow, true);
149
    $(sCode + '_selected_installmentplan').value = iInstallments;
150
}