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

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