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