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

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