Passed
Pull Request — master (#126)
by Kiran
04:13
created

assets/js/subscriptions.js   A

Complexity

Total Complexity 13
Complexity/F 1.18

Size

Lines of Code 63
Function Count 11

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 13
mnd 1
bc 14
fnc 11
bpm 1.2727
cpm 1.1818
noi 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A $(document).ready 0 62 1
1
var WPInv_Admin;
2
jQuery(document).ready(function($) {
3
    var WPInv_Recurring = {
4
        init: function() {
5
            //Recurring select field conditionals
6
            this.edit_product_id();
7
            this.edit_profile_id();
8
            this.edit_txn_id();
9
            this.delete();
10
        },
11
        /**
12
         * Edit Subscription Text Input
13
         */
14
        edit_subscription_input: function(link, input) {
15
            //User clicks edit
16
            if (link.text() === WPInv_Admin.action_edit) {
0 ignored issues
show
Bug introduced by
The variable WPInv_Admin seems to be never initialized.
Loading history...
17
                //Preserve current value
18
                link.data('current-value', input.val());
19
                //Update text to 'cancel'
20
                link.text(WPInv_Admin.action_cancel);
21
            } else {
22
                //User clicked cancel, return previous value
23
                input.val(link.data('current-value'));
24
                //Update link text back to 'edit'
25
                link.text(WPInv_Admin.action_edit);
26
            }
27
        },
28
        edit_profile_id: function() {
29
            $('.wpinv-edit-sub-profile-id').on('click', function(e) {
30
                e.preventDefault();
31
                var link = $(this);
32
                var profile_input = $('input.wpinv-sub-profile-id');
33
                WPInv_Recurring.edit_subscription_input(link, profile_input);
34
                $('.wpinv-sub-profile-id').toggle();
35
                $('#wpinv-sub-profile-id-update-notice').slideToggle();
36
            });
37
        },
38
        edit_product_id: function() {
39
            $('.wpinv-sub-product-id').on('change', function(e) {
40
                e.preventDefault();
41
                $('#wpinv-sub-product-update-notice').slideDown();
42
            });
43
        },
44
        edit_txn_id: function() {
45
            $('.wpinv-edit-sub-transaction-id').on('click', function(e) {
46
                e.preventDefault();
47
                var link = $(this);
48
                var txn_input = $('input.wpinv-sub-transaction-id');
49
                WPInv_Recurring.edit_subscription_input(link, txn_input);
50
                $('.wpinv-sub-transaction-id').toggle();
51
            });
52
        },
53
        delete: function() {
54
            $('.wpinv-delete-subscription').on('click', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
55
                if (confirm(WPInv_Admin.delete_subscription)) {
0 ignored issues
show
Bug introduced by
The variable WPInv_Admin seems to be never initialized.
Loading history...
56
                    return true;
57
                }
58
                return false;
59
            });
60
        }
61
    };
62
    WPInv_Recurring.init();
63
});