-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-script.js
More file actions
365 lines (315 loc) · 14.4 KB
/
Copy pathadmin-script.js
File metadata and controls
365 lines (315 loc) · 14.4 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
jQuery(document).ready(function($) {
// Modern Top-Right Toast Notifications
function showToast(message, type) {
if ($('#webclyde-toast-container').length === 0) {
$('body').append('<div id="webclyde-toast-container"></div>');
}
var icon = 'ℹ️';
if (type === 'success') icon = '✅';
if (type === 'error') icon = '❌';
var toast = $('<div class="webclyde-toast ' + type + '"><span class="webclyde-toast-icon">' + icon + '</span><div>' + message + '</div></div>');
$('#webclyde-toast-container').append(toast);
// Slide out and remove toast after 4 seconds
setTimeout(function() {
toast.css('animation', 'webclyde-slide-out 0.3s ease-in forwards');
setTimeout(function() {
toast.remove();
}, 300);
}, 4000);
}
// Save settings via AJAX
$('#webclyde-settings-form').on('submit', function(e) {
e.preventDefault();
var btn = $(this).find('button[type="submit"]');
var originalHtml = btn.html();
btn.html('<span class="dashicons dashicons-update spin" style="margin-top:3px;"></span> Saving...').prop('disabled', true);
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_save_settings',
nonce: webclydeContentVault.nonce,
data: $(this).serialize()
}, function(response) {
btn.html(originalHtml).prop('disabled', false);
if (response.success) {
showToast('Settings saved successfully!', 'success');
} else {
showToast(response.data || 'Error saving settings', 'error');
}
}).fail(function() {
btn.html(originalHtml).prop('disabled', false);
showToast('Request failed. Please try again.', 'error');
});
});
// Test API Connection
$('#webclyde-test-connection').on('click', function() {
var btn = $(this);
var originalHtml = btn.html();
btn.html('<span class="dashicons dashicons-update spin" style="margin-top:3px;"></span> Testing...').prop('disabled', true);
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_test_connection',
nonce: webclydeContentVault.nonce
}, function(response) {
btn.html(originalHtml).prop('disabled', false);
if (response.success) {
showToast('API connection successful!', 'success');
} else {
showToast(response.data || 'Connection failed', 'error');
}
}).fail(function() {
btn.html(originalHtml).prop('disabled', false);
showToast('API request failed.', 'error');
});
});
// Check Status of a Job
$(document).on('click', '.webclyde-check-status', function() {
var btn = $(this);
var jobId = btn.data('job-id');
var originalHtml = btn.html();
btn.html('<span class="dashicons dashicons-update spin" style="margin-top:3px;"></span> Check').prop('disabled', true);
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_check_status',
nonce: webclydeContentVault.nonce,
job_id: jobId
}, function(response) {
if (response.success) {
location.reload();
} else {
btn.html(originalHtml).prop('disabled', false);
showToast(response.data || 'Error checking status', 'error');
}
}).fail(function() {
btn.html(originalHtml).prop('disabled', false);
showToast('Request failed.', 'error');
});
});
// Check Link Health
$(document).on('click', '.webclyde-check-health', function() {
var btn = $(this);
var logId = btn.data('log-id');
var originalHtml = btn.html();
btn.html('<span class="dashicons dashicons-update spin" style="margin-top:3px;"></span> Health').prop('disabled', true);
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_check_health',
nonce: webclydeContentVault.nonce,
log_id: logId
}, function(response) {
if (response.success) {
location.reload();
} else {
btn.html(originalHtml).prop('disabled', false);
showToast(response.data || 'Error checking health', 'error');
}
}).fail(function() {
btn.html(originalHtml).prop('disabled', false);
showToast('Request failed.', 'error');
});
});
// Retry Archiving for a failed log
$(document).on('click', '.webclyde-retry', function() {
var btn = $(this);
var logId = btn.data('log-id');
btn.prop('disabled', true);
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_retry_archive',
nonce: webclydeContentVault.nonce,
log_id: logId
}, function(response) {
if (response.success) {
location.reload();
} else {
btn.prop('disabled', false);
showToast(response.data || 'Error retrying archive', 'error');
}
}).fail(function() {
btn.prop('disabled', false);
showToast('Request failed.', 'error');
});
});
// Delete Log
$(document).on('click', '.webclyde-delete', function() {
if (!confirm(webclydeContentVault.strings.confirm_delete)) return;
var btn = $(this);
var logId = btn.data('log-id');
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_delete_log',
nonce: webclydeContentVault.nonce,
log_id: logId
}, function(response) {
if (response.success) {
btn.closest('tr').fadeOut(function() { $(this).remove(); });
showToast('Log deleted successfully', 'success');
} else {
showToast(response.data || 'Error deleting log', 'error');
}
});
});
// Bulk Delete Logs
$('#webclyde-bulk-delete').on('click', function() {
var ids = [];
$('.webclyde-log-checkbox:checked').each(function() {
ids.push($(this).val());
});
if (ids.length === 0) {
showToast('Please select logs to delete', 'error');
return;
}
if (!confirm(webclydeContentVault.strings.confirm_bulk_delete)) return;
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_bulk_delete',
nonce: webclydeContentVault.nonce,
ids: ids
}, function(response) {
if (response.success) {
location.reload();
} else {
showToast(response.data || 'Error deleting logs', 'error');
}
});
});
// Select all logs in list table
$('#webclyde-select-all').on('change', function() {
$('.webclyde-log-checkbox').prop('checked', $(this).is(':checked'));
});
// Select all post types in settings
$(document).on('change', '#webclyde-select-all-post-types', function() {
$('.webclyde-post-type-checkbox').prop('checked', $(this).is(':checked'));
});
// Unified Click Handler for "Archive Now / Archive Again" button
$(document).on('click', '#webclyde-archive-now-btn, .webclyde-archive-now-inline, #webclyde-gutenberg-archive-btn, #webclyde-classic-archive-btn', function(e) {
e.preventDefault();
var btn = $(this);
var postId = btn.data('post-id');
var originalHtml = btn.html();
btn.prop('disabled', true).html('<span class="dashicons dashicons-update spin" style="font-size: 16px; width: 16px; height: 16px;"></span> Archiving...');
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_archive_now',
nonce: webclydeContentVault.nonce,
post_id: postId
}, function(response) {
if (response.success) {
btn.html('✓ Success!');
showToast('Archive job created successfully! Checking status...', 'success');
setTimeout(function() {
location.reload();
}, 1500);
} else {
btn.prop('disabled', false).html(originalHtml);
showToast(response.data || 'Failed to trigger archive.', 'error');
}
}).fail(function() {
btn.prop('disabled', false).html(originalHtml);
showToast('Request failed. Please check connection.', 'error');
});
});
// Delete a single local version snapshot
$(document).on('click', '.webclyde-delete-version', function() {
if (!confirm(webclydeContentVault.strings.confirm_delete)) return;
var btn = $(this);
var versionId = btn.data('version-id');
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_delete_version',
nonce: webclydeContentVault.nonce,
version_id: versionId
}, function(response) {
if (response.success) {
btn.closest('tr').fadeOut(function() { $(this).remove(); });
showToast('Version deleted', 'success');
} else {
showToast(response.data || 'Error deleting version', 'error');
}
});
});
// Select all version checkboxes
$('#webclyde-versions-select-all').on('change', function() {
$('.webclyde-version-checkbox').prop('checked', $(this).is(':checked'));
});
// Bulk delete local version snapshots
$('#webclyde-bulk-delete-versions').on('click', function() {
var ids = [];
$('.webclyde-version-checkbox:checked').each(function() {
ids.push($(this).val());
});
if (ids.length === 0) {
showToast('Please select versions to delete', 'error');
return;
}
if (!confirm(webclydeContentVault.strings.confirm_bulk_delete)) return;
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_bulk_delete_versions',
nonce: webclydeContentVault.nonce,
ids: ids
}, function(response) {
if (response.success) {
location.reload();
} else {
showToast(response.data || 'Error deleting versions', 'error');
}
});
});
// Bulk Archive All Published Content
$('#webclyde-bulk-archive-all').on('click', function() {
var btn = $(this);
var result = $('#webclyde-bulk-archive-result');
var originalHtml = btn.html();
if (!confirm('This will queue ALL published posts for archiving to the Wayback Machine. Continue?')) {
return;
}
btn.prop('disabled', true).html('<span class="dashicons dashicons-update spin" style="margin-top:3px;"></span> Queuing...');
result.hide();
$.post(webclydeContentVault.ajaxurl, {
action: 'webclyde_bulk_archive_all',
nonce: webclydeContentVault.nonce
}, function(response) {
btn.prop('disabled', false).html(originalHtml);
if (response.success) {
result.text(response.data.message).css('color', '#10b981').show();
showToast(response.data.message, 'success');
} else {
result.text(response.data || 'Error queuing archives.').css('color', '#ef4444').show();
showToast(response.data || 'Error queuing archives.', 'error');
}
}).fail(function() {
btn.prop('disabled', false).html(originalHtml);
showToast('Request failed. Please try again.', 'error');
});
});
// Gutenberg Editor Header Button Injection
function injectGutenbergHeaderButton() {
var editorEl = $('#editor');
if (editorEl.length === 0) return;
// Prevent duplicate injection
if ($('#webclyde-gutenberg-archive-btn').length > 0) return;
// Locate the top-right header toolbar in Gutenberg
var settingsToolbar = $('.edit-post-header__settings');
if (settingsToolbar.length > 0) {
// Get current Post ID securely
var postId = $('#post_ID').val();
if (!postId && wp.data && wp.data.select('core/editor')) {
postId = wp.data.select('core/editor').getCurrentPostId();
}
if (!postId) return;
var btnHtml = '<button type="button" id="webclyde-gutenberg-archive-btn" class="components-button is-secondary" data-post-id="' + postId + '" style="margin-right: 12px; border: 1.5px solid #667eea; color: #667eea; background: transparent; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; border-radius: 4px; height: 32px; padding: 0 12px; cursor: pointer;">';
btnHtml += '<span class="dashicons dashicons-backup" style="font-size: 16px; width: 16px; height: 16px; margin-top: -2px;"></span> Archive Now';
btnHtml += '</button>';
// Insert button directly in the editor header toolbar
settingsToolbar.prepend(btnHtml);
}
}
// Classic Editor Publish Box Button Injection
function injectClassicEditorButton() {
if ($('#major-publishing-actions').length === 0) return;
if ($('#webclyde-classic-archive-btn').length > 0) return;
var postId = $('#post_ID').val();
if (!postId) return;
var btnHtml = '<div id="webclyde-classic-archive-btn-container" style="float:left; margin-top: 4px; margin-right: 8px;">';
btnHtml += '<button type="button" id="webclyde-classic-archive-btn" class="button button-large" data-post-id="' + postId + '" style="border-color: #667eea; color: #667eea; font-weight: 600; display: inline-flex; align-items: center; gap: 4px;">';
btnHtml += '<span class="dashicons dashicons-backup" style="font-size: 16px; width: 16px; height: 16px; margin-top: 2px;"></span> Archive Now';
btnHtml += '</button>';
btnHtml += '</div>';
$('#major-publishing-actions').prepend(btnHtml);
}
// Run observer loops to support real-time header rendering in both Classic and Block (Gutenberg) Editors
setInterval(function() {
injectGutenbergHeaderButton();
injectClassicEditorButton();
}, 1000);
});