PluginProbe
Stream – Activity Log & Audit Trail / 2.0.5
Stream – Activity Log & Audit Trail v2.0.5
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
stream / ui / js / migrate.js

migrate.js in Stream – Activity Log & Audit Trail 2.0.5, at ui/js/migrate.js

120 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* globals wp_stream_migrate, ajaxurl */
2 jQuery( function( $ ) {
3
4 var chunk_size = parseInt( wp_stream_migrate.chunk_size, 10 ),
5 record_count = parseInt( wp_stream_migrate.record_count, 10 ),
6 progress_step = ( chunk_size < record_count ) ? ( chunk_size / record_count ) * 100 : 100,
7 progress_val = 0;
8
9 $( document ).on( 'click', '#stream-start-migrate', function( e ) {
10 if ( ! window.confirm( wp_stream_migrate.i18n.confirm_start_migrate ) ) {
11 e.preventDefault();
12 } else {
13 stream_migrate_action( 'migrate' );
14 }
15 });
16
17 $( document ).on( 'click', '#stream-resume-migrate', function( e ) {
18 e.preventDefault();
19 stream_migrate_action( 'migrate' );
20 });
21
22 $( document ).on( 'click', '#stream-migrate-reminder', function( e ) {
23 if ( ! window.confirm( wp_stream_migrate.i18n.confirm_migrate_reminder ) ) {
24 e.preventDefault();
25 } else {
26 stream_migrate_action( 'delay' );
27 }
28 });
29
30 $( document ).on( 'click', '#stream-delete-records', function( e ) {
31 if ( ! window.confirm( wp_stream_migrate.i18n.confirm_delete_records ) ) {
32 e.preventDefault();
33 } else {
34 stream_migrate_action( 'delete' );
35 }
36 });
37
38 $( document ).on( 'click', '#stream-migrate-actions-close', function() {
39 location.reload( true );
40 });
41
42 function stream_migrate_action( migrate_action ) {
43 var data = {
44 'action': 'wp_stream_migrate_action',
45 'migrate_action': migrate_action,
46 'nonce': wp_stream_migrate.nonce
47 };
48
49 $.ajax({
50 type: 'POST',
51 url: ajaxurl,
52 data: data,
53 dataType: 'json',
54 beforeSend: function() {
55 stream_migrate_start( migrate_action );
56 },
57 success: function( response ) {
58 if ( false === response.success ) {
59 stream_migrate_end( response.data, true );
60 } else {
61 if ( 'migrate' === response.data || 'delete' === response.data ) {
62 stream_migrate_progress_loop( response.data );
63 } else {
64 stream_migrate_end( response.data );
65 }
66 }
67 },
68 error: function() {
69 stream_migrate_end( wp_stream_migrate.i18n.error_message, true );
70 }
71 });
72 }
73
74 function stream_migrate_progress_loop( migrate_action ) {
75 progress_val = ( ( progress_step + progress_val ) < 100 ) ? progress_step + progress_val : 100;
76
77 $( '#stream-migrate-progress progress' ).val( progress_val );
78 $( '#stream-migrate-progress strong' ).text( Math.round( progress_val ) + '%' );
79
80 stream_migrate_action( migrate_action );
81 }
82
83 function stream_migrate_start( migrate_action ) {
84 $( '#stream-migrate-actions' ).hide();
85 $( '#stream-migrate-progress' ).show();
86
87 if ( 'migrate' === migrate_action ) {
88 $( '#stream-migrate-title' ).text( wp_stream_migrate.i18n.migrate_process_title );
89 $( '#stream-migrate-message' ).text( wp_stream_migrate.i18n.migrate_process_message );
90 }
91
92 if ( 'delete' === migrate_action ) {
93 $( '#stream-migrate-title' ).text( wp_stream_migrate.i18n.delete_process_title );
94 $( '#stream-migrate-message' ).text( wp_stream_migrate.i18n.delete_process_message );
95 }
96
97 if ( 'delay' !== migrate_action ) {
98 $( '#stream-migrate-progress strong' ).show();
99 }
100 }
101
102 function stream_migrate_end( message, is_error ) {
103 is_error = 'undefined' !== typeof is_error ? is_error : false;
104
105 $( '#stream-migrate-message' ).hide();
106 $( '#stream-migrate-progress progress' ).hide();
107 $( '#stream-migrate-progress strong' ).hide();
108 $( '#stream-migrate-actions-close' ).show();
109
110 if ( message ) {
111 $( '#stream-migrate-progress em' ).html( message );
112
113 if ( is_error ) {
114 $( '#stream-migrate-progress em' ).css( 'color', '#a00' );
115 }
116 }
117 }
118
119 });
120