general-settings.js
3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* global _SEARCHWP */
( function($) {
'use strict';
const app = {
/**
* Init.
*
* @since 4.3.0
*/
init: () => {
$( app.ready );
},
/**
* Document ready
*
* @since 4.3.0
*/
ready: () => {
app.events();
},
/**
* Page events.
*
* @since 4.3.0
*/
events: () => {
$( '#swp-license-activate' ).on( 'click', app.activateLicense );
$( '#swp-license-deactivate' ).on( 'click', app.deactivateLicense );
},
/**
* Callback for clicking "Activate License" button.
*
* @since 4.3.0
*/
activateLicense: function(e) {
e.preventDefault();
$( '#swp-license-error-msg' ).hide().empty();
$( '.swp-content-container button' ).attr( 'disabled','disabled' );
$( '#swp-license-activate' ).addClass( 'swp-button--processing' );
$.post(
ajaxurl,
{
_ajax_nonce: _SEARCHWP.nonce,
action: _SEARCHWP.prefix + 'license_activate',
license_key: $( '#swp-license' ).val(),
},
app.activateLicenseProcessResponse
);
},
/**
* Callback for clicking "Deactivate License" button.
*
* @since 4.3.0
*/
deactivateLicense: function(e) {
e.preventDefault();
$( '#swp-license-error-msg' ).hide().empty();
$( '.swp-content-container button' ).attr( 'disabled','disabled' );
$( '#swp-license-deactivate' ).addClass( 'swp-button--processing' );
$.post(
ajaxurl,
{
_ajax_nonce: _SEARCHWP.nonce,
action: _SEARCHWP.prefix + 'license_deactivate',
license_key: $( '#swp-license' ).val(),
},
app.deactivateLicenseProcessResponse
);
},
/**
* Process response for the "Activate License" button callback.
*
* @since 4.3.0
*/
activateLicenseProcessResponse: ( response ) => {
$( '.swp-content-container button' ).removeAttr( 'disabled' );
$( '#swp-license-activate' ).removeClass( 'swp-button--processing' );
if ( response.success && 'valid' === response.data.status ) {
$( '#swp-license' ).attr( 'type', 'password' ).attr( 'disabled', true );
$( '#swp-license-activate' ).hide();
$( '#swp-license-deactivate' ).show();
$( '#swp-license-inactive-msg' ).hide();
$( '#swp-license-type' ).text( response.data.type.toUpperCase() );
$( '#swp-license-remaining' ).text( response.data.remaining );
$( '#swp-license-active-msg' ).show();
}
if ( ! response.success ) {
$( '#swp-license-error-msg' ).show().text( typeof response.data === 'string' ? response.data : 'There was a problem activating your license.' );
}
},
/**
* Process response for the "Deactivate License" button callback.
*
* @since 4.3.0
*/
deactivateLicenseProcessResponse: ( response ) => {
$( '.swp-content-container button' ).removeAttr( 'disabled' );
$( '#swp-license-deactivate' ).removeClass( 'swp-button--processing' );
if ( response.success && 'deactivated' === response.data.status ) {
$( '#swp-license' ).attr( 'type', 'text' ).attr( 'disabled', false ).removeAttr( 'value' ).val( '' );
$( '#swp-license-activate' ).show();
$( '#swp-license-deactivate' ).hide();
$( '#swp-license-inactive-msg' ).show();
$( '#swp-license-type' ).empty();
$( '#swp-license-remaining' ).empty();
$( '#swp-license-active-msg' ).hide();
}
if ( ! response.success ) {
$( '#swp-license-error-msg' ).show().text( typeof response.data === 'string' ? response.data : 'There was a problem deactivating your license.' );
}
},
};
app.init();
window.searchwp = window.searchwp || {};
window.searchwp.AdminGeneralSettingsPage = app;
}( jQuery ) );