1
|
|
|
/** |
2
|
|
|
* JavaScript for Bulk Delete Plugin |
3
|
|
|
* |
4
|
|
|
* http://bulkwp.com |
5
|
|
|
* |
6
|
|
|
* @author: Sudar <http://sudarmuthu.com> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/*global BulkWP, postboxes, pagenow*/ |
10
|
|
|
jQuery(document).ready(function () { |
11
|
|
|
/** |
12
|
|
|
* Enable select2 |
13
|
|
|
*/ |
14
|
|
|
jQuery( '.select2' ).select2(); |
15
|
|
|
|
16
|
|
|
// Start Jetpack. |
17
|
|
|
BulkWP.jetpack(); |
18
|
|
|
|
19
|
|
|
jQuery( '.user_restrict_to_no_posts_filter' ).change( function() { |
20
|
|
|
var $this = jQuery(this), |
21
|
|
|
filterEnabled = $this.is( ':checked' ), |
22
|
|
|
$filterItems = $this.parents( 'table' ).children().find( '.user_restrict_to_no_posts_filter_items' ); |
23
|
|
|
|
24
|
|
|
if ( filterEnabled ) { |
25
|
|
|
$filterItems.removeClass( 'visually-hidden' ); |
26
|
|
|
} else { |
27
|
|
|
$filterItems.addClass( 'visually-hidden' ); |
28
|
|
|
} |
29
|
|
|
} ); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Enable Postbox handling |
33
|
|
|
*/ |
34
|
|
|
postboxes.add_postbox_toggles(pagenow); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Toggle the date restrict fields |
38
|
|
|
*/ |
39
|
|
|
function toggle_date_restrict(el) { |
40
|
|
|
if (jQuery("#smbd" + el + "_restrict").is(":checked")) { |
41
|
|
|
jQuery("#smbd" + el + "_op").removeAttr('disabled'); |
42
|
|
|
jQuery("#smbd" + el + "_days").removeAttr('disabled'); |
43
|
|
|
} else { |
44
|
|
|
jQuery("#smbd" + el + "_op").attr('disabled', 'true'); |
45
|
|
|
jQuery("#smbd" + el + "_days").attr('disabled', 'true'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Toggle limit restrict fields |
51
|
|
|
*/ |
52
|
|
|
function toggle_limit_restrict(el) { |
53
|
|
|
if (jQuery("#smbd" + el + "_limit").is(":checked")) { |
54
|
|
|
jQuery("#smbd" + el + "_limit_to").removeAttr('disabled'); |
55
|
|
|
} else { |
56
|
|
|
jQuery("#smbd" + el + "_limit_to").attr('disabled', 'true'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Toggle user login restrict fields |
62
|
|
|
*/ |
63
|
|
|
function toggle_login_restrict(el) { |
64
|
|
|
if (jQuery("#smbd" + el + "_login_restrict").is(":checked")) { |
65
|
|
|
jQuery("#smbd" + el + "_login_days").removeAttr('disabled'); |
66
|
|
|
} else { |
67
|
|
|
jQuery("#smbd" + el + "_login_days").attr('disabled', 'true'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Toggle user registered restrict fields |
73
|
|
|
*/ |
74
|
|
|
function toggle_registered_restrict(el) { |
75
|
|
|
if (jQuery("#smbd" + el + "_registered_restrict").is(":checked")) { |
76
|
|
|
jQuery("#smbd" + el + "_registered_days").removeAttr('disabled'); |
77
|
|
|
} else { |
78
|
|
|
jQuery("#smbd" + el + "_registered_days").attr('disabled', 'true'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Toggle Post type dropdown. |
84
|
|
|
*/ |
85
|
|
|
function toggle_post_type_dropdown( el ) { |
86
|
|
|
// TODO: Check why the element is not toggling even when display:none is added by JS. |
87
|
|
|
if ( jQuery( "#smbd" + el + "_no_posts" ).is( ":checked" ) ) { |
88
|
|
|
jQuery( "tr#smbd" + el + "-post-type-dropdown" ).show(); |
89
|
|
|
} else { |
90
|
|
|
jQuery( "tr#smbd" + el + "-post-type-dropdown" ).hide(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// hide all terms |
95
|
|
|
function hideAllTerms() { |
96
|
|
|
jQuery('table.terms').hide(); |
97
|
|
|
jQuery('input.terms').attr('checked', false); |
98
|
|
|
} |
99
|
|
|
// call it for the first time |
100
|
|
|
hideAllTerms(); |
101
|
|
|
|
102
|
|
|
// taxonomy click handling |
103
|
|
|
jQuery('.custom-tax').change(function () { |
104
|
|
|
var $this = jQuery(this), |
105
|
|
|
$tax = $this.val(), |
106
|
|
|
$terms = jQuery('table.terms_' + $tax); |
107
|
|
|
|
108
|
|
|
if ($this.is(':checked')) { |
109
|
|
|
hideAllTerms(); |
110
|
|
|
$terms.show('slow'); |
111
|
|
|
} |
112
|
|
|
}); |
113
|
|
|
|
114
|
|
|
// date time picker |
115
|
|
|
jQuery.each(BulkWP.dt_iterators, function (index, value) { |
116
|
|
|
// invoke the date time picker |
117
|
|
|
jQuery('#smbd' + value + '_cron_start').datetimepicker({ |
118
|
|
|
timeFormat: 'HH:mm:ss' |
119
|
|
|
}); |
120
|
|
|
|
121
|
|
|
jQuery('#smbd' + value + '_restrict').change(function () { |
122
|
|
|
toggle_date_restrict(value); |
123
|
|
|
}); |
124
|
|
|
|
125
|
|
|
jQuery('#smbd' + value + '_limit').change(function () { |
126
|
|
|
toggle_limit_restrict(value); |
127
|
|
|
}); |
128
|
|
|
|
129
|
|
|
jQuery('#smbd' + value + '_login_restrict').change(function () { |
130
|
|
|
toggle_login_restrict(value); |
131
|
|
|
}); |
132
|
|
|
|
133
|
|
|
jQuery('#smbd' + value + '_registered_restrict').change(function () { |
134
|
|
|
toggle_registered_restrict(value); |
135
|
|
|
}); |
136
|
|
|
|
137
|
|
|
jQuery( '#smbd' + value + '_no_posts' ).change( function () { |
138
|
|
|
toggle_post_type_dropdown( value ); |
139
|
|
|
}); |
140
|
|
|
}); |
141
|
|
|
|
142
|
|
|
jQuery.each( BulkWP.pro_iterators, function ( index, value) { |
143
|
|
|
jQuery('.bd-' + value.replace( '_', '-' ) + '-pro').hide(); |
144
|
|
|
jQuery('#smbd_' + value + '_cron_freq, #smbd_' + value + '_cron_start, #smbd_' + value + '_cron').removeAttr('disabled'); |
145
|
|
|
} ); |
146
|
|
|
|
147
|
|
|
// Validate user action |
148
|
|
|
jQuery('button[name="bd_action"]').click(function () { |
149
|
|
|
var currentButton = jQuery(this).val(), |
150
|
|
|
valid = false, |
151
|
|
|
msg_key = "deletePostsWarning", |
152
|
|
|
error_key = "selectPostOption"; |
153
|
|
|
|
154
|
|
|
if (currentButton in BulkWP.validators) { |
155
|
|
|
valid = BulkWP[BulkWP.validators[currentButton]](this); |
156
|
|
|
} else { |
157
|
|
|
if (jQuery(this).parent().prev().children('table').find(":checkbox:checked[value!='true']").size() > 0) { // monstrous selector |
158
|
|
|
valid = true; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if (valid) { |
163
|
|
|
if (currentButton in BulkWP.pre_action_msg) { |
164
|
|
|
msg_key = BulkWP.pre_action_msg[currentButton]; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return confirm(BulkWP.msg[msg_key]); |
168
|
|
|
} else { |
169
|
|
|
if (currentButton in BulkWP.error_msg) { |
170
|
|
|
error_key = BulkWP.error_msg[currentButton]; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
alert(BulkWP.msg[error_key]); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
return false; |
177
|
|
|
}); |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Validation functions |
181
|
|
|
*/ |
182
|
|
|
BulkWP.noValidation = function() { |
183
|
|
|
return true; |
184
|
|
|
}; |
185
|
|
|
|
186
|
|
|
BulkWP.validateSelect2 = function(that) { |
187
|
|
|
if (null !== jQuery(that).parent().prev().children().find(".select2[multiple]").val()) { |
188
|
|
|
return true; |
189
|
|
|
} else { |
190
|
|
|
return false; |
191
|
|
|
} |
192
|
|
|
}; |
193
|
|
|
|
194
|
|
|
BulkWP.validateUrl = function(that) { |
195
|
|
|
if (jQuery(that).parent().prev().children('table').find("textarea").val() !== '') { |
196
|
|
|
return true; |
197
|
|
|
} else { |
198
|
|
|
return false; |
199
|
|
|
} |
200
|
|
|
}; |
201
|
|
|
|
202
|
|
|
BulkWP.validateUserMeta = function() { |
203
|
|
|
if (jQuery('#smbd_u_meta_value').val() !== '') { |
204
|
|
|
return true; |
205
|
|
|
} else { |
206
|
|
|
return false; |
207
|
|
|
} |
208
|
|
|
}; |
209
|
|
|
}); |
210
|
|
|
|
211
|
|
|
BulkWP.jetpack = function() { |
212
|
|
|
jQuery('.bd-feedback-pro').hide(); |
213
|
|
|
|
214
|
|
|
jQuery('#smbd_feedback_cron_freq, #smbd_feedback_cron_start, #smbd_feedback_cron').removeAttr('disabled'); |
215
|
|
|
jQuery('#smbd_feedback_use_filter').removeAttr('disabled'); |
216
|
|
|
|
217
|
|
|
// enable filters |
218
|
|
|
jQuery('input[name="smbd_feedback_use_filter"]').change(function() { |
219
|
|
|
if('true' === jQuery(this).val()) { |
220
|
|
|
// using filters |
221
|
|
|
jQuery('#jetpack-filters').show(); |
222
|
|
|
} else { |
223
|
|
|
jQuery('#jetpack-filters').hide(); |
224
|
|
|
} |
225
|
|
|
}); |
226
|
|
|
|
227
|
|
|
// enable individual filters |
228
|
|
|
jQuery.each(['name', 'email', 'ip'], function (index, value) { |
229
|
|
|
jQuery('#smbd_feedback_author_' + value + '_filter').change(function() { |
230
|
|
|
if(jQuery(this).is(':checked')) { |
231
|
|
|
jQuery('#smbd_feedback_author_' + value + '_op').removeAttr('disabled'); |
232
|
|
|
jQuery('#smbd_feedback_author_' + value + '_value').removeAttr('disabled'); |
233
|
|
|
} else { |
234
|
|
|
jQuery('#smbd_feedback_author_' + value + '_op').attr('disabled', 'true'); |
235
|
|
|
jQuery('#smbd_feedback_author_' + value + '_value').attr('disabled', 'true'); |
236
|
|
|
} |
237
|
|
|
}); |
238
|
|
|
}); |
239
|
|
|
}; |
240
|
|
|
|