PluginProbe
Contact Forms by Cimatti / trunk
Contact Forms by Cimatti vtrunk
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / assets / js / admin / single-submission.js

single-submission.js in Contact Forms by Cimatti trunk, at assets/js/admin/single-submission.js

110 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Single submission page - anonymize + notes handlers.
3 *
4 * @package ContactForms
5 * @since 2.2.5
6 */
7 /* global jQuery, ajaxurl, accuaSingleSubmission */
8 jQuery( function( $ ) {
9 var l10n = ( accuaSingleSubmission || {} ).l10n || {};
10
11 // Anonymize button
12 $( '#accua-forms-anonymize-btn' ).on( 'click', function( e ) {
13 e.preventDefault();
14 var btn = $( this );
15 if ( btn.data( 'processing' ) ) return;
16
17 if ( ! window.confirm( l10n.confirmAnonymize || '' ) ) {
18 return;
19 }
20
21 btn.data( 'processing', true ).text( l10n.anonymizing || '' );
22
23 $.ajax( {
24 url: ajaxurl,
25 type: 'POST',
26 data: {
27 action: 'accua-forms-anonymize-submission',
28 subid: btn.data( 'subid' ),
29 _nonce_anonymize: btn.data( 'nonce' )
30 },
31 success: function() {
32 window.location.reload();
33 },
34 error: function() {
35 btn.data( 'processing', false ).text( l10n.anonymize || '' );
36 window.alert( l10n.errorAnonymize || '' );
37 }
38 } );
39 } );
40
41 // Add note
42 $( '#accua-add-note-btn' ).on( 'click', function() {
43 var btn = $( this );
44 var textarea = $( '#note_site_user' );
45 var text = textarea.val().trim();
46 if ( ! text || btn.prop( 'disabled' ) ) return;
47
48 btn.prop( 'disabled', true );
49
50 $.ajax( {
51 url: ajaxurl,
52 type: 'POST',
53 data: {
54 action: 'accua-forms-add-note',
55 subid: btn.data( 'subid' ),
56 text: text,
57 _nonce: btn.data( 'nonce' )
58 },
59 success: function( response ) {
60 btn.prop( 'disabled', false );
61 if ( response.success ) {
62 textarea.val( '' );
63 var note = '<div class="accua-note">' +
64 '<div class="accua-note-content">' + $( '<span>' ).text( text ).html() + '</div>' +
65 '<p class="accua-note-meta">' + $( '<span>' ).text( response.data.date ).html() + '<br>' + $( '<span>' ).text( response.data.user ).html() +
66 ' <span class="row-actions"><button type="button" class="button-link accua-delete-note" data-subid="' + btn.data( 'subid' ) + '" data-date="' + response.data.date + '" data-nonce="' + response.data.del_nonce + '">' + $( '<span>' ).text( l10n.deleteNote || 'Delete' ).html() + '</button></span>' +
67 '</p></div>';
68 $( '#accua-notes-list' ).prepend( note );
69 } else {
70 window.alert( l10n.errorNote || '' );
71 }
72 },
73 error: function() {
74 btn.prop( 'disabled', false );
75 window.alert( l10n.errorNote || '' );
76 }
77 } );
78 } );
79
80 // Delete note
81 $( '#accua-notes-list' ).on( 'click', '.accua-delete-note', function() {
82 var btn = $( this );
83 if ( ! window.confirm( l10n.confirmDeleteNote || '' ) ) return;
84
85 var noteDiv = btn.closest( '.accua-note' );
86 noteDiv.css( 'opacity', '0.5' );
87
88 $.ajax( {
89 url: ajaxurl,
90 type: 'POST',
91 data: {
92 action: 'accua-forms-delete-note',
93 subid: btn.data( 'subid' ),
94 date: btn.data( 'date' ),
95 _nonce: btn.data( 'nonce' )
96 },
97 success: function( response ) {
98 if ( response.success ) {
99 noteDiv.remove();
100 } else {
101 noteDiv.css( 'opacity', '' );
102 }
103 },
104 error: function() {
105 noteDiv.css( 'opacity', '' );
106 }
107 } );
108 } );
109 } );
110