-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrt-transcoder-admin.js
120 lines (97 loc) · 2.82 KB
/
rt-transcoder-admin.js
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
/**
* Transcoder admin page.
*
* @package transcoder
*/
/* global ajaxurl, rt_transcoder_script */
( function ( $ ) {
$( document ).ready(
function() {
$( document ).on(
'click',
'#api-key-submit',
function( e ) {
var apikey = document.getElementById( 'new-api-key' ).value;
if ( ! apikey ) {
$( '#api-key-error' ).remove();
var error_div = $(
'<div/>',
{
id: 'api-key-error',
class: 'error'
}
);
$( 'h1:first' ).after( error_div.html( $( '<p/>' ).text( rt_transcoder_script.error_empty_key ) ) );
e.preventDefault();
}
}
);
$( document ).on(
'click',
'#disable-transcoding',
function( e ) {
e.preventDefault();
if ( confirm( rt_transcoder_script.disable_encoding ) ) {
var data = {
action: 'rt_disable_transcoding',
rt_transcoder_nonce: rt_transcoder_script.security_nonce_for_disabling_encoding
};
if ( $( this ).next( 'img' ).length === 0 ) {
$( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) );
}
// Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php.
$.post(
ajaxurl,
data,
function( response ) {
if ( response ) {
if ( $( '#rtt-settings_updated' ).length > 0 ) {
$( '#rtt-settings_updated p' ).text( response );
$( '#rtt-settings_updated' ).show();
}
// $( '#rtmedia-transcoding-usage' ).hide();
$( '#disable-transcoding' ).next( 'img' ).remove();
$( '#disable-transcoding' ).hide();
$( '#enable-transcoding' ).css( 'display', 'inline' );
}
}
);
}
}
);
$( document ).on(
'click',
'#enable-transcoding',
function( e ) {
e.preventDefault();
if ( confirm( rt_transcoder_script.enable_encoding ) ) {
var data = {
action: 'rt_enable_transcoding',
rt_transcoder_nonce: rt_transcoder_script.security_nonce_for_enabling_encoding
};
if ( $( this ).next( 'img' ).length === 0 ) {
$( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) );
}
$.post(
ajaxurl,
data,
function( response ) {
if ( response ) {
if ( $( '#rtt-settings_updated' ).length > 0 ) {
$( '#rtt-settings_updated p' ).text( response );
$( '#rtt-settings_updated' ).show();
}
$( '#enable-transcoding' ).next( 'img' ).remove();
$( '#enable-transcoding' ).hide();
$( '#disable-transcoding' ).css( 'display', 'inline' );
} else {
$( '#settings-error-transcoding-disabled' ).remove();
}
}
);
}
}
);
}
);
} )( jQuery );