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

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