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

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