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.7 0.2 0.2.1 0.2.2 0.2.3
cf7-conditional-fields / js / scripts_admin.js
cf7-conditional-fields / js Last commit date
scripts.js 7 years ago scripts_admin.js 7 years ago
scripts_admin.js
342 lines
1 /**
2 * Created by jules on 7/17/2015.
3 */
4 var $wpcf7cf_new_entry = jQuery('#wpcf7cf-new-entry').eq(0);
5
6 if ($wpcf7cf_new_entry.length > 0) {
7
8 var wpcf7cf_new_and_rule_html = $wpcf7cf_new_entry.find('.wpcf7cf-and-rule')[0].outerHTML;
9 var wpcf7cf_new_entry_html = $wpcf7cf_new_entry.html();
10
11 var regex = /show \[(.*)\] if \[(.*)\] (equals|not equals|equals \(regex\)|not equals \(regex\)|>|>=|<=|<|is empty|not empty) "(.*)"/g;
12 var regex_and = /and if \[(.*)\] (equals|not equals|equals \(regex\)|not equals \(regex\)|>|>=|<=|<|is empty|not empty) "(.*)"/g;
13
14
15 if (_wpcf7 == null) { var _wpcf7 = wpcf7}; // wpcf7 4.8 fix
16
17 var old_compose = _wpcf7.taggen.compose;
18
19 var regexes = [
20 { label: wpcf7cf_options_0.regex_email_label, desc: wpcf7cf_options_0.regex_email },
21 { label: wpcf7cf_options_0.regex_numeric_label, desc: wpcf7cf_options_0.regex_numeric },
22 { label: wpcf7cf_options_0.regex_alphanumeric_label, desc: wpcf7cf_options_0.regex_alphanumeric },
23 { label: wpcf7cf_options_0.regex_alphabetic_label, desc: wpcf7cf_options_0.regex_alphabetic },
24 { label: wpcf7cf_options_0.regex_date_label, desc: wpcf7cf_options_0.regex_date },
25 { label: wpcf7cf_options_0.regex_custom_1_label, desc: wpcf7cf_options_0.regex_custom_1 },
26 { label: wpcf7cf_options_0.regex_custom_2_label, desc: wpcf7cf_options_0.regex_custom_2 },
27 { label: wpcf7cf_options_0.regex_custom_3_label, desc: wpcf7cf_options_0.regex_custom_3 },
28 { label: wpcf7cf_options_0.regex_custom_4_label, desc: wpcf7cf_options_0.regex_custom_4 },
29 { label: wpcf7cf_options_0.regex_custom_5_label, desc: wpcf7cf_options_0.regex_custom_5 },
30 ];
31
32 var i = regexes.length;
33 while (i--) {
34 if (null == regexes[i].label || null == regexes[i].desc || regexes[i].label == '' || regexes[i].desc == '') {
35 regexes.splice(i,1);
36 }
37 }
38
39 var termTemplate = "<span class='ui-autocomplete-term'>%s</span>";
40
41 (function($) {
42
43 $('#wpcf7cf-entries').sortable();
44 $(('.wpcf7cf-and-rules')).sortable();
45
46
47 // ...before overwriting the jQuery extension point
48 _wpcf7.taggen.compose = function(tagType, $form)
49 {
50
51 $('#tag-generator-panel-group-style-hidden').val($('#tag-generator-panel-group-style').val());
52
53 // original behavior - use function.apply to preserve context
54 var ret = old_compose.apply(this, arguments);
55 //tagType = arguments[0];
56 //$form = arguments[1];
57
58 // START: code here will be executed after the _wpcf7.taggen.update function
59 if (tagType== 'group') ret += "[/group]";
60 if (tagType== 'repeater') ret += "[/repeater]";
61
62 // END
63
64 if (tagType== 'togglebutton') {
65 $val1 = $('#tag-generator-panel-togglebutton-value-1');
66 $val2 = $('#tag-generator-panel-togglebutton-value-2');
67 var val1 = $val1.val();
68 var val2 = $val2.val();
69
70 if (val1 == "") val1 = $val1.data('default');
71 if (val2 == "") val2 = $val2.data('default');
72
73 str_val = ' "'+val1+'" "'+val2+'"';
74
75 ret = ret.replace(']', str_val+']');
76 }
77
78 return ret;
79 };
80
81 var index = $('#wpcf7cf-entries .entry').length;
82 var index_and = 0;
83
84 $('#wpcf7cf-add-button').click(function(){
85
86 var id = add_condition_fields();
87
88 return false;
89
90 });
91
92 function clear_all_condition_fields() {
93 $('.entry').remove();
94 }
95
96 function add_condition_fields() {
97 $('<div class="entry" id="entry-'+index+'">'+(wpcf7cf_new_entry_html.replace(/{id}/g, index))+'</div>').appendTo('#wpcf7cf-entries');
98 index++;
99 update_entries();
100 return (index-1);
101 }
102
103 function add_and_condition_fields(id) {
104 // $('#entry-'+id+' .wpcf7cf-and-rules').eq(0).append($wpcf7cf_new_and_rule.clone());
105 $('#entry-'+id+' .wpcf7cf-and-rules').eq(0).append(wpcf7cf_new_and_rule_html.replace(/{id}/g, index-1).replace(/\[and_rules\]\[0\]/g, '[and_rules]['+index_and+']'));
106 index_and++;
107 return (index_and-1);
108 }
109
110 function import_condition_fields() {
111
112 $if_values = $('.if-value');
113
114 var lines = $('#wpcf7cf-settings-text').val().split(/\r?\n/);
115
116 var id = -1;
117
118 for (var i = 0; i<lines.length; i++) {
119
120 var str = lines[i];
121
122 var match = regex.exec(str);
123
124 if (match != null) {
125
126 index_and = 0; // reset this for each first condition (This one has and_index [0]).
127
128 id = add_condition_fields();
129
130 $('#entry-'+id+' .then-field-select').val(match[1]);
131 $('#entry-'+id+' .if-field-select').val(match[2]);
132 $('#entry-'+id+' .operator').val(match[3]);
133 $('#entry-'+id+' .if-value').val(match[4]);
134
135 index_and = 1; // the next and condition will gave and_index[1];
136
137 regex.lastIndex = 0;
138
139 }
140
141 match = regex_and.exec(str);
142
143 if (match != null && id != -1) {
144
145 var and_id = add_and_condition_fields(id);
146
147 $('#entry-'+id+' .wpcf7cf-and-rule:last-child .if-field-select').val(match[1]);
148 $('#entry-'+id+' .wpcf7cf-and-rule:last-child .operator').val(match[2]);
149 $('#entry-'+id+' .wpcf7cf-and-rule:last-child .if-value').val(match[3]);
150
151 regex_and.lastIndex = 0;
152
153 }
154 }
155 }
156
157 // export/import settings
158
159 $('#wpcf7cf-settings-text-wrap').hide();
160
161 $('#wpcf7cf-settings-to-text').click(function() {
162 $('#wpcf7cf-settings-text-wrap').show();
163
164 $('#wpcf7cf-settings-text').val('');
165 $('#wpcf7cf-entries .entry').each(function() {
166 var $entry = $(this);
167 var line = 'show [' + $entry.find('.then-field-select').val() + ']';
168 var text_indent = line.length-3;
169 $entry.find('.wpcf7cf-and-rule').each(function(i) {
170 $and_rule = $(this);
171 if (i>0) {
172
173 line += '\n'+' '.repeat(text_indent)+'and';
174
175 }
176 line += ' if [' + $and_rule.find('.if-field-select').val() + ']'
177 + ' ' + $and_rule.find('.operator').val()
178 + ' "' + $and_rule.find('.if-value').val() + '"';
179 });
180 $('#wpcf7cf-settings-text').val($('#wpcf7cf-settings-text').val() + line + "\n" ).select();
181 });
182 return false;
183 });
184
185 $if_values = $('.if-value');
186
187 $('#add-fields').click(function() {
188 import_condition_fields();
189 update_entries();
190 return false;
191 });
192
193 $('#overwrite-fields').click(function() {
194 clear_all_condition_fields();
195 import_condition_fields();
196 update_entries();
197 return false;
198 });
199
200 $('#wpcf7cf-settings-text-clear').click(function() {
201 $('#wpcf7cf-settings-text-wrap').hide();
202 $('#wpcf7cf-settings-text').val('');
203 return false;
204 });
205
206 function update_entries() {
207 $if_values = $('.if-value');
208 init_autocomplete();
209 $if_values.css({'visibility':'visible'});
210 $if_values.autocomplete( "disable" );
211
212 $('#wpcf7cf-entries .wpcf7cf-and-rule').each(function() {
213 var $and_rule = $(this);
214 if ($and_rule.find('.operator').eq(0).val() === 'is empty' || $and_rule.find('.operator').eq(0).val() === 'not empty') {
215 $and_rule.find('.if-value').eq(0).css({'visibility':'hidden'});
216 } else if ($and_rule.find('.operator').eq(0).val().endsWith('(regex)')) {
217 $and_rule.find('.if-value').eq(0).autocomplete( "enable" );
218 }
219 });
220
221 scale_and_button();
222
223 set_events();
224 }
225
226 function init_autocomplete() {
227
228 $if_values.autocomplete({
229 disabled: true,
230 source: function(request, response) {
231 var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
232 response($.grep(regexes, function(value) {
233 return matcher.test(value.label || value.value || value) || matcher.test(value.desc);
234 }));
235 },
236 focus: function( event, ui ) {
237 $( event.target ).val( ui.item.desc );
238 return false;
239 },
240 select: function( event, ui ) {
241 $( event.target ).val( ui.item.desc );
242 return false;
243 },
244 open: function(e,ui) {
245 $el = $(e.target);
246 var styledTerm = termTemplate.replace('%s', $el.val());
247
248 $('.ui-autocomplete').find('em').each(function() {
249 var me = $(this);
250 me.html( me.text().replace($el.val(), styledTerm) );
251 });
252 },
253 minLength: 0
254 }).each(function() {
255 $(this).autocomplete( "instance" )._renderItem = function( ul, item ) {
256 return $("<li>")
257 .append("<div><em>" + item.label + "</em><br><em>" + item.desc + "</em></div>")
258 .appendTo(ul);
259 }
260 });
261 $if_values.on('focus', function() {
262 $(this).autocomplete("search");
263 });
264 }
265
266 update_entries();
267
268 function set_events() { // called at the end of update_entries
269
270 $('.wpcf7cf-and-rules').sortable();
271
272 $('.and-button').off('click').click(function() {
273 $this = $(this);
274 $andblock = $this.closest('.wpcf7cf-and-rule');
275 $andblocks_container = $this.closest('.wpcf7cf-and-rules');
276 next_index = $andblocks_container.data('next-index');
277 $andblocks_container.data('next-index',next_index+1);
278 var and_i = next_index;
279 clone_html = $andblock.get(0).outerHTML.replace(/wpcf7cf_options\[([0-9]*)\]\[and_rules\]\[([0-9]*)\]/g, 'wpcf7cf_options[$1][and_rules]['+and_i+']');
280 $andblock.after(clone_html);
281 update_entries();
282 return false;
283 });
284
285 $('.delete-button').off('click').click(function(){
286 $and_rule = $(this).closest('.wpcf7cf-and-rule');
287 if ($and_rule.siblings().length > 0) {
288 $and_rule.remove();
289 } else {
290 $and_rule[0].closest('.entry').remove();
291 }
292
293 update_entries();
294
295 return false;
296 });
297
298 $('.operator').off('change').change(function() {
299 update_entries();
300 return false;
301 });
302 }
303
304 function scale_and_button() {
305 $('.wpcf7cf-and-rule:first-child .and-button').each(function(){
306 $and_button = $(this);
307 num_and_rules = $and_button.closest('.wpcf7cf-and-rule').siblings().length+1;
308 var height = (34*num_and_rules-12)+'px';
309 $and_button.css({'height':height,'line-height':height});
310 });
311 }
312
313 })( jQuery );
314
315 }
316
317 (function($) {
318 // ------------------------------------
319 // OPTIONS PAGE
320 // ------------------------------------
321
322 $(document).ready(function() {
323
324 $('.wpcf7cf-options-notice .notice-dismiss-2').click(function () {
325 $('.wpcf7cf-options-notice .notice-dismiss').click();
326 });
327 $('.wpcf7cf-options-notice .notice-dismiss').click(function () {
328 wpcf7cf_dismiss_notice();
329 });
330
331 function wpcf7cf_dismiss_notice() {
332 console.log(ajaxurl);
333
334 $('input[name="wpcf7cf_options[notice_dismissed]"]').val('true');
335
336 $.post(ajaxurl, {action:'wpcf7cf_dismiss_notice'}, function(response) {
337 // nothing to do. dismiss_notice option should be set to TRUE server side by now.
338 });
339 }
340
341 });
342 })( jQuery );