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

1,841 lines 64.1 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.4.4
19 Generated: 2020-01-23 (1579756424406)
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').serialize(),
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-premium/index.js */
1201 weForms.routeComponents.Premium = {
1202 template: '#tmpl-wpuf-weforms-premium',
1203 data: function data() {
1204 return {
1205 showModal: false
1206 };
1207 }
1208 };
1209 /* ./assets/spa/components/weforms-settings/index.js */
1210 weForms.routeComponents.Settings = {
1211 template: '#tmpl-wpuf-weforms-settings',
1212 mixins: [weForms.mixins.Loading, weForms.mixins.Cookie],
1213 data: function data() {
1214 return {
1215 loading: false,
1216 settings: {
1217 email_gateway: 'wordpress',
1218 credit: false,
1219 permission: 'manage_options',
1220 gateways: {
1221 sendgrid: '',
1222 mailgun: '',
1223 sparkpost: ''
1224 },
1225 recaptcha: {
1226 type: 'v2',
1227 key: '',
1228 secret: ''
1229 }
1230 },
1231
1232 activeTab: 'general'
1233 };
1234 },
1235
1236 computed: {
1237
1238 is_pro: function is_pro() {
1239 return 'true' === weForms.is_pro;
1240 }
1241 },
1242
1243 created: function created() {
1244 this.fetchSettings();
1245
1246 if (this.getCookie('weforms_settings_active_tab')) {
1247 this.activeTab = this.getCookie('weforms_settings_active_tab');
1248 }
1249 },
1250
1251 methods: {
1252
1253 makeActive: function makeActive(val) {
1254 this.activeTab = val;
1255 },
1256
1257 isActiveTab: function isActiveTab(val) {
1258 return this.activeTab === val;
1259 },
1260
1261 fetchSettings: function fetchSettings() {
1262 var self = this;
1263
1264 self.loading = true;
1265
1266 wp.ajax.send('weforms_get_settings', {
1267 data: {
1268 _wpnonce: weForms.nonce
1269 },
1270
1271 success: function success(response) {
1272
1273 if (response === undefined) {
1274 return;
1275 }
1276
1277 // set defaults if undefined
1278 $.each(self.settings, function (key, value) {
1279 if (response[key] === undefined) {
1280 response[key] = value;
1281 }
1282 });
1283
1284 self.settings = response;
1285 },
1286
1287 complete: function complete() {
1288 self.loading = false;
1289 }
1290 });
1291 },
1292
1293 saveSettings: function saveSettings(target) {
1294 var self = this;
1295
1296 $(target).addClass('updating-message');
1297
1298 wp.ajax.send('weforms_save_settings', {
1299 data: {
1300 settings: JSON.stringify(self.settings),
1301 _wpnonce: weForms.nonce
1302 },
1303
1304 success: function success(response) {
1305 toastr.options.timeOut = 1000;
1306 toastr.success('Settings has been updated');
1307
1308 weForms.settings = response;
1309 },
1310
1311 error: function error(_error15) {
1312 console.log(_error15);
1313 },
1314
1315 complete: function complete() {
1316 $(target).removeClass('updating-message');
1317 }
1318 });
1319 },
1320
1321 post: function post(action, data, _success) {
1322 data = data || {};
1323 _success = _success || function () {};
1324 data._wpnonce = weForms.nonce;
1325
1326 wp.ajax.send(action, {
1327 data: data,
1328
1329 success: function success(response) {
1330 _success(response);
1331 },
1332
1333 error: function error(_error16) {
1334 console.log(_error16);
1335 },
1336
1337 complete: function complete() {}
1338 });
1339 }
1340 },
1341
1342 watch: {
1343 activeTab: function activeTab(value) {
1344 this.setCookie('weforms_settings_active_tab', value, '365');
1345 }
1346 }
1347 };
1348
1349 /* ./assets/spa/app.js */
1350 if (!Array.prototype.hasOwnProperty('swap')) {
1351 Array.prototype.swap = function (from, to) {
1352 this.splice(to, 0, this.splice(from, 1)[0]);
1353 };
1354 }
1355
1356 Vue.component('datepicker', {
1357 template: '<input type="text" v-bind:value="value" />',
1358 props: ['value'],
1359 mounted: function mounted() {
1360 var self = this;
1361
1362 $(this.$el).datetimepicker({
1363 dateFormat: 'yy-mm-dd',
1364 timeFormat: "HH:mm:ss",
1365 onClose: this.onClose
1366 });
1367 },
1368
1369 methods: {
1370 onClose: function onClose(date) {
1371 this.$emit('input', date);
1372 }
1373 }
1374 });
1375
1376 Vue.component('weforms-colorpicker', {
1377 template: '<input type="text" v-bind:value="value" />',
1378 props: ['value'],
1379 mounted: function mounted() {
1380 var self = this;
1381
1382 $(this.$el).wpColorPicker({
1383 change: this.onChange
1384 });
1385 },
1386
1387 methods: {
1388 onChange: function onChange(event, ui) {
1389 this.$emit('input', ui.color.toString());
1390 }
1391 }
1392 });
1393
1394 // check if an element is visible in browser viewport
1395 function is_element_in_viewport(el) {
1396 if (typeof jQuery === "function" && el instanceof jQuery) {
1397 el = el[0];
1398 }
1399
1400 var rect = el.getBoundingClientRect();
1401
1402 return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1403 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1404 ;
1405 }
1406
1407 /**
1408 * Vuex Store data
1409 */
1410 var wpuf_form_builder_store = new Vuex.Store({
1411 state: {
1412 post: {},
1413 form_fields: [],
1414 panel_sections: wpuf_form_builder.panel_sections,
1415 field_settings: wpuf_form_builder.field_settings,
1416 notifications: [],
1417 settings: {},
1418 integrations: {},
1419 current_panel: 'form-fields',
1420 editing_field_id: 0 // editing form field id
1421 },
1422
1423 mutations: {
1424 set_form_fields: function set_form_fields(state, form_fields) {
1425 Vue.set(state, 'form_fields', form_fields);
1426 },
1427
1428 set_form_post: function set_form_post(state, post) {
1429 Vue.set(state, 'post', post);
1430 },
1431
1432 set_form_notification: function set_form_notification(state, value) {
1433 Vue.set(state, 'notifications', value);
1434 },
1435
1436 set_form_integrations: function set_form_integrations(state, value) {
1437 Vue.set(state, 'integrations', value);
1438 },
1439
1440 set_form_settings: function set_form_settings(state, value) {
1441 Vue.set(state, 'settings', value);
1442 },
1443
1444 // set the current panel
1445 set_current_panel: function set_current_panel(state, panel) {
1446 if ('field-options' !== state.current_panel && 'field-options' === panel && state.form_fields.length) {
1447 state.editing_field_id = state.form_fields[0].id;
1448 }
1449
1450 state.current_panel = panel;
1451
1452 // reset editing field id
1453 if ('form-fields' === panel) {
1454 state.editing_field_id = 0;
1455 }
1456 },
1457
1458 // add show property to every panel section
1459 panel_add_show_prop: function panel_add_show_prop(state) {
1460 state.panel_sections.map(function (section, index) {
1461 if (!section.hasOwnProperty('show')) {
1462 Vue.set(state.panel_sections[index], 'show', true);
1463 }
1464 });
1465 },
1466
1467 // toggle panel sections
1468 panel_toggle: function panel_toggle(state, index) {
1469 state.panel_sections[index].show = !state.panel_sections[index].show;
1470 },
1471
1472 // open field settings panel
1473 open_field_settings: function open_field_settings(state, field_id) {
1474 var field = state.form_fields.filter(function (item) {
1475 return parseInt(field_id) === parseInt(item.id);
1476 });
1477
1478 if ('field-options' === state.current_panel && field[0].id === state.editing_field_id) {
1479 return;
1480 }
1481
1482 if (field.length) {
1483 state.editing_field_id = 0;
1484 state.current_panel = 'field-options';
1485
1486 setTimeout(function () {
1487 state.editing_field_id = field[0].id;
1488 }, 400);
1489 }
1490 },
1491
1492 update_editing_form_field: function update_editing_form_field(state, payload) {
1493 var i = 0;
1494
1495 for (i = 0; i < state.form_fields.length; i++) {
1496 // check if the editing field exist in normal fields
1497 if (state.form_fields[i].id === parseInt(payload.editing_field_id)) {
1498 state.form_fields[i][payload.field_name] = payload.value;
1499 }
1500
1501 // check if the editing field belong to a column field
1502 if (state.form_fields[i].template === 'column_field') {
1503 var innerColumnFields = state.form_fields[i].inner_fields;
1504
1505 for (var columnFields in innerColumnFields) {
1506 if (innerColumnFields.hasOwnProperty(columnFields)) {
1507 var columnFieldIndex = 0;
1508
1509 while (columnFieldIndex < innerColumnFields[columnFields].length) {
1510 if (innerColumnFields[columnFields][columnFieldIndex].id === parseInt(payload.editing_field_id)) {
1511 innerColumnFields[columnFields][columnFieldIndex][payload.field_name] = payload.value;
1512 }
1513 columnFieldIndex++;
1514 }
1515 }
1516 }
1517 }
1518 }
1519 },
1520
1521 // add new form field element
1522 add_form_field_element: function add_form_field_element(state, payload) {
1523 state.form_fields.splice(payload.toIndex, 0, payload.field);
1524
1525 // bring newly added element into viewport
1526 Vue.nextTick(function () {
1527 var el = $('#form-preview-stage .wpuf-form .field-items').eq(payload.toIndex);
1528
1529 if (el && !is_element_in_viewport(el.get(0))) {
1530 $('#builder-stage section').scrollTo(el, 800, { offset: -50 });
1531 }
1532 });
1533 },
1534
1535 // sorting inside stage
1536 swap_form_field_elements: function swap_form_field_elements(state, payload) {
1537 state.form_fields.swap(payload.fromIndex, payload.toIndex);
1538 },
1539
1540 clone_form_field_element: function clone_form_field_element(state, payload) {
1541 var field = _.find(state.form_fields, function (item) {
1542 return parseInt(item.id) === parseInt(payload.field_id);
1543 });
1544
1545 var clone = $.extend(true, {}, field),
1546 index = parseInt(payload.index) + 1;
1547
1548 clone.id = payload.new_id;
1549 clone.name = clone.name + '_copy';
1550 clone.is_new = true;
1551
1552 state.form_fields.splice(index, 0, clone);
1553 },
1554
1555 // delete a field
1556 delete_form_field_element: function delete_form_field_element(state, index) {
1557 state.current_panel = 'form-fields';
1558 state.form_fields.splice(index, 1);
1559 },
1560
1561 // set fields for a panel section
1562 set_panel_section_fields: function set_panel_section_fields(state, payload) {
1563 var section = _.find(state.panel_sections, function (item) {
1564 return item.id === payload.id;
1565 });
1566
1567 section.fields = payload.fields;
1568 },
1569
1570 // notifications
1571 addNotification: function addNotification(state, payload) {
1572 state.notifications.push(_.clone(payload));
1573 },
1574
1575 deleteNotification: function deleteNotification(state, index) {
1576 state.notifications.splice(index, 1);
1577 },
1578
1579 cloneNotification: function cloneNotification(state, index) {
1580 var clone = $.extend(true, {}, state.notifications[index]);
1581
1582 index = parseInt(index) + 1;
1583 state.notifications.splice(index, 0, clone);
1584 },
1585
1586 // update by it's property
1587 updateNotificationProperty: function updateNotificationProperty(state, payload) {
1588 state.notifications[payload.index][payload.property] = payload.value;
1589 },
1590
1591 updateNotification: function updateNotification(state, payload) {
1592 state.notifications[payload.index] = payload.value;
1593 },
1594
1595 updateIntegration: function updateIntegration(state, payload) {
1596 // console.log(payload);
1597 // console.log(state.integrations[payload.index]);
1598 // state.integrations[payload.index] = payload.value;
1599 Vue.set(state.integrations, payload.index, payload.value);
1600
1601 // state.integrations.splice(payload.index, 0, payload.value);
1602 },
1603
1604 // add new form field element to column field
1605 add_column_inner_field_element: function add_column_inner_field_element(state, payload) {
1606 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1607 return field.id === payload.toWhichColumnField;
1608 });
1609
1610 if (state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn] === undefined) {
1611 state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn] = [];
1612 }
1613
1614 if (state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn] !== undefined) {
1615 var innerColumnFields = state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn];
1616
1617 if (innerColumnFields.filter(function (innerField) {
1618 return innerField.name === payload.field.name;
1619 }).length <= 0) {
1620 state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn].splice(payload.toIndex, 0, payload.field);
1621 }
1622 }
1623 },
1624
1625 move_column_inner_fields: function move_column_inner_fields(state, payload) {
1626 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1627 return field.id === payload.field_id;
1628 }),
1629 innerFields = payload.inner_fields,
1630 mergedFields = [];
1631
1632 Object.keys(innerFields).forEach(function (column) {
1633 // clear column-1, column-2 and column-3 fields if move_to specified column-1
1634 // add column-1, column-2 and column-3 fields to mergedFields, later mergedFields will move to column-1 field
1635 if (payload.move_to === "column-1") {
1636 innerFields[column].forEach(function (field) {
1637 mergedFields.push(field);
1638 });
1639
1640 // clear current column inner fields
1641 state.form_fields[columnFieldIndex].inner_fields[column].splice(0, innerFields[column].length);
1642 }
1643
1644 // clear column-2 and column-3 fields if move_to specified column-2
1645 // add column-2 and column-3 fields to mergedFields, later mergedFields will move to column-2 field
1646 if (payload.move_to === "column-2") {
1647 if (column === "column-2" || column === "column-3") {
1648 innerFields[column].forEach(function (field) {
1649 mergedFields.push(field);
1650 });
1651
1652 // clear current column inner fields
1653 state.form_fields[columnFieldIndex].inner_fields[column].splice(0, innerFields[column].length);
1654 }
1655 }
1656 });
1657
1658 // move inner fields to specified column
1659 if (mergedFields.length !== 0) {
1660 mergedFields.forEach(function (field) {
1661 state.form_fields[columnFieldIndex].inner_fields[payload.move_to].splice(0, 0, field);
1662 });
1663 }
1664 },
1665
1666 // sorting inside column field
1667 swap_column_field_elements: function swap_column_field_elements(state, payload) {
1668 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1669 return field.id === payload.field_id;
1670 }),
1671 fieldObj = state.form_fields[columnFieldIndex].inner_fields[payload.fromColumn][payload.fromIndex];
1672
1673 if (payload.fromColumn !== payload.toColumn) {
1674 // add the field object to the target column
1675 state.form_fields[columnFieldIndex].inner_fields[payload.toColumn].splice(payload.toIndex, 0, fieldObj);
1676
1677 // remove the field index from the source column
1678 state.form_fields[columnFieldIndex].inner_fields[payload.fromColumn].splice(payload.fromIndex, 1);
1679 } else {
1680 state.form_fields[columnFieldIndex].inner_fields[payload.toColumn].swap(payload.fromIndex, payload.toIndex);
1681 }
1682 },
1683
1684 // open field settings panel
1685 open_column_field_settings: function open_column_field_settings(state, payload) {
1686 var field = payload.column_field;
1687
1688 if ('field-options' === state.current_panel && field.id === state.editing_field_id) {
1689 return;
1690 }
1691
1692 if (field) {
1693 state.editing_field_id = 0;
1694 state.current_panel = 'field-options';
1695 state.editing_field_type = 'column_field';
1696 state.editing_column_field_id = payload.field_id;
1697 state.edting_field_column = payload.column;
1698 state.editing_inner_field_index = payload.index;
1699
1700 setTimeout(function () {
1701 state.editing_field_id = field.id;
1702 }, 400);
1703 }
1704 },
1705
1706 clone_column_field_element: function clone_column_field_element(state, payload) {
1707 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1708 return field.id === payload.field_id;
1709 });
1710
1711 var field = _.find(state.form_fields[columnFieldIndex].inner_fields[payload.toColumn], function (item) {
1712 return parseInt(item.id) === parseInt(payload.column_field_id);
1713 });
1714
1715 var clone = $.extend(true, {}, field),
1716 index = parseInt(payload.index) + 1;
1717
1718 clone.id = payload.new_id;
1719 clone.name = clone.name + '_copy';
1720 clone.is_new = true;
1721
1722 state.form_fields[columnFieldIndex].inner_fields[payload.toColumn].splice(index, 0, clone);
1723 },
1724
1725 // delete a column field
1726 delete_column_field_element: function delete_column_field_element(state, payload) {
1727 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1728 return field.id === payload.field_id;
1729 });
1730
1731 state.current_panel = 'form-fields';
1732 state.form_fields[columnFieldIndex].inner_fields[payload.fromColumn].splice(payload.index, 1);
1733 }
1734 }
1735 });
1736
1737 // 1. Define route components.
1738 weForms.routeComponents.FormHome = { template: '<div><router-view class="child"></router-view></div>' };
1739 weForms.routeComponents.SingleForm = { template: '#tmpl-wpuf-form-editor' };
1740 weForms.routeComponents.FormEntriesHome = {
1741 template: '<div><router-view class="grand-child"></router-view></div>'
1742 };
1743
1744 /**
1745 * Parse the route array and bind required components
1746 *
1747 * This changes the weForms.routes array and changes the components
1748 * so we can use weForms.routeComponents.{compontent} component.
1749 *
1750 * @param {array} routes
1751 *
1752 * @return {void}
1753 */
1754 function parseRouteComponent(routes) {
1755
1756 for (var i = 0; i < routes.length; i++) {
1757 if (_typeof(routes[i].children) === 'object') {
1758
1759 parseRouteComponent(routes[i].children);
1760
1761 if (typeof routes[i].component !== 'undefined') {
1762 routes[i].component = weForms.routeComponents[routes[i].component];
1763 }
1764 } else {
1765 routes[i].component = weForms.routeComponents[routes[i].component];
1766 }
1767 }
1768 }
1769
1770 // mutate the localized array
1771 parseRouteComponent(weForms.routes);
1772
1773 // 3. Create the router instance and pass the `routes` option
1774 var router = new VueRouter({
1775 routes: weForms.routes,
1776 scrollBehavior: function scrollBehavior(to, from, savedPosition) {
1777 if (savedPosition) {
1778 return savedPosition;
1779 } else {
1780 return { x: 0, y: 0 };
1781 }
1782 }
1783 });
1784
1785 window.weFormsBuilderisDirty = false;
1786
1787 router.beforeEach(function (to, from, next) {
1788 // show warning if builder has unsaved changes
1789 if (window.weFormsBuilderisDirty) {
1790 if (confirm(wpuf_form_builder.i18n.unsaved_changes + ' ' + wpuf_form_builder.i18n.areYouSureToLeave)) {
1791 window.weFormsBuilderisDirty = false;
1792 } else {
1793 next(from.path);
1794 return false;
1795 }
1796 }
1797
1798 next();
1799 });
1800
1801 weForms.validators = {
1802 is_recaptcha_v2: function is_recaptcha_v2() {
1803 return weForms.settings.recaptcha.type === 'v2';
1804 }
1805 };
1806
1807 var app = new Vue({
1808 router: router,
1809 store: wpuf_form_builder_store
1810 }).$mount('#wpuf-contact-form-app');
1811
1812 // Admin menu hack
1813 var menuRoot = $('#toplevel_page_weforms');
1814
1815 menuRoot.on('click', 'a', function () {
1816 var self = $(this);
1817
1818 $('ul.wp-submenu li', menuRoot).removeClass('current');
1819
1820 if (self.hasClass('wp-has-submenu')) {
1821 $('li.wp-first-item', menuRoot).addClass('current');
1822 } else {
1823 self.parents('li').addClass('current');
1824 }
1825 });
1826
1827 $(function () {
1828
1829 // select the current sub menu on page load
1830 var current_url = window.location.href;
1831 var current_path = current_url.substr(current_url.indexOf('admin.php'));
1832
1833 $('ul.wp-submenu a', menuRoot).each(function (index, el) {
1834 if ($(el).attr('href') === current_path) {
1835 $(el).parent().addClass('current');
1836 return;
1837 }
1838 });
1839 });
1840 })(jQuery);
1841