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

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