Passed
Pull Request — master (#116)
by
unknown
03:57
created

assets/js/subscriptions.js   A

Complexity

Total Complexity 13
Complexity/F 1.18

Size

Lines of Code 92
Function Count 11

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 92
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  
B $(document).ready 0 90 1
1
var WPInv_Admin;
2
3
jQuery( document ).ready( function ( $ ) {
4
5
	var WPInv_Recurring = {
6
		init: function () {
7
8
			//Recurring select field conditionals
9
			this.edit_product_id();
10
			this.edit_profile_id();
11
			this.edit_txn_id();
12
			this.delete();
13
14
		},
15
16
        /**
17
         * Edit Subscription Text Input
18
         */
19
        edit_subscription_input: function (link, input) {
20
21
            //User clicks edit
22
            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...
23
                //Preserve current value
24
                link.data('current-value', input.val());
25
                //Update text to 'cancel'
26
                link.text(WPInv_Admin.action_cancel);
27
            } else {
28
                //User clicked cancel, return previous value
29
                input.val(link.data('current-value'));
30
                //Update link text back to 'edit'
31
                link.text(WPInv_Admin.action_edit);
32
            }
33
34
        },
35
36
		edit_profile_id: function() {
37
38
			$('.wpinv-edit-sub-profile-id').on('click', function(e) {
39
				e.preventDefault();
40
41
				var link = $(this);
42
				var profile_input = $('input.wpinv-sub-profile-id');
43
				WPInv_Recurring.edit_subscription_input(link, profile_input);
44
45
				$('.wpinv-sub-profile-id').toggle();
46
				$('#wpinv-sub-profile-id-update-notice').slideToggle();
47
			});
48
49
		},
50
51
		edit_product_id: function() {
52
53
			$('.wpinv-sub-product-id').on('change', function(e) {
54
				e.preventDefault();
55
56
				$('#wpinv-sub-product-update-notice').slideDown();
57
			});
58
59
		},
60
61
		edit_txn_id: function() {
62
63
			$('.wpinv-edit-sub-transaction-id').on('click', function(e) {
64
				e.preventDefault();
65
66
				var link = $(this);
67
				var txn_input = $('input.wpinv-sub-transaction-id');
68
				WPInv_Recurring.edit_subscription_input(link, txn_input);
69
70
				$('.wpinv-sub-transaction-id').toggle();
71
			});
72
73
		},
74
75
		delete: function() {
76
77
			$('.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...
78
79
				if( confirm( WPInv_Admin.delete_subscription ) ) {
0 ignored issues
show
Bug introduced by
The variable WPInv_Admin seems to be never initialized.
Loading history...
80
					return true;
81
				}
82
83
				return false;
84
			});
85
86
		}
87
88
	};
89
90
	WPInv_Recurring.init();
91
92
} );
93