PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.15
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.15
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.15, at assets/js/spa-app.js

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