PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.28
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.28
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / assets / js / spa-app.js

spa-app.js in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.6.28, at assets/js/spa-app.js

2,031 lines 75.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 var _typeof34 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
5 var _typeof33 = typeof Symbol === "function" && _typeof34(Symbol.iterator) === "symbol" ? function (obj) {
6 return typeof obj === "undefined" ? "undefined" : _typeof34(obj);
7 } : function (obj) {
8 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof34(obj);
9 };
10
11 var _typeof32 = typeof Symbol === "function" && _typeof33(Symbol.iterator) === "symbol" ? function (obj) {
12 return typeof obj === "undefined" ? "undefined" : _typeof33(obj);
13 } : function (obj) {
14 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof33(obj);
15 };
16
17 var _typeof31 = typeof Symbol === "function" && _typeof32(Symbol.iterator) === "symbol" ? function (obj) {
18 return typeof obj === "undefined" ? "undefined" : _typeof32(obj);
19 } : function (obj) {
20 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof32(obj);
21 };
22
23 var _typeof30 = typeof Symbol === "function" && _typeof31(Symbol.iterator) === "symbol" ? function (obj) {
24 return typeof obj === "undefined" ? "undefined" : _typeof31(obj);
25 } : function (obj) {
26 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof31(obj);
27 };
28
29 var _typeof29 = typeof Symbol === "function" && _typeof30(Symbol.iterator) === "symbol" ? function (obj) {
30 return typeof obj === "undefined" ? "undefined" : _typeof30(obj);
31 } : function (obj) {
32 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof30(obj);
33 };
34
35 var _typeof28 = typeof Symbol === "function" && _typeof29(Symbol.iterator) === "symbol" ? function (obj) {
36 return typeof obj === "undefined" ? "undefined" : _typeof29(obj);
37 } : function (obj) {
38 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof29(obj);
39 };
40
41 var _typeof27 = typeof Symbol === "function" && _typeof28(Symbol.iterator) === "symbol" ? function (obj) {
42 return typeof obj === "undefined" ? "undefined" : _typeof28(obj);
43 } : function (obj) {
44 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof28(obj);
45 };
46
47 var _typeof26 = typeof Symbol === "function" && _typeof27(Symbol.iterator) === "symbol" ? function (obj) {
48 return typeof obj === "undefined" ? "undefined" : _typeof27(obj);
49 } : function (obj) {
50 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof27(obj);
51 };
52
53 var _typeof25 = typeof Symbol === "function" && _typeof26(Symbol.iterator) === "symbol" ? function (obj) {
54 return typeof obj === "undefined" ? "undefined" : _typeof26(obj);
55 } : function (obj) {
56 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof26(obj);
57 };
58
59 var _typeof24 = typeof Symbol === "function" && _typeof25(Symbol.iterator) === "symbol" ? function (obj) {
60 return typeof obj === "undefined" ? "undefined" : _typeof25(obj);
61 } : function (obj) {
62 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof25(obj);
63 };
64
65 var _typeof23 = typeof Symbol === "function" && _typeof24(Symbol.iterator) === "symbol" ? function (obj) {
66 return typeof obj === "undefined" ? "undefined" : _typeof24(obj);
67 } : function (obj) {
68 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof24(obj);
69 };
70
71 var _typeof22 = typeof Symbol === "function" && _typeof23(Symbol.iterator) === "symbol" ? function (obj) {
72 return typeof obj === "undefined" ? "undefined" : _typeof23(obj);
73 } : function (obj) {
74 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof23(obj);
75 };
76
77 var _typeof21 = typeof Symbol === "function" && _typeof22(Symbol.iterator) === "symbol" ? function (obj) {
78 return typeof obj === "undefined" ? "undefined" : _typeof22(obj);
79 } : function (obj) {
80 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof22(obj);
81 };
82
83 var _typeof20 = typeof Symbol === "function" && _typeof21(Symbol.iterator) === "symbol" ? function (obj) {
84 return typeof obj === "undefined" ? "undefined" : _typeof21(obj);
85 } : function (obj) {
86 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof21(obj);
87 };
88
89 var _typeof19 = typeof Symbol === "function" && _typeof20(Symbol.iterator) === "symbol" ? function (obj) {
90 return typeof obj === "undefined" ? "undefined" : _typeof20(obj);
91 } : function (obj) {
92 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof20(obj);
93 };
94
95 var _typeof18 = typeof Symbol === "function" && _typeof19(Symbol.iterator) === "symbol" ? function (obj) {
96 return typeof obj === "undefined" ? "undefined" : _typeof19(obj);
97 } : function (obj) {
98 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof19(obj);
99 };
100
101 var _typeof17 = typeof Symbol === "function" && _typeof18(Symbol.iterator) === "symbol" ? function (obj) {
102 return typeof obj === "undefined" ? "undefined" : _typeof18(obj);
103 } : function (obj) {
104 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof18(obj);
105 };
106
107 var _typeof16 = typeof Symbol === "function" && _typeof17(Symbol.iterator) === "symbol" ? function (obj) {
108 return typeof obj === "undefined" ? "undefined" : _typeof17(obj);
109 } : function (obj) {
110 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof17(obj);
111 };
112
113 var _typeof15 = typeof Symbol === "function" && _typeof16(Symbol.iterator) === "symbol" ? function (obj) {
114 return typeof obj === "undefined" ? "undefined" : _typeof16(obj);
115 } : function (obj) {
116 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof16(obj);
117 };
118
119 var _typeof14 = typeof Symbol === "function" && _typeof15(Symbol.iterator) === "symbol" ? function (obj) {
120 return typeof obj === "undefined" ? "undefined" : _typeof15(obj);
121 } : function (obj) {
122 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof15(obj);
123 };
124
125 var _typeof13 = typeof Symbol === "function" && _typeof14(Symbol.iterator) === "symbol" ? function (obj) {
126 return typeof obj === "undefined" ? "undefined" : _typeof14(obj);
127 } : function (obj) {
128 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof14(obj);
129 };
130
131 var _typeof12 = typeof Symbol === "function" && _typeof13(Symbol.iterator) === "symbol" ? function (obj) {
132 return typeof obj === "undefined" ? "undefined" : _typeof13(obj);
133 } : function (obj) {
134 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof13(obj);
135 };
136
137 var _typeof11 = typeof Symbol === "function" && _typeof12(Symbol.iterator) === "symbol" ? function (obj) {
138 return typeof obj === "undefined" ? "undefined" : _typeof12(obj);
139 } : function (obj) {
140 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof12(obj);
141 };
142
143 var _typeof10 = typeof Symbol === "function" && _typeof11(Symbol.iterator) === "symbol" ? function (obj) {
144 return typeof obj === "undefined" ? "undefined" : _typeof11(obj);
145 } : function (obj) {
146 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof11(obj);
147 };
148
149 var _typeof9 = typeof Symbol === "function" && _typeof10(Symbol.iterator) === "symbol" ? function (obj) {
150 return typeof obj === "undefined" ? "undefined" : _typeof10(obj);
151 } : function (obj) {
152 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof10(obj);
153 };
154
155 var _typeof8 = typeof Symbol === "function" && _typeof9(Symbol.iterator) === "symbol" ? function (obj) {
156 return typeof obj === "undefined" ? "undefined" : _typeof9(obj);
157 } : function (obj) {
158 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof9(obj);
159 };
160
161 var _typeof7 = typeof Symbol === "function" && _typeof8(Symbol.iterator) === "symbol" ? function (obj) {
162 return typeof obj === "undefined" ? "undefined" : _typeof8(obj);
163 } : function (obj) {
164 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof8(obj);
165 };
166
167 var _typeof6 = typeof Symbol === "function" && _typeof7(Symbol.iterator) === "symbol" ? function (obj) {
168 return typeof obj === "undefined" ? "undefined" : _typeof7(obj);
169 } : function (obj) {
170 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof7(obj);
171 };
172
173 var _typeof5 = typeof Symbol === "function" && _typeof6(Symbol.iterator) === "symbol" ? function (obj) {
174 return typeof obj === "undefined" ? "undefined" : _typeof6(obj);
175 } : function (obj) {
176 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof6(obj);
177 };
178
179 var _typeof4 = typeof Symbol === "function" && _typeof5(Symbol.iterator) === "symbol" ? function (obj) {
180 return typeof obj === "undefined" ? "undefined" : _typeof5(obj);
181 } : function (obj) {
182 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof5(obj);
183 };
184
185 var _typeof3 = typeof Symbol === "function" && _typeof4(Symbol.iterator) === "symbol" ? function (obj) {
186 return typeof obj === "undefined" ? "undefined" : _typeof4(obj);
187 } : function (obj) {
188 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof4(obj);
189 };
190
191 var _typeof2 = typeof Symbol === "function" && _typeof3(Symbol.iterator) === "symbol" ? function (obj) {
192 return typeof obj === "undefined" ? "undefined" : _typeof3(obj);
193 } : function (obj) {
194 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof3(obj);
195 };
196
197 var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
198 return typeof obj === "undefined" ? "undefined" : _typeof2(obj);
199 } : function (obj) {
200 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof2(obj);
201 };
202
203 /*!
204 weForms - v1.6.7
205 Generated: 2021-06-08 (1623168583312)
206 */
207
208 ;(function ($) {
209 /* ./assets/spa/components/component-table/index.js */
210 Vue.component('wpuf-table', {
211 template: '#tmpl-wpuf-component-table',
212 mixins: [weForms.mixins.Loading, weForms.mixins.Paginate, weForms.mixins.BulkAction],
213 props: {
214 has_export: String,
215 action: String,
216 delete: String,
217 id: [String, Number],
218 status: [String]
219 },
220
221 data: function data() {
222 return {
223 loading: false,
224 columns: [],
225 items: [],
226 ajaxAction: this.action,
227 nonce: weForms.nonce,
228 index: 'id',
229 bulkDeleteAction: this.delete ? this.delete : 'weforms_form_entry_trash_bulk'
230 };
231 },
232 created: function created() {
233 this.fetchData();
234 },
235
236 computed: {
237 columnLength: function columnLength() {
238 return Object.keys(this.columns).length;
239 }
240 },
241 methods: {
242
243 fetchData: function fetchData() {
244 var self = this;
245
246 this.loading = true;
247
248 wp.ajax.send(self.action, {
249 data: {
250 id: self.id,
251 page: self.currentPage,
252 status: self.status,
253 _wpnonce: weForms.nonce
254 },
255 success: function success(response) {
256 self.loading = false;
257 self.columns = response.columns;
258 self.items = response.entries;
259 self.form_title = response.form_title;
260 self.totalItems = response.pagination.total;
261 self.perPage = response.pagination.per_page;
262 self.totalPage = response.pagination.pages;
263
264 self.$emit('ajaxsuccess', response);
265 },
266 error: function error(_error) {
267 self.loading = false;
268 alert(_error);
269 }
270 });
271 },
272
273 handleBulkAction: function handleBulkAction() {
274 if ('-1' === this.bulkAction) {
275 alert('Please chose a bulk action to perform');
276 return;
277 }
278
279 if ('delete' === this.bulkAction) {
280 if (!this.checkedItems.length) {
281 alert('Please select atleast one entry to delete.');
282 return;
283 }
284
285 if (confirm('Are you sure to delete the entries?')) {
286 this.deleteBulk();
287 }
288 }
289
290 if ('restore' === this.bulkAction) {
291 if (!this.checkedItems.length) {
292 alert('Please select atleast one entry to restore.');
293 return;
294 }
295
296 this.restoreBulk();
297 }
298 },
299 restore: function restore(entry_id) {
300 var self = this;
301 self.loading = true;
302
303 wp.ajax.send('weforms_form_entry_restore', {
304 data: {
305 entry_id: entry_id,
306 _wpnonce: weForms.nonce
307 },
308 success: function success(response) {
309 self.loading = false;
310 self.fetchData();
311 },
312 error: function error(_error2) {
313 self.loading = false;
314 alert(_error2);
315 }
316 });
317 },
318 deletePermanently: function deletePermanently(entry_id) {
319
320 if (confirm('Are you sure to delete this entry?')) {
321
322 var self = this;
323 self.loading = true;
324
325 wp.ajax.send('weforms_form_entry_delete', {
326 data: {
327 entry_id: entry_id,
328 _wpnonce: weForms.nonce
329 },
330 success: function success(response) {
331 self.loading = false;
332 self.fetchData();
333 },
334 error: function error(_error3) {
335 self.loading = false;
336 alert(_error3);
337 }
338 });
339 }
340 }
341 },
342
343 watch: {
344 id: function id() {
345 this.fetchData();
346 },
347 status: function status() {
348 this.currentPage = 1;
349 this.bulkAction = -1;
350 this.fetchData();
351 }
352 }
353 });
354
355 /* ./assets/spa/components/entries/index.js */
356 weForms.routeComponents.Entries = {
357 template: '#tmpl-wpuf-entries',
358 data: function data() {
359 return {
360 selected: 0,
361 forms: {},
362 form_title: 'Loading...',
363 status: 'publish',
364 total: 0,
365 totalTrash: 0
366 };
367 },
368
369 created: function created() {
370 this.get_forms();
371 },
372
373 methods: {
374 get_forms: function get_forms() {
375 var self = this;
376
377 wp.ajax.send('weforms_form_list', {
378 data: {
379 _wpnonce: weForms.nonce,
380 page: self.currentPage,
381 posts_per_page: -1,
382 filter: 'entries'
383 },
384 success: function success(response) {
385 if (Object.keys(response.forms).length) {
386 self.forms = response.forms;
387 self.selected = self.forms[Object.keys(self.forms)[0]].id;
388 } else {
389 self.form_title = 'No entry found';
390 }
391 },
392 error: function error(_error4) {
393 alert(_error4);
394 }
395 });
396 }
397 }
398 };
399
400 /* ./assets/spa/components/form-builder/index.js */
401 weForms.routeComponents.FormEditComponent = {
402 template: '#tmpl-wpuf-form-builder',
403 mixins: wpuf_form_builder_mixins(wpuf_mixins.root),
404 data: function data() {
405 return {
406 is_form_saving: false,
407 is_form_saved: false,
408 is_form_switcher: false,
409 post_title_editing: false,
410 loading: false,
411 activeTab: 'editor',
412 activeSettingsTab: 'form',
413 activePaymentTab: 'paypal'
414 };
415 },
416
417 watch: {
418 loading: function loading(value) {
419 if (value) {
420 NProgress.configure({ parent: '#wpadminbar' });
421 NProgress.start();
422 } else {
423 NProgress.done();
424 }
425 },
426 form_fields: {
427 handler: function handler() {
428 window.weFormsBuilderisDirty = true;
429 },
430 deep: true
431 },
432 notifications: {
433 handler: function handler() {
434 window.weFormsBuilderisDirty = true;
435 },
436 deep: true
437 },
438 integrations: {
439 handler: function handler() {
440 window.weFormsBuilderisDirty = true;
441 },
442 deep: true
443 },
444 settings: {
445 handler: function handler() {
446 window.weFormsBuilderisDirty = true;
447 },
448 deep: true
449 },
450 payment: {
451 handler: function handler() {
452 window.weFormsBuilderisDirty = true;
453 },
454 deep: true
455 }
456 },
457
458 created: function created() {
459 this.set_current_panel('form-fields');
460 this.fetchForm();
461
462 this.$store.commit('panel_add_show_prop');
463
464 /**
465 * This is the event hub we'll use in every
466 * component to communicate between them
467 */
468 wpuf_form_builder.event_hub = new Vue();
469 },
470
471 computed: {
472 current_panel: function current_panel() {
473 return this.$store.state.current_panel;
474 },
475
476 post: function post() {
477 return this.$store.state.post;
478 },
479
480 form_fields_count: function form_fields_count() {
481 return this.$store.state.form_fields.length;
482 },
483
484 form_fields: function form_fields() {
485 return this.$store.state.form_fields;
486 },
487
488 notifications: function notifications() {
489 return this.$store.state.notifications;
490 },
491
492 integrations: function integrations() {
493 return this.$store.state.integrations;
494 },
495
496 settings: function settings() {
497 return this.$store.state.settings;
498 },
499
500 payment: function payment() {
501 return this.$store.state.payment;
502 }
503 },
504
505 mounted: function mounted() {
506
507 var clipboard = new window.Clipboard('.form-id');
508 $(".form-id").tooltip();
509
510 var self = this;
511
512 this.started = true;
513
514 clipboard.on('success', function (e) {
515 // Show copied tooltip
516 $(e.trigger).attr('data-original-title', 'Copied!').tooltip('show');
517
518 // Reset the copied tooltip
519 setTimeout(function () {
520 $(e.trigger).tooltip('hide').attr('data-original-title', self.i18n.copy_shortcode);
521 }, 1000);
522
523 e.clearSelection();
524 });
525
526 this.initSharingClipBoard();
527
528 setTimeout(function () {
529 window.weFormsBuilderisDirty = false;
530 }, 500);
531
532 window.onbeforeunload = function () {
533 if (window.weFormsBuilderisDirty) {
534 return self.i18n.unsaved_changes;
535 }
536 };
537 },
538
539 methods: {
540
541 makeActive: function makeActive(val) {
542 this.activeTab = val;
543 },
544
545 isActiveTab: function isActiveTab(val) {
546 return this.activeTab === val;
547 },
548
549 isActiveSettingsTab: function isActiveSettingsTab(val) {
550 return this.activeSettingsTab === val;
551 },
552
553 makeActiveSettingsTab: function makeActiveSettingsTab(val) {
554 this.activeSettingsTab = val;
555 },
556
557 isActivePaymentTab: function isActivePaymentTab(val) {
558 return this.activePaymentTab === val;
559 },
560
561 makeActivePaymentTab: function makeActivePaymentTab(val) {
562 this.activePaymentTab = val;
563 },
564
565 fetchForm: function fetchForm() {
566 var self = this;
567
568 self.loading = true;
569
570 wp.ajax.send('weforms_get_form', {
571 data: {
572 form_id: this.$route.params.id,
573 _wpnonce: weForms.nonce
574 },
575 success: function success(response) {
576
577 self.$store.commit('set_form_post', response.post);
578 self.$store.commit('set_form_fields', response.form_fields);
579 self.$store.commit('set_form_notification', response.notifications);
580 self.$store.commit('set_form_settings', response.settings);
581
582 // if nothing saved in the form, it provides an empty array
583 // but we expect to be an object
584 if (response.integrations.length !== undefined) {
585 self.$store.commit('set_form_integrations', {});
586 } else {
587 self.$store.commit('set_form_integrations', response.integrations);
588 }
589 },
590 error: function error(_error5) {
591 alert(_error5);
592 },
593
594 complete: function complete() {
595 self.loading = false;
596 }
597 });
598 },
599
600 // set current sidebar panel
601 set_current_panel: function set_current_panel(panel) {
602 this.$store.commit('set_current_panel', panel);
603 },
604
605 // save form builder data
606 save_form_builder: function save_form_builder() {
607 var self = this;
608
609 if (_.isFunction(this.validate_form_before_submit) && !this.validate_form_before_submit()) {
610
611 this.warn({
612 text: this.validation_error_msg
613 });
614
615 return;
616 }
617
618 self.is_form_saving = true;
619 self.set_current_panel('form-fields');
620
621 wp.ajax.send('wpuf_form_builder_save_form', {
622 data: {
623 form_data: $('#wpuf-form-builder').weSerialize(),
624 form_fields: JSON.stringify(self.form_fields),
625 notifications: JSON.stringify(self.notifications),
626 settings: JSON.stringify(self.settings),
627 payment: JSON.stringify(self.payment),
628 integrations: JSON.stringify(self.integrations)
629 },
630
631 success: function success(response) {
632 if (response.form_fields) {
633 self.$store.commit('set_form_fields', response.form_fields);
634 }
635
636 self.is_form_saving = false;
637 self.is_form_saved = true;
638
639 setTimeout(function () {
640 window.weFormsBuilderisDirty = false;
641 }, 500);
642
643 toastr.success(self.i18n.saved_form_data);
644 },
645
646 error: function error() {
647 self.is_form_saving = false;
648 }
649 });
650 },
651
652 save_settings: function save_settings() {
653 toastr.options.preventDuplicates = true;
654 this.save_form_builder();
655 },
656
657 shareForm: function shareForm(site_url, post) {
658
659 var self = this;
660
661 if (self.settings.sharing_on === 'on') {
662
663 var post_link = site_url + '?weforms=' + btoa(self.getSharingHash() + '_' + Math.floor(Date.now() / 1000) + '_' + post.ID);
664
665 swal({
666 title: self.i18n.shareYourForm,
667 html: '<p>' + self.i18n.shareYourFormText + '</p> <p><input onClick="this.setSelectionRange(0, this.value.length)" type="text" class="regular-text" value="' + post_link + '"/> <button class="anonymous-share-btn button button-primary" title="Copy URL" data-clipboard-text="' + post_link + '"><i class="fa fa-clipboard" aria-hidden="true"></i></button></p>',
668 showCloseButton: true,
669 showCancelButton: true,
670 confirmButtonClass: 'btn btn-success',
671 cancelButtonClass: 'btn btn-danger',
672 confirmButtonColor: '#d54e21',
673 confirmButtonText: self.i18n.disableSharing,
674 cancelButtonText: self.i18n.close,
675 focusCancel: true
676
677 }).then(function () {
678 swal({
679 title: self.i18n.areYouSure,
680 html: "<p>" + self.i18n.areYouSureDesc + "</p>",
681 type: 'info',
682 confirmButtonColor: '#d54e21',
683 showCancelButton: true,
684 confirmButtonText: self.i18n.disable,
685 cancelButtonText: self.i18n.cancel
686 }).then(function () {
687 self.disableSharing();
688 });
689 });
690 } else {
691
692 swal({
693 title: self.i18n.shareYourForm,
694 html: self.i18n.shareYourFormDesc,
695 type: 'info',
696 showCancelButton: true,
697 confirmButtonText: 'Enable',
698 cancelButtonText: 'Cancel'
699 }).then(function () {
700 self.enableSharing(site_url, post);
701 });
702 }
703 },
704
705 enableSharing: function enableSharing(site_url, post) {
706
707 this.settings.sharing_on = 'on';
708 this.save_settings();
709 this.shareForm(site_url, post);
710 },
711
712 disableSharing: function disableSharing() {
713 this.settings.sharing_on = false;
714 this.save_settings();
715 },
716 getSharingHash: function getSharingHash() {
717
718 if (!this.settings.sharing_hash) {
719 this.settings.sharing_hash = this.makeRandomString(8);
720 this.save_settings();
721 }
722
723 return this.settings.sharing_hash;
724 },
725
726 makeRandomString: function makeRandomString(limit) {
727 limit = limit || 8;
728 var text = "";
729 var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
730
731 for (var i = 0; i < limit; i++) {
732
733 text += possible.charAt(Math.floor(Math.random() * possible.length));
734 }
735
736 return text;
737 },
738
739 initSharingClipBoard: function initSharingClipBoard(val) {
740 var clipboard2 = new window.Clipboard('.anonymous-share-btn');
741
742 $(".anonymous-share-btn").tooltip();
743
744 clipboard2.on('success', function (e) {
745 // Show copied tooltip
746 $(e.trigger).attr('data-original-title', 'Copied!').tooltip('show');
747
748 // Reset the copied tooltip
749 setTimeout(function () {
750 $(e.trigger).tooltip('hide').attr('data-original-title', 'Copy URL');
751 }, 1000);
752
753 e.clearSelection();
754 });
755 }
756
757 }
758 };
759
760 /* ./assets/spa/components/form-entries/index.js */
761 weForms.routeComponents.FormEntries = {
762 props: {
763 id: [String, Number]
764 },
765 template: '#tmpl-wpuf-form-entries',
766 data: function data() {
767 return {
768 selected: 0,
769 form_title: 'Loading...',
770 status: 'publish',
771 total: 0,
772 totalTrash: 0
773 };
774 }
775 };
776
777 /* ./assets/spa/components/form-entry-single/index.js */
778 weForms.routeComponents.FormEntriesSingle = {
779 template: '#tmpl-wpuf-form-entry-single',
780 mixins: [weForms.mixins.Loading, weForms.mixins.Cookie],
781 data: function data() {
782 return {
783 loading: false,
784 hideEmpty: true,
785 hasEmpty: false,
786 show_payment_data: false,
787 entry: {
788 form_fields: {},
789 meta_data: {},
790 payment_data: {}
791 },
792 form_settings: {},
793 respondent_points: 0,
794 answers: {},
795 countries: weForms.countries
796 };
797 },
798 created: function created() {
799 this.hideEmpty = this.hideEmptyStatus();
800 this.fetchData();
801 },
802 computed: {
803 hasFormFields: function hasFormFields() {
804 return Object.keys(this.entry.form_fields).length;
805 }
806 },
807 methods: {
808 fetchData: function fetchData() {
809 var self = this;
810
811 this.loading = true;
812
813 wp.ajax.send('weforms_form_entry_details', {
814 data: {
815 entry_id: self.$route.params.entryid,
816 form_id: self.$route.params.id,
817 _wpnonce: weForms.nonce
818 },
819 success: function success(response) {
820 self.loading = false;
821 self.entry = response;
822 self.hasEmpty = response.has_empty;
823 self.form_settings = response.form_settings;
824 self.respondent_points = response.respondent_points;
825 self.answers = response.answers;
826 },
827 error: function error(_error6) {
828 self.loading = false;
829 alert(_error6);
830 }
831 });
832 },
833
834 trashEntry: function trashEntry() {
835 var self = this;
836
837 if (!confirm(weForms.confirm)) {
838 return;
839 }
840
841 wp.ajax.send('weforms_form_entry_trash', {
842 data: {
843 entry_id: self.$route.params.entryid,
844 _wpnonce: weForms.nonce
845 },
846
847 success: function success() {
848 self.loading = false;
849
850 self.$router.push({ name: 'formEntries', params: { id: self.$route.params.id } });
851 },
852 error: function error(_error7) {
853 self.loading = false;
854 alert(_error7);
855 }
856 });
857 },
858
859 hideEmptyStatus: function hideEmptyStatus() {
860 return this.getCookie('weFormsEntryHideEmpty') === 'false' ? false : true;
861 },
862
863 findCountry: function findCountry(code) {
864 return this.countries.find(function (country) {
865 return country.code === code;
866 });
867 },
868
869 getCountryName: function getCountryName(code) {
870 if (this.findCountry(code)) {
871 return this.findCountry(code).name;
872 }
873 },
874
875 getAddressFieldValue: function getAddressFieldValue(value) {
876 var self = this,
877 countryString = value.match(/Country Select:(\s([A-Z])\w+)/g);
878
879 if (countryString !== null) {
880 var countryCode = countryString[0].substring(15, countryString[0].length).trim(),
881 countryName = self.getCountryName(countryCode),
882 strToReplace = countryCode;
883
884 return value.replace(strToReplace, countryName);
885 }
886
887 return value;
888 }
889 },
890 watch: {
891 hideEmpty: function hideEmpty(value) {
892 this.setCookie('weFormsEntryHideEmpty', value, 356);
893 }
894 }
895 };
896
897 /* ./assets/spa/components/form-list-table/index.js */
898 Vue.component('form-list-table', {
899 template: '#tmpl-wpuf-form-list-table',
900 mixins: [weForms.mixins.Loading, weForms.mixins.Paginate, weForms.mixins.BulkAction],
901 data: function data() {
902 return {
903 loading: false,
904 index: 'ID',
905 items: [],
906 bulkDeleteAction: 'weforms_form_delete_bulk'
907 };
908 },
909 created: function created() {
910 this.fetchData();
911 },
912 computed: {
913 is_pro: function is_pro() {
914 return 'true' === weForms.is_pro;
915 },
916 has_payment: function has_payment() {
917 return 'true' === weForms.has_payment;
918 }
919 },
920
921 methods: {
922 fetchData: function fetchData() {
923 var self = this;
924
925 this.loading = true;
926
927 wp.ajax.send('weforms_form_list', {
928 data: {
929 _wpnonce: weForms.nonce,
930 page: self.currentPage
931 },
932 success: function success(response) {
933 self.loading = false;
934 self.items = response.forms;
935 self.totalItems = response.meta.total;
936 self.totalPage = response.meta.pages;
937 },
938 error: function error(_error8) {
939 self.loading = false;
940 alert(_error8);
941 }
942 });
943 },
944
945 deleteForm: function deleteForm(index) {
946 var self = this;
947
948 if (confirm('Are you sure?')) {
949 self.loading = true;
950
951 wp.ajax.send('weforms_form_delete', {
952 data: {
953 form_id: this.items[index].id,
954 _wpnonce: weForms.nonce
955 },
956 success: function success(response) {
957 self.items.splice(index, 1);
958 self.loading = false;
959 },
960 error: function error(_error9) {
961 alert(_error9);
962 self.loading = false;
963 }
964 });
965 }
966 },
967
968 duplicate: function duplicate(form_id, index) {
969 var self = this;
970
971 this.loading = true;
972
973 wp.ajax.send('weforms_form_duplicate', {
974 data: {
975 form_id: form_id,
976 _wpnonce: weForms.nonce
977 },
978 success: function success(response) {
979 self.items.splice(0, 0, response);
980 self.loading = false;
981 },
982 error: function error(_error10) {
983 alert(_error10);
984 self.loading = false;
985 }
986 });
987 },
988
989 handleBulkAction: function handleBulkAction() {
990 if ('-1' === this.bulkAction) {
991 alert('Please chose a bulk action to perform');
992 return;
993 }
994
995 if ('delete' === this.bulkAction) {
996 if (!this.checkedItems.length) {
997 alert('Please select atleast one form to delete.');
998 return;
999 }
1000
1001 if (confirm('Are you sure to delete the forms?')) {
1002 this.deleteBulk();
1003 }
1004 }
1005 },
1006
1007 isPendingForm: function isPendingForm(scheduleStart) {
1008 var currentTime = Math.round(new Date().getTime() / 1000),
1009 startTime = Math.round(new Date(scheduleStart).getTime() / 1000);
1010
1011 if (currentTime < startTime) {
1012 return true;
1013 }
1014 return false;
1015 },
1016
1017 isExpiredForm: function isExpiredForm(scheduleEnd) {
1018 var currentTime = Math.round(new Date().getTime() / 1000),
1019 endTime = Math.round(new Date(scheduleEnd).getTime() / 1000);
1020
1021 if (currentTime > endTime) {
1022 return true;
1023 }
1024 return false;
1025 },
1026
1027 isOpenForm: function isOpenForm(scheduleStart, scheduleEnd) {
1028 var currentTime = Math.round(new Date().getTime() / 1000),
1029 startTime = Math.round(new Date(scheduleStart).getTime() / 1000),
1030 endTime = Math.round(new Date(scheduleEnd).getTime() / 1000);
1031
1032 if (currentTime > startTime && currentTime < endTime) {
1033 return true;
1034 }
1035 return false;
1036 },
1037
1038 isFormStatusClosed: function isFormStatusClosed(formSettings, entries) {
1039 if (formSettings.schedule_form === 'true' && this.isPendingForm(formSettings.schedule_start)) {
1040 return true;
1041 }
1042
1043 if (formSettings.schedule_form === 'true' && this.isExpiredForm(formSettings.schedule_end)) {
1044 return true;
1045 }
1046
1047 if (formSettings.limit_entries === 'true' && entries >= formSettings.limit_number) {
1048 return true;
1049 }
1050 return;
1051 },
1052
1053 formatTime: function formatTime(time) {
1054 var date = new Date(time),
1055 month = date.toLocaleString('en-us', { month: 'short' });
1056
1057 return month + ' ' + date.getDate() + ', ' + date.getFullYear();
1058 }
1059 }
1060 });
1061 /* ./assets/spa/components/form-payments/index.js */
1062 weForms.routeComponents.FormPayments = {
1063 props: {
1064 id: [String, Number]
1065 },
1066 template: '#tmpl-wpuf-form-payments',
1067 data: function data() {
1068 return {
1069 form_title: 'Loading...'
1070 };
1071 }
1072 };
1073
1074 /* ./assets/spa/components/home-page/index.js */
1075 weForms.routeComponents.Home = {
1076 template: '#tmpl-wpuf-home-page',
1077
1078 data: function data() {
1079 return {
1080 showTemplateModal: false
1081 };
1082 },
1083
1084 methods: {
1085 displayModal: function displayModal() {
1086 this.showTemplateModal = true;
1087 },
1088
1089 closeModal: function closeModal() {
1090 this.showTemplateModal = false;
1091 }
1092 }
1093 };
1094
1095 /* ./assets/spa/components/tools/index.js */
1096 weForms.routeComponents.Tools = {
1097 template: '#tmpl-wpuf-tools',
1098 mixins: [weForms.mixins.Tabs, weForms.mixins.Loading],
1099 data: function data() {
1100 return {
1101 activeTab: 'export',
1102 exportType: 'all',
1103 loading: false,
1104 forms: [],
1105 importButton: 'Import',
1106 currentStatus: 0,
1107 responseMessage: '',
1108 logs: [],
1109 ximport: {
1110 current: '',
1111 title: '',
1112 action: '',
1113 message: '',
1114 type: 'updated',
1115 refs: {}
1116 }
1117 };
1118 },
1119
1120 computed: {
1121
1122 isInitial: function isInitial() {
1123 return this.currentStatus === 0;
1124 },
1125
1126 isSaving: function isSaving() {
1127 return this.currentStatus === 1;
1128 },
1129
1130 isSuccess: function isSuccess() {
1131 return this.currentStatus === 2;
1132 },
1133
1134 isFailed: function isFailed() {
1135 return this.currentStatus === 3;
1136 },
1137
1138 hasRefs: function hasRefs() {
1139 return Object.keys(this.ximport.refs).length;
1140 },
1141 hasLogs: function hasLogs() {
1142 return Object.keys(this.logs).length;
1143 }
1144 },
1145
1146 created: function created() {
1147 this.fetchData();
1148 this.fetchLogs();
1149 },
1150
1151 methods: {
1152 fetchLogs: function fetchLogs(target) {
1153 var self = this;
1154
1155 self.startLoading(target);
1156
1157 wp.ajax.send('weforms_read_logs', {
1158 data: {
1159 _wpnonce: weForms.nonce
1160 },
1161 success: function success(response) {
1162 self.stopLoading(target);
1163 self.logs = response;
1164 }, error: function error() {
1165 self.stopLoading(target);
1166 self.logs = [];
1167 }
1168 });
1169 },
1170 deleteLogs: function deleteLogs(target) {
1171 var self = this;
1172
1173 if (confirm('Are you sure to clear the log file?')) {
1174
1175 self.startLoading(target);
1176
1177 wp.ajax.send('weforms_delete_logs', {
1178 data: {
1179 _wpnonce: weForms.nonce
1180 },
1181 success: function success(response) {
1182 self.logs = [];
1183 self.stopLoading(target);
1184 self.fetchLogs();
1185 },
1186 error: function error(response) {
1187 self.logs = [];
1188 self.stopLoading(target);
1189 self.fetchLogs();
1190 }
1191 });
1192 }
1193 },
1194 stopLoading: function stopLoading(target) {
1195 target = $(target);
1196
1197 if (target.is('button')) {
1198 target.removeClass('updating-message').find('span').show();
1199 } else if (target.is('span')) {
1200 target.show().parent().removeClass('updating-message');
1201 }
1202 },
1203 startLoading: function startLoading(target) {
1204
1205 target = $(target);
1206
1207 if (target.is('button')) {
1208 target.addClass('updating-message').find('span').hide();
1209 } else if (target.is('span')) {
1210 target.hide().parent().addClass('updating-message');
1211 }
1212 },
1213 fetchData: function fetchData() {
1214 var self = this;
1215
1216 this.loading = true;
1217
1218 wp.ajax.send('weforms_form_names', {
1219 data: {
1220 _wpnonce: weForms.nonce
1221 },
1222 success: function success(response) {
1223 // console.log(response);
1224 self.loading = false;
1225 self.forms = response;
1226 },
1227 error: function error(_error11) {
1228 self.loading = false;
1229 alert(_error11);
1230 }
1231 });
1232 },
1233
1234 importForm: function importForm(fieldName, fileList, event) {
1235 if (!fileList.length) {
1236 return;
1237 }
1238
1239 var formData = new FormData();
1240 var self = this;
1241
1242 formData.append(fieldName, fileList[0], fileList[0].name);
1243 formData.append('action', 'weforms_import_form');
1244 formData.append('_wpnonce', weForms.nonce);
1245
1246 self.currentStatus = 1;
1247
1248 $.ajax({
1249 type: "POST",
1250 url: window.ajaxurl,
1251 data: formData,
1252 processData: false,
1253 contentType: false,
1254 success: function success(response) {
1255 self.responseMessage = response.data;
1256
1257 if (response.success) {
1258 self.currentStatus = 2;
1259 } else {
1260 self.currentStatus = 3;
1261 }
1262
1263 // reset the value
1264 $(event.target).val('');
1265 },
1266
1267 error: function error(errResponse) {
1268 console.log(errResponse);
1269 self.currentStatus = 3;
1270 },
1271
1272 complete: function complete() {
1273 $(event.target).val('');
1274 }
1275 });
1276 },
1277
1278 importx: function importx(target, plugin) {
1279 var button = $(target);
1280 var self = this;
1281
1282 self.ximport.current = plugin;
1283 button.addClass('updating-message').text(button.data('importing'));
1284
1285 wp.ajax.send('weforms_import_xforms_' + plugin, {
1286 data: {
1287 _wpnonce: weForms.nonce
1288 },
1289
1290 success: function success(response) {
1291 self.ximport.title = response.title;
1292 self.ximport.message = response.message;
1293 self.ximport.action = response.action;
1294 self.ximport.refs = response.refs;
1295 },
1296
1297 error: function error(_error12) {
1298 alert(_error12.message);
1299 },
1300
1301 complete: function complete() {
1302 button.removeClass('updating-message').text(button.data('original'));
1303 }
1304 });
1305 },
1306
1307 replaceX: function replaceX(target, type) {
1308 var button = $(target);
1309 var self = this;
1310
1311 button.addClass('updating-message');
1312
1313 wp.ajax.send('weforms_import_xreplace_' + self.ximport.current, {
1314 data: {
1315 type: type,
1316 _wpnonce: weForms.nonce
1317 },
1318
1319 success: function success(response) {
1320 if ('replace' === button.data('type')) {
1321 alert(response);
1322 }
1323 },
1324
1325 error: function error(_error13) {
1326 alert(_error13);
1327 },
1328
1329 complete: function complete() {
1330 self.ximport.current = '';
1331 self.ximport.title = '';
1332 }
1333 });
1334 }
1335 }
1336 };
1337
1338 /* ./assets/spa/components/transactions/index.js */
1339 weForms.routeComponents.Transactions = {
1340 template: '#tmpl-wpuf-transactions',
1341 data: function data() {
1342 return {
1343 selected: 0,
1344 no_transactions: false,
1345 forms: {},
1346 form_title: 'Loading...'
1347 };
1348 },
1349
1350 created: function created() {
1351 this.get_forms();
1352 },
1353
1354 methods: {
1355 get_forms: function get_forms() {
1356 var self = this;
1357
1358 wp.ajax.send('weforms_form_list', {
1359 data: {
1360 _wpnonce: weForms.nonce,
1361 page: self.currentPage,
1362 filter: 'transactions'
1363 },
1364 success: function success(response) {
1365
1366 if (Object.keys(response.forms).length) {
1367 self.forms = response.forms;
1368 self.selected = self.forms[Object.keys(self.forms)[0]].id;
1369 } else {
1370 self.form_title = 'No transaction found';
1371 self.no_transactions = true;
1372 }
1373 },
1374 error: function error(_error14) {
1375 alert(_error14);
1376 }
1377 });
1378 }
1379 }
1380 };
1381
1382 /* ./assets/spa/components/weforms-page-help/index.js */
1383 weForms.routeComponents.Help = {
1384 template: '#tmpl-wpuf-weforms-page-help'
1385 };
1386 /* ./assets/spa/components/weforms-page-privacy/index.js */
1387 weForms.routeComponents.Privacy = {
1388 template: '#tmpl-wpuf-weforms-page-privacy'
1389 };
1390 /* ./assets/spa/components/weforms-premium/index.js */
1391 weForms.routeComponents.Premium = {
1392 template: '#tmpl-wpuf-weforms-premium',
1393 data: function data() {
1394 return {
1395 showModal: false
1396 };
1397 }
1398 };
1399 /* ./assets/spa/components/weforms-settings/index.js */
1400 weForms.routeComponents.Settings = {
1401 template: '#tmpl-wpuf-weforms-settings',
1402 mixins: [weForms.mixins.Loading, weForms.mixins.Cookie],
1403 data: function data() {
1404 return {
1405 loading: false,
1406 settings: {
1407 email_gateway: 'wordpress',
1408 credit: false,
1409 permission: 'manage_options',
1410 gateways: {
1411 sendgrid: '',
1412 mailgun: '',
1413 sparkpost: ''
1414 },
1415 recaptcha: {
1416 type: 'v2',
1417 key: '',
1418 secret: ''
1419 }
1420 },
1421
1422 activeTab: 'general'
1423 };
1424 },
1425
1426 computed: {
1427
1428 is_pro: function is_pro() {
1429 return 'true' === weForms.is_pro;
1430 }
1431 },
1432
1433 created: function created() {
1434 this.fetchSettings();
1435
1436 if (this.getCookie('weforms_settings_active_tab')) {
1437 this.activeTab = this.getCookie('weforms_settings_active_tab');
1438 }
1439 },
1440
1441 methods: {
1442
1443 makeActive: function makeActive(val) {
1444 this.activeTab = val;
1445 },
1446
1447 isActiveTab: function isActiveTab(val) {
1448 return this.activeTab === val;
1449 },
1450
1451 fetchSettings: function fetchSettings() {
1452 var self = this;
1453
1454 self.loading = true;
1455
1456 wp.ajax.send('weforms_get_settings', {
1457 data: {
1458 _wpnonce: weForms.nonce
1459 },
1460
1461 success: function success(response) {
1462
1463 if (response === undefined) {
1464 return;
1465 }
1466
1467 // set defaults if undefined
1468 $.each(self.settings, function (key, value) {
1469 if (response[key] === undefined) {
1470 response[key] = value;
1471 }
1472 });
1473
1474 self.settings = response;
1475 },
1476
1477 complete: function complete() {
1478 self.loading = false;
1479 }
1480 });
1481 },
1482
1483 saveSettings: function saveSettings(target) {
1484 var self = this;
1485
1486 $(target).addClass('updating-message');
1487
1488 wp.ajax.send('weforms_save_settings', {
1489 data: {
1490 settings: JSON.stringify(self.settings),
1491 _wpnonce: weForms.nonce
1492 },
1493
1494 success: function success(response) {
1495 toastr.options.timeOut = 1000;
1496 toastr.success('Settings has been updated');
1497
1498 weForms.settings = response;
1499 },
1500
1501 error: function error(_error15) {
1502 console.log(_error15);
1503 },
1504
1505 complete: function complete() {
1506 $(target).removeClass('updating-message');
1507 }
1508 });
1509 },
1510
1511 post: function post(action, data, _success) {
1512 data = data || {};
1513 _success = _success || function () {};
1514 data._wpnonce = weForms.nonce;
1515
1516 wp.ajax.send(action, {
1517 data: data,
1518
1519 success: function success(response) {
1520 _success(response);
1521 },
1522
1523 error: function error(_error16) {
1524 console.log(_error16);
1525 },
1526
1527 complete: function complete() {}
1528 });
1529 }
1530 },
1531
1532 watch: {
1533 activeTab: function activeTab(value) {
1534 this.setCookie('weforms_settings_active_tab', value, '365');
1535 }
1536 }
1537 };
1538
1539 /* ./assets/spa/app.js */
1540 if (!Array.prototype.hasOwnProperty('swap')) {
1541 Array.prototype.swap = function (from, to) {
1542 this.splice(to, 0, this.splice(from, 1)[0]);
1543 };
1544 }
1545
1546 Vue.component('datepicker', {
1547 template: '<input type="text" v-bind:value="value" />',
1548 props: ['value'],
1549 mounted: function mounted() {
1550 var self = this;
1551
1552 $(this.$el).datetimepicker({
1553 dateFormat: 'yy-mm-dd',
1554 timeFormat: "HH:mm:ss",
1555 onClose: this.onClose
1556 });
1557 },
1558
1559 methods: {
1560 onClose: function onClose(date) {
1561 this.$emit('input', date);
1562 }
1563 }
1564 });
1565
1566 Vue.component('weforms-colorpicker', {
1567 template: '<input type="text" v-bind:value="value" />',
1568 props: ['value'],
1569 mounted: function mounted() {
1570 var self = this;
1571
1572 $(this.$el).wpColorPicker({
1573 change: this.onChange
1574 });
1575 },
1576
1577 methods: {
1578 onChange: function onChange(event, ui) {
1579 this.$emit('input', ui.color.toString());
1580 }
1581 }
1582 });
1583
1584 // check if an element is visible in browser viewport
1585 function is_element_in_viewport(el) {
1586 if (typeof jQuery === "function" && el instanceof jQuery) {
1587 el = el[0];
1588 }
1589
1590 var rect = el.getBoundingClientRect();
1591
1592 return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1593 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1594 ;
1595 }
1596
1597 /**
1598 * Vuex Store data
1599 */
1600 var wpuf_form_builder_store = new Vuex.Store({
1601 state: {
1602 post: {},
1603 form_fields: [],
1604 panel_sections: wpuf_form_builder.panel_sections,
1605 field_settings: wpuf_form_builder.field_settings,
1606 notifications: [],
1607 settings: {},
1608 integrations: {},
1609 current_panel: 'form-fields',
1610 editing_field_id: 0 // editing form field id
1611 },
1612
1613 mutations: {
1614 set_form_fields: function set_form_fields(state, form_fields) {
1615 Vue.set(state, 'form_fields', form_fields);
1616 },
1617
1618 set_form_post: function set_form_post(state, post) {
1619 Vue.set(state, 'post', post);
1620 },
1621
1622 set_form_notification: function set_form_notification(state, value) {
1623 Vue.set(state, 'notifications', value);
1624 },
1625
1626 set_form_integrations: function set_form_integrations(state, value) {
1627 Vue.set(state, 'integrations', value);
1628 },
1629
1630 set_form_settings: function set_form_settings(state, value) {
1631 Vue.set(state, 'settings', value);
1632 },
1633
1634 // set the current panel
1635 set_current_panel: function set_current_panel(state, panel) {
1636 if ('field-options' !== state.current_panel && 'field-options' === panel && state.form_fields.length) {
1637 state.editing_field_id = state.form_fields[0].id;
1638 }
1639
1640 state.current_panel = panel;
1641
1642 // reset editing field id
1643 if ('form-fields' === panel) {
1644 state.editing_field_id = 0;
1645 }
1646 },
1647
1648 // add show property to every panel section
1649 panel_add_show_prop: function panel_add_show_prop(state) {
1650 state.panel_sections.map(function (section, index) {
1651 if (!section.hasOwnProperty('show')) {
1652 Vue.set(state.panel_sections[index], 'show', true);
1653 }
1654 });
1655 },
1656
1657 // toggle panel sections
1658 panel_toggle: function panel_toggle(state, index) {
1659 state.panel_sections[index].show = !state.panel_sections[index].show;
1660 },
1661
1662 // open field settings panel
1663 open_field_settings: function open_field_settings(state, field_id) {
1664 var field = state.form_fields.filter(function (item) {
1665 return parseInt(field_id) === parseInt(item.id);
1666 });
1667
1668 if ('field-options' === state.current_panel && field[0].id === state.editing_field_id) {
1669 return;
1670 }
1671
1672 if (field.length) {
1673 state.editing_field_id = 0;
1674 state.current_panel = 'field-options';
1675
1676 setTimeout(function () {
1677 state.editing_field_id = field[0].id;
1678 }, 400);
1679 }
1680 },
1681
1682 update_editing_form_field: function update_editing_form_field(state, payload) {
1683 var i = 0;
1684
1685 for (i = 0; i < state.form_fields.length; i++) {
1686 // check if the editing field exist in normal fields
1687 if (state.form_fields[i].id === parseInt(payload.editing_field_id)) {
1688 state.form_fields[i][payload.field_name] = payload.value;
1689 }
1690
1691 // check if the editing field belong to a column field
1692 if (state.form_fields[i].template === 'column_field') {
1693 var innerColumnFields = state.form_fields[i].inner_fields;
1694
1695 for (var columnFields in innerColumnFields) {
1696 if (innerColumnFields.hasOwnProperty(columnFields)) {
1697 var columnFieldIndex = 0;
1698
1699 while (columnFieldIndex < innerColumnFields[columnFields].length) {
1700 if (innerColumnFields[columnFields][columnFieldIndex].id === parseInt(payload.editing_field_id)) {
1701 innerColumnFields[columnFields][columnFieldIndex][payload.field_name] = payload.value;
1702 }
1703 columnFieldIndex++;
1704 }
1705 }
1706 }
1707 }
1708 }
1709 },
1710
1711 // add new form field element
1712 add_form_field_element: function add_form_field_element(state, payload) {
1713 state.form_fields.splice(payload.toIndex, 0, payload.field);
1714
1715 // bring newly added element into viewport
1716 Vue.nextTick(function () {
1717 var el = $('#form-preview-stage .wpuf-form .field-items').eq(payload.toIndex);
1718
1719 if (el && !is_element_in_viewport(el.get(0))) {
1720 $('#builder-stage section').scrollTo(el, 800, { offset: -50 });
1721 }
1722 });
1723 },
1724
1725 // sorting inside stage
1726 swap_form_field_elements: function swap_form_field_elements(state, payload) {
1727 state.form_fields.swap(payload.fromIndex, payload.toIndex);
1728 },
1729
1730 clone_form_field_element: function clone_form_field_element(state, payload) {
1731 var field = _.find(state.form_fields, function (item) {
1732 return parseInt(item.id) === parseInt(payload.field_id);
1733 });
1734
1735 var clone = $.extend(true, {}, field),
1736 index = parseInt(payload.index) + 1;
1737
1738 clone.id = payload.new_id;
1739 clone.name = clone.name + '_copy';
1740 clone.is_new = true;
1741
1742 state.form_fields.splice(index, 0, clone);
1743 },
1744
1745 // delete a field
1746 delete_form_field_element: function delete_form_field_element(state, index) {
1747 state.current_panel = 'form-fields';
1748 state.form_fields.splice(index, 1);
1749 },
1750
1751 // set fields for a panel section
1752 set_panel_section_fields: function set_panel_section_fields(state, payload) {
1753 var section = _.find(state.panel_sections, function (item) {
1754 return item.id === payload.id;
1755 });
1756
1757 section.fields = payload.fields;
1758 },
1759
1760 // notifications
1761 addNotification: function addNotification(state, payload) {
1762 state.notifications.push(_.clone(payload));
1763 },
1764
1765 deleteNotification: function deleteNotification(state, index) {
1766 state.notifications.splice(index, 1);
1767 },
1768
1769 cloneNotification: function cloneNotification(state, index) {
1770 var clone = $.extend(true, {}, state.notifications[index]);
1771
1772 index = parseInt(index) + 1;
1773 state.notifications.splice(index, 0, clone);
1774 },
1775
1776 // update by it's property
1777 updateNotificationProperty: function updateNotificationProperty(state, payload) {
1778 state.notifications[payload.index][payload.property] = payload.value;
1779 },
1780
1781 updateNotification: function updateNotification(state, payload) {
1782 state.notifications[payload.index] = payload.value;
1783 },
1784
1785 updateIntegration: function updateIntegration(state, payload) {
1786 // console.log(payload);
1787 // console.log(state.integrations[payload.index]);
1788 // state.integrations[payload.index] = payload.value;
1789 Vue.set(state.integrations, payload.index, payload.value);
1790
1791 // state.integrations.splice(payload.index, 0, payload.value);
1792 },
1793
1794 // add new form field element to column field
1795 add_column_inner_field_element: function add_column_inner_field_element(state, payload) {
1796 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1797 return field.id === payload.toWhichColumnField;
1798 });
1799
1800 if (state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn] === undefined) {
1801 state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn] = [];
1802 }
1803
1804 if (state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn] !== undefined) {
1805 var innerColumnFields = state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn];
1806
1807 if (innerColumnFields.filter(function (innerField) {
1808 return innerField.name === payload.field.name;
1809 }).length <= 0) {
1810 state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn].splice(payload.toIndex, 0, payload.field);
1811 }
1812 }
1813 },
1814
1815 move_column_inner_fields: function move_column_inner_fields(state, payload) {
1816 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1817 return field.id === payload.field_id;
1818 }),
1819 innerFields = payload.inner_fields,
1820 mergedFields = [];
1821
1822 Object.keys(innerFields).forEach(function (column) {
1823 // clear column-1, column-2 and column-3 fields if move_to specified column-1
1824 // add column-1, column-2 and column-3 fields to mergedFields, later mergedFields will move to column-1 field
1825 if (payload.move_to === "column-1") {
1826 innerFields[column].forEach(function (field) {
1827 mergedFields.push(field);
1828 });
1829
1830 // clear current column inner fields
1831 state.form_fields[columnFieldIndex].inner_fields[column].splice(0, innerFields[column].length);
1832 }
1833
1834 // clear column-2 and column-3 fields if move_to specified column-2
1835 // add column-2 and column-3 fields to mergedFields, later mergedFields will move to column-2 field
1836 if (payload.move_to === "column-2") {
1837 if (column === "column-2" || column === "column-3") {
1838 innerFields[column].forEach(function (field) {
1839 mergedFields.push(field);
1840 });
1841
1842 // clear current column inner fields
1843 state.form_fields[columnFieldIndex].inner_fields[column].splice(0, innerFields[column].length);
1844 }
1845 }
1846 });
1847
1848 // move inner fields to specified column
1849 if (mergedFields.length !== 0) {
1850 mergedFields.forEach(function (field) {
1851 state.form_fields[columnFieldIndex].inner_fields[payload.move_to].splice(0, 0, field);
1852 });
1853 }
1854 },
1855
1856 // sorting inside column field
1857 swap_column_field_elements: function swap_column_field_elements(state, payload) {
1858 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1859 return field.id === payload.field_id;
1860 }),
1861 fieldObj = state.form_fields[columnFieldIndex].inner_fields[payload.fromColumn][payload.fromIndex];
1862
1863 if (payload.fromColumn !== payload.toColumn) {
1864 // add the field object to the target column
1865 state.form_fields[columnFieldIndex].inner_fields[payload.toColumn].splice(payload.toIndex, 0, fieldObj);
1866
1867 // remove the field index from the source column
1868 state.form_fields[columnFieldIndex].inner_fields[payload.fromColumn].splice(payload.fromIndex, 1);
1869 } else {
1870 state.form_fields[columnFieldIndex].inner_fields[payload.toColumn].swap(payload.fromIndex, payload.toIndex);
1871 }
1872 },
1873
1874 // open field settings panel
1875 open_column_field_settings: function open_column_field_settings(state, payload) {
1876 var field = payload.column_field;
1877
1878 if ('field-options' === state.current_panel && field.id === state.editing_field_id) {
1879 return;
1880 }
1881
1882 if (field) {
1883 state.editing_field_id = 0;
1884 state.current_panel = 'field-options';
1885 state.editing_field_type = 'column_field';
1886 state.editing_column_field_id = payload.field_id;
1887 state.edting_field_column = payload.column;
1888 state.editing_inner_field_index = payload.index;
1889
1890 setTimeout(function () {
1891 state.editing_field_id = field.id;
1892 }, 400);
1893 }
1894 },
1895
1896 clone_column_field_element: function clone_column_field_element(state, payload) {
1897 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1898 return field.id === payload.field_id;
1899 });
1900
1901 var field = _.find(state.form_fields[columnFieldIndex].inner_fields[payload.toColumn], function (item) {
1902 return parseInt(item.id) === parseInt(payload.column_field_id);
1903 });
1904
1905 var clone = $.extend(true, {}, field),
1906 index = parseInt(payload.index) + 1;
1907
1908 clone.id = payload.new_id;
1909 clone.name = clone.name + '_copy';
1910 clone.is_new = true;
1911
1912 state.form_fields[columnFieldIndex].inner_fields[payload.toColumn].splice(index, 0, clone);
1913 },
1914
1915 // delete a column field
1916 delete_column_field_element: function delete_column_field_element(state, payload) {
1917 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1918 return field.id === payload.field_id;
1919 });
1920
1921 state.current_panel = 'form-fields';
1922 state.form_fields[columnFieldIndex].inner_fields[payload.fromColumn].splice(payload.index, 1);
1923 }
1924 }
1925 });
1926
1927 // 1. Define route components.
1928 weForms.routeComponents.FormHome = { template: '<div><router-view class="child"></router-view></div>' };
1929 weForms.routeComponents.SingleForm = { template: '#tmpl-wpuf-form-editor' };
1930 weForms.routeComponents.FormEntriesHome = {
1931 template: '<div><router-view class="grand-child"></router-view></div>'
1932 };
1933
1934 /**
1935 * Parse the route array and bind required components
1936 *
1937 * This changes the weForms.routes array and changes the components
1938 * so we can use weForms.routeComponents.{compontent} component.
1939 *
1940 * @param {array} routes
1941 *
1942 * @return {void}
1943 */
1944 function parseRouteComponent(routes) {
1945
1946 for (var i = 0; i < routes.length; i++) {
1947 if (_typeof(routes[i].children) === 'object') {
1948
1949 parseRouteComponent(routes[i].children);
1950
1951 if (typeof routes[i].component !== 'undefined') {
1952 routes[i].component = weForms.routeComponents[routes[i].component];
1953 }
1954 } else {
1955 routes[i].component = weForms.routeComponents[routes[i].component];
1956 }
1957 }
1958 }
1959
1960 // mutate the localized array
1961 parseRouteComponent(weForms.routes);
1962
1963 // 3. Create the router instance and pass the `routes` option
1964 var router = new VueRouter({
1965 routes: weForms.routes,
1966 scrollBehavior: function scrollBehavior(to, from, savedPosition) {
1967 if (savedPosition) {
1968 return savedPosition;
1969 } else {
1970 return { x: 0, y: 0 };
1971 }
1972 }
1973 });
1974
1975 window.weFormsBuilderisDirty = false;
1976
1977 router.beforeEach(function (to, from, next) {
1978 // show warning if builder has unsaved changes
1979 if (window.weFormsBuilderisDirty) {
1980 if (confirm(wpuf_form_builder.i18n.unsaved_changes + ' ' + wpuf_form_builder.i18n.areYouSureToLeave)) {
1981 window.weFormsBuilderisDirty = false;
1982 } else {
1983 next(from.path);
1984 return false;
1985 }
1986 }
1987
1988 next();
1989 });
1990
1991 weForms.validators = {
1992 is_recaptcha_v2: function is_recaptcha_v2() {
1993 return weForms.settings.recaptcha.type === 'v2';
1994 }
1995 };
1996
1997 var app = new Vue({
1998 router: router,
1999 store: wpuf_form_builder_store
2000 }).$mount('#wpuf-contact-form-app');
2001
2002 // Admin menu hack
2003 var menuRoot = $('#toplevel_page_weforms');
2004
2005 menuRoot.on('click', 'a', function () {
2006 var self = $(this);
2007
2008 $('ul.wp-submenu li', menuRoot).removeClass('current');
2009
2010 if (self.hasClass('wp-has-submenu')) {
2011 $('li.wp-first-item', menuRoot).addClass('current');
2012 } else {
2013 self.parents('li').addClass('current');
2014 }
2015 });
2016
2017 $(function () {
2018
2019 // select the current sub menu on page load
2020 var current_url = window.location.href;
2021 var current_path = current_url.substr(current_url.indexOf('admin.php'));
2022
2023 $('ul.wp-submenu a', menuRoot).each(function (index, el) {
2024 if ($(el).attr('href') === current_path) {
2025 $(el).parent().addClass('current');
2026 return;
2027 }
2028 });
2029 });
2030 })(jQuery);
2031