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