PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.4
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.4
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / assets / js / spa-app.js

spa-app.js in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.4.4, at assets/js/spa-app.js

1,844 lines 64.6 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.4.1
31 Generated: 2019-11-15 (1573811026161)
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 bulkDeleteAction: 'weforms_form_delete_bulk'
733 };
734 },
735 created: function created() {
736 this.fetchData();
737 },
738 computed: {
739 is_pro: function is_pro() {
740 return 'true' === weForms.is_pro;
741 },
742 has_payment: function has_payment() {
743 return 'true' === weForms.has_payment;
744 }
745 },
746
747 methods: {
748 fetchData: function fetchData() {
749 var self = this;
750
751 this.loading = true;
752
753 wp.ajax.send('weforms_form_list', {
754 data: {
755 _wpnonce: weForms.nonce,
756 page: self.currentPage
757 },
758 success: function success(response) {
759 self.loading = false;
760 self.items = response.forms;
761 self.totalItems = response.meta.total;
762 self.totalPage = response.meta.pages;
763 },
764 error: function error(_error8) {
765 self.loading = false;
766 alert(_error8);
767 }
768 });
769 },
770
771 deleteForm: function deleteForm(index) {
772 var self = this;
773
774 if (confirm('Are you sure?')) {
775 self.loading = true;
776
777 wp.ajax.send('weforms_form_delete', {
778 data: {
779 form_id: this.items[index].id,
780 _wpnonce: weForms.nonce
781 },
782 success: function success(response) {
783 self.items.splice(index, 1);
784 self.loading = false;
785 },
786 error: function error(_error9) {
787 alert(_error9);
788 self.loading = false;
789 }
790 });
791 }
792 },
793
794 duplicate: function duplicate(form_id, index) {
795 var self = this;
796
797 this.loading = true;
798
799 wp.ajax.send('weforms_form_duplicate', {
800 data: {
801 form_id: form_id,
802 _wpnonce: weForms.nonce
803 },
804 success: function success(response) {
805 self.items.splice(0, 0, response);
806 self.loading = false;
807 },
808 error: function error(_error10) {
809 alert(_error10);
810 self.loading = false;
811 }
812 });
813 },
814
815 handleBulkAction: function handleBulkAction() {
816 if ('-1' === this.bulkAction) {
817 alert('Please chose a bulk action to perform');
818 return;
819 }
820
821 if ('delete' === this.bulkAction) {
822 if (!this.checkedItems.length) {
823 alert('Please select atleast one form to delete.');
824 return;
825 }
826
827 if (confirm('Are you sure to delete the forms?')) {
828 this.deleteBulk();
829 }
830 }
831 },
832
833 isPendingForm: function isPendingForm(scheduleStart) {
834 var currentTime = Math.round(new Date().getTime() / 1000),
835 startTime = Math.round(new Date(scheduleStart).getTime() / 1000);
836
837 if (currentTime < startTime) {
838 return true;
839 }
840 return false;
841 },
842
843 isExpiredForm: function isExpiredForm(scheduleEnd) {
844 var currentTime = Math.round(new Date().getTime() / 1000),
845 endTime = Math.round(new Date(scheduleEnd).getTime() / 1000);
846
847 if (currentTime > endTime) {
848 return true;
849 }
850 return false;
851 },
852
853 isOpenForm: function isOpenForm(scheduleStart, scheduleEnd) {
854 var currentTime = Math.round(new Date().getTime() / 1000),
855 startTime = Math.round(new Date(scheduleStart).getTime() / 1000),
856 endTime = Math.round(new Date(scheduleEnd).getTime() / 1000);
857
858 if (currentTime > startTime && currentTime < endTime) {
859 return true;
860 }
861 return false;
862 },
863
864 isFormStatusClosed: function isFormStatusClosed(formSettings, entries) {
865 if (formSettings.schedule_form === 'true' && this.isPendingForm(formSettings.schedule_start)) {
866 return true;
867 }
868
869 if (formSettings.schedule_form === 'true' && this.isExpiredForm(formSettings.schedule_end)) {
870 return true;
871 }
872
873 if (formSettings.limit_entries === 'true' && entries >= formSettings.limit_number) {
874 return true;
875 }
876 return;
877 },
878
879 formatTime: function formatTime(time) {
880 var date = new Date(time),
881 month = date.toLocaleString('en-us', { month: 'short' });
882
883 return month + ' ' + date.getDate() + ', ' + date.getFullYear();
884 }
885 }
886 });
887 /* ./assets/spa/components/form-payments/index.js */
888 weForms.routeComponents.FormPayments = {
889 props: {
890 id: [String, Number]
891 },
892 template: '#tmpl-wpuf-form-payments',
893 data: function data() {
894 return {
895 form_title: 'Loading...'
896 };
897 }
898 };
899
900 /* ./assets/spa/components/home-page/index.js */
901 weForms.routeComponents.Home = {
902 template: '#tmpl-wpuf-home-page',
903
904 data: function data() {
905 return {
906 showTemplateModal: false
907 };
908 },
909
910 methods: {
911 displayModal: function displayModal() {
912 this.showTemplateModal = true;
913 },
914
915 closeModal: function closeModal() {
916 this.showTemplateModal = false;
917 }
918 }
919 };
920
921 /* ./assets/spa/components/tools/index.js */
922 weForms.routeComponents.Tools = {
923 template: '#tmpl-wpuf-tools',
924 mixins: [weForms.mixins.Tabs, weForms.mixins.Loading],
925 data: function data() {
926 return {
927 activeTab: 'export',
928 exportType: 'all',
929 loading: false,
930 forms: [],
931 importButton: 'Import',
932 currentStatus: 0,
933 responseMessage: '',
934 logs: [],
935 ximport: {
936 current: '',
937 title: '',
938 action: '',
939 message: '',
940 type: 'updated',
941 refs: {}
942 }
943 };
944 },
945
946 computed: {
947
948 isInitial: function isInitial() {
949 return this.currentStatus === 0;
950 },
951
952 isSaving: function isSaving() {
953 return this.currentStatus === 1;
954 },
955
956 isSuccess: function isSuccess() {
957 return this.currentStatus === 2;
958 },
959
960 isFailed: function isFailed() {
961 return this.currentStatus === 3;
962 },
963
964 hasRefs: function hasRefs() {
965 return Object.keys(this.ximport.refs).length;
966 },
967 hasLogs: function hasLogs() {
968 return Object.keys(this.logs).length;
969 }
970 },
971
972 created: function created() {
973 this.fetchData();
974 this.fetchLogs();
975 },
976
977 methods: {
978 fetchLogs: function fetchLogs(target) {
979 var self = this;
980
981 self.startLoading(target);
982
983 wp.ajax.send('weforms_read_logs', {
984 data: {
985 _wpnonce: weForms.nonce
986 },
987 success: function success(response) {
988 self.stopLoading(target);
989 self.logs = response;
990 }, error: function error() {
991 self.stopLoading(target);
992 self.logs = [];
993 }
994 });
995 },
996 deleteLogs: function deleteLogs(target) {
997 var self = this;
998
999 if (confirm('Are you sure to clear the log file?')) {
1000
1001 self.startLoading(target);
1002
1003 wp.ajax.send('weforms_delete_logs', {
1004 data: {
1005 _wpnonce: weForms.nonce
1006 },
1007 success: function success(response) {
1008 self.logs = [];
1009 self.stopLoading(target);
1010 self.fetchLogs();
1011 },
1012 error: function error(response) {
1013 self.logs = [];
1014 self.stopLoading(target);
1015 self.fetchLogs();
1016 }
1017 });
1018 }
1019 },
1020 stopLoading: function stopLoading(target) {
1021 target = $(target);
1022
1023 if (target.is('button')) {
1024 target.removeClass('updating-message').find('span').show();
1025 } else if (target.is('span')) {
1026 target.show().parent().removeClass('updating-message');
1027 }
1028 },
1029 startLoading: function startLoading(target) {
1030
1031 target = $(target);
1032
1033 if (target.is('button')) {
1034 target.addClass('updating-message').find('span').hide();
1035 } else if (target.is('span')) {
1036 target.hide().parent().addClass('updating-message');
1037 }
1038 },
1039 fetchData: function fetchData() {
1040 var self = this;
1041
1042 this.loading = true;
1043
1044 wp.ajax.send('weforms_form_names', {
1045 data: {
1046 _wpnonce: weForms.nonce
1047 },
1048 success: function success(response) {
1049 // console.log(response);
1050 self.loading = false;
1051 self.forms = response;
1052 },
1053 error: function error(_error11) {
1054 self.loading = false;
1055 alert(_error11);
1056 }
1057 });
1058 },
1059
1060 importForm: function importForm(fieldName, fileList, event) {
1061 if (!fileList.length) {
1062 return;
1063 }
1064
1065 var formData = new FormData();
1066 var self = this;
1067
1068 formData.append(fieldName, fileList[0], fileList[0].name);
1069 formData.append('action', 'weforms_import_form');
1070 formData.append('_wpnonce', weForms.nonce);
1071
1072 self.currentStatus = 1;
1073
1074 $.ajax({
1075 type: "POST",
1076 url: window.ajaxurl,
1077 data: formData,
1078 processData: false,
1079 contentType: false,
1080 success: function success(response) {
1081 self.responseMessage = response.data;
1082
1083 if (response.success) {
1084 self.currentStatus = 2;
1085 } else {
1086 self.currentStatus = 3;
1087 }
1088
1089 // reset the value
1090 $(event.target).val('');
1091 },
1092
1093 error: function error(errResponse) {
1094 console.log(errResponse);
1095 self.currentStatus = 3;
1096 },
1097
1098 complete: function complete() {
1099 $(event.target).val('');
1100 }
1101 });
1102 },
1103
1104 importx: function importx(target, plugin) {
1105 var button = $(target);
1106 var self = this;
1107
1108 self.ximport.current = plugin;
1109 button.addClass('updating-message').text(button.data('importing'));
1110
1111 wp.ajax.send('weforms_import_xforms_' + plugin, {
1112 data: {
1113 _wpnonce: weForms.nonce
1114 },
1115
1116 success: function success(response) {
1117 self.ximport.title = response.title;
1118 self.ximport.message = response.message;
1119 self.ximport.action = response.action;
1120 self.ximport.refs = response.refs;
1121 },
1122
1123 error: function error(_error12) {
1124 alert(_error12.message);
1125 },
1126
1127 complete: function complete() {
1128 button.removeClass('updating-message').text(button.data('original'));
1129 }
1130 });
1131 },
1132
1133 replaceX: function replaceX(target, type) {
1134 var button = $(target);
1135 var self = this;
1136
1137 button.addClass('updating-message');
1138
1139 wp.ajax.send('weforms_import_xreplace_' + self.ximport.current, {
1140 data: {
1141 type: type,
1142 _wpnonce: weForms.nonce
1143 },
1144
1145 success: function success(response) {
1146 if ('replace' === button.data('type')) {
1147 alert(response);
1148 }
1149 },
1150
1151 error: function error(_error13) {
1152 alert(_error13);
1153 },
1154
1155 complete: function complete() {
1156 self.ximport.current = '';
1157 self.ximport.title = '';
1158 }
1159 });
1160 }
1161 }
1162 };
1163
1164 /* ./assets/spa/components/transactions/index.js */
1165 weForms.routeComponents.Transactions = {
1166 template: '#tmpl-wpuf-transactions',
1167 data: function data() {
1168 return {
1169 selected: 0,
1170 no_transactions: false,
1171 forms: {},
1172 form_title: 'Loading...'
1173 };
1174 },
1175
1176 created: function created() {
1177 this.get_forms();
1178 },
1179
1180 methods: {
1181 get_forms: function get_forms() {
1182 var self = this;
1183
1184 wp.ajax.send('weforms_form_list', {
1185 data: {
1186 _wpnonce: weForms.nonce,
1187 page: self.currentPage,
1188 filter: 'transactions'
1189 },
1190 success: function success(response) {
1191
1192 if (Object.keys(response.forms).length) {
1193 self.forms = response.forms;
1194 self.selected = self.forms[Object.keys(self.forms)[0]].id;
1195 } else {
1196 self.form_title = 'No transaction found';
1197 self.no_transactions = true;
1198 }
1199 },
1200 error: function error(_error14) {
1201 alert(_error14);
1202 }
1203 });
1204 }
1205 }
1206 };
1207
1208 /* ./assets/spa/components/weforms-page-help/index.js */
1209 weForms.routeComponents.Help = {
1210 template: '#tmpl-wpuf-weforms-page-help'
1211 };
1212 /* ./assets/spa/components/weforms-premium/index.js */
1213 weForms.routeComponents.Premium = {
1214 template: '#tmpl-wpuf-weforms-premium',
1215 data: function data() {
1216 return {
1217 showModal: false
1218 };
1219 }
1220 };
1221 /* ./assets/spa/components/weforms-settings/index.js */
1222 weForms.routeComponents.Settings = {
1223 template: '#tmpl-wpuf-weforms-settings',
1224 mixins: [weForms.mixins.Loading, weForms.mixins.Cookie],
1225 data: function data() {
1226 return {
1227 loading: false,
1228 settings: {
1229 email_gateway: 'wordpress',
1230 credit: false,
1231 permission: 'manage_options',
1232 gateways: {
1233 sendgrid: '',
1234 mailgun: '',
1235 sparkpost: ''
1236 },
1237 recaptcha: {
1238 type: 'v2',
1239 key: '',
1240 secret: ''
1241 }
1242 },
1243
1244 activeTab: 'general'
1245 };
1246 },
1247
1248 computed: {
1249
1250 is_pro: function is_pro() {
1251 return 'true' === weForms.is_pro;
1252 }
1253 },
1254
1255 created: function created() {
1256 this.fetchSettings();
1257
1258 if (this.getCookie('weforms_settings_active_tab')) {
1259 this.activeTab = this.getCookie('weforms_settings_active_tab');
1260 }
1261 },
1262
1263 methods: {
1264
1265 makeActive: function makeActive(val) {
1266 this.activeTab = val;
1267 },
1268
1269 isActiveTab: function isActiveTab(val) {
1270 return this.activeTab === val;
1271 },
1272
1273 fetchSettings: function fetchSettings() {
1274 var self = this;
1275
1276 self.loading = true;
1277
1278 wp.ajax.send('weforms_get_settings', {
1279 data: {
1280 _wpnonce: weForms.nonce
1281 },
1282
1283 success: function success(response) {
1284
1285 if (response === undefined) {
1286 return;
1287 }
1288
1289 // set defaults if undefined
1290 $.each(self.settings, function (key, value) {
1291 if (response[key] === undefined) {
1292 response[key] = value;
1293 }
1294 });
1295
1296 self.settings = response;
1297 },
1298
1299 complete: function complete() {
1300 self.loading = false;
1301 }
1302 });
1303 },
1304
1305 saveSettings: function saveSettings(target) {
1306 var self = this;
1307
1308 $(target).addClass('updating-message');
1309
1310 wp.ajax.send('weforms_save_settings', {
1311 data: {
1312 settings: JSON.stringify(self.settings),
1313 _wpnonce: weForms.nonce
1314 },
1315
1316 success: function success(response) {
1317 toastr.options.timeOut = 1000;
1318 toastr.success('Settings has been updated');
1319 },
1320
1321 error: function error(_error15) {
1322 console.log(_error15);
1323 },
1324
1325 complete: function complete() {
1326 $(target).removeClass('updating-message');
1327 }
1328 });
1329 },
1330
1331 post: function post(action, data, _success) {
1332 data = data || {};
1333 _success = _success || function () {};
1334 data._wpnonce = weForms.nonce;
1335
1336 wp.ajax.send(action, {
1337 data: data,
1338
1339 success: function success(response) {
1340 _success(response);
1341 },
1342
1343 error: function error(_error16) {
1344 console.log(_error16);
1345 },
1346
1347 complete: function complete() {}
1348 });
1349 }
1350 },
1351
1352 watch: {
1353 activeTab: function activeTab(value) {
1354 this.setCookie('weforms_settings_active_tab', value, '365');
1355 }
1356 }
1357 };
1358 /* ./assets/spa/app.js */
1359 if (!Array.prototype.hasOwnProperty('swap')) {
1360 Array.prototype.swap = function (from, to) {
1361 this.splice(to, 0, this.splice(from, 1)[0]);
1362 };
1363 }
1364
1365 Vue.component('datepicker', {
1366 template: '<input type="text" v-bind:value="value" />',
1367 props: ['value'],
1368 mounted: function mounted() {
1369 var self = this;
1370
1371 $(this.$el).datetimepicker({
1372 dateFormat: 'yy-mm-dd',
1373 timeFormat: "HH:mm:ss",
1374 onClose: this.onClose
1375 });
1376 },
1377
1378 methods: {
1379 onClose: function onClose(date) {
1380 this.$emit('input', date);
1381 }
1382 }
1383 });
1384
1385 Vue.component('weforms-colorpicker', {
1386 template: '<input type="text" v-bind:value="value" />',
1387 props: ['value'],
1388 mounted: function mounted() {
1389 var self = this;
1390
1391 $(this.$el).wpColorPicker({
1392 change: this.onChange
1393 });
1394 },
1395
1396 methods: {
1397 onChange: function onChange(event, ui) {
1398 this.$emit('input', ui.color.toString());
1399 }
1400 }
1401 });
1402
1403 // check if an element is visible in browser viewport
1404 function is_element_in_viewport(el) {
1405 if (typeof jQuery === "function" && el instanceof jQuery) {
1406 el = el[0];
1407 }
1408
1409 var rect = el.getBoundingClientRect();
1410
1411 return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1412 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1413 ;
1414 }
1415
1416 /**
1417 * Vuex Store data
1418 */
1419 var wpuf_form_builder_store = new Vuex.Store({
1420 state: {
1421 post: {},
1422 form_fields: [],
1423 panel_sections: wpuf_form_builder.panel_sections,
1424 field_settings: wpuf_form_builder.field_settings,
1425 notifications: [],
1426 settings: {},
1427 integrations: {},
1428 current_panel: 'form-fields',
1429 editing_field_id: 0 // editing form field id
1430 },
1431
1432 mutations: {
1433 set_form_fields: function set_form_fields(state, form_fields) {
1434 Vue.set(state, 'form_fields', form_fields);
1435 },
1436
1437 set_form_post: function set_form_post(state, post) {
1438 Vue.set(state, 'post', post);
1439 },
1440
1441 set_form_notification: function set_form_notification(state, value) {
1442 Vue.set(state, 'notifications', value);
1443 },
1444
1445 set_form_integrations: function set_form_integrations(state, value) {
1446 Vue.set(state, 'integrations', value);
1447 },
1448
1449 set_form_settings: function set_form_settings(state, value) {
1450 Vue.set(state, 'settings', value);
1451 },
1452
1453 // set the current panel
1454 set_current_panel: function set_current_panel(state, panel) {
1455 if ('field-options' !== state.current_panel && 'field-options' === panel && state.form_fields.length) {
1456 state.editing_field_id = state.form_fields[0].id;
1457 }
1458
1459 state.current_panel = panel;
1460
1461 // reset editing field id
1462 if ('form-fields' === panel) {
1463 state.editing_field_id = 0;
1464 }
1465 },
1466
1467 // add show property to every panel section
1468 panel_add_show_prop: function panel_add_show_prop(state) {
1469 state.panel_sections.map(function (section, index) {
1470 if (!section.hasOwnProperty('show')) {
1471 Vue.set(state.panel_sections[index], 'show', true);
1472 }
1473 });
1474 },
1475
1476 // toggle panel sections
1477 panel_toggle: function panel_toggle(state, index) {
1478 state.panel_sections[index].show = !state.panel_sections[index].show;
1479 },
1480
1481 // open field settings panel
1482 open_field_settings: function open_field_settings(state, field_id) {
1483 var field = state.form_fields.filter(function (item) {
1484 return parseInt(field_id) === parseInt(item.id);
1485 });
1486
1487 if ('field-options' === state.current_panel && field[0].id === state.editing_field_id) {
1488 return;
1489 }
1490
1491 if (field.length) {
1492 state.editing_field_id = 0;
1493 state.current_panel = 'field-options';
1494
1495 setTimeout(function () {
1496 state.editing_field_id = field[0].id;
1497 }, 400);
1498 }
1499 },
1500
1501 update_editing_form_field: function update_editing_form_field(state, payload) {
1502 var i = 0;
1503
1504 for (i = 0; i < state.form_fields.length; i++) {
1505 // check if the editing field exist in normal fields
1506 if (state.form_fields[i].id === parseInt(payload.editing_field_id)) {
1507 state.form_fields[i][payload.field_name] = payload.value;
1508 }
1509
1510 // check if the editing field belong to a column field
1511 if (state.form_fields[i].template === 'column_field') {
1512 var innerColumnFields = state.form_fields[i].inner_fields;
1513
1514 for (var columnFields in innerColumnFields) {
1515 if (innerColumnFields.hasOwnProperty(columnFields)) {
1516 var columnFieldIndex = 0;
1517
1518 while (columnFieldIndex < innerColumnFields[columnFields].length) {
1519 if (innerColumnFields[columnFields][columnFieldIndex].id === parseInt(payload.editing_field_id)) {
1520 innerColumnFields[columnFields][columnFieldIndex][payload.field_name] = payload.value;
1521 }
1522 columnFieldIndex++;
1523 }
1524 }
1525 }
1526 }
1527 }
1528 },
1529
1530 // add new form field element
1531 add_form_field_element: function add_form_field_element(state, payload) {
1532 state.form_fields.splice(payload.toIndex, 0, payload.field);
1533
1534 // bring newly added element into viewport
1535 Vue.nextTick(function () {
1536 var el = $('#form-preview-stage .wpuf-form .field-items').eq(payload.toIndex);
1537
1538 if (el && !is_element_in_viewport(el.get(0))) {
1539 $('#builder-stage section').scrollTo(el, 800, { offset: -50 });
1540 }
1541 });
1542 },
1543
1544 // sorting inside stage
1545 swap_form_field_elements: function swap_form_field_elements(state, payload) {
1546 state.form_fields.swap(payload.fromIndex, payload.toIndex);
1547 },
1548
1549 clone_form_field_element: function clone_form_field_element(state, payload) {
1550 var field = _.find(state.form_fields, function (item) {
1551 return parseInt(item.id) === parseInt(payload.field_id);
1552 });
1553
1554 var clone = $.extend(true, {}, field),
1555 index = parseInt(payload.index) + 1;
1556
1557 clone.id = payload.new_id;
1558 clone.name = clone.name + '_copy';
1559 clone.is_new = true;
1560
1561 state.form_fields.splice(index, 0, clone);
1562 },
1563
1564 // delete a field
1565 delete_form_field_element: function delete_form_field_element(state, index) {
1566 state.current_panel = 'form-fields';
1567 state.form_fields.splice(index, 1);
1568 },
1569
1570 // set fields for a panel section
1571 set_panel_section_fields: function set_panel_section_fields(state, payload) {
1572 var section = _.find(state.panel_sections, function (item) {
1573 return item.id === payload.id;
1574 });
1575
1576 section.fields = payload.fields;
1577 },
1578
1579 // notifications
1580 addNotification: function addNotification(state, payload) {
1581 state.notifications.push(_.clone(payload));
1582 },
1583
1584 deleteNotification: function deleteNotification(state, index) {
1585 state.notifications.splice(index, 1);
1586 },
1587
1588 cloneNotification: function cloneNotification(state, index) {
1589 var clone = $.extend(true, {}, state.notifications[index]);
1590
1591 index = parseInt(index) + 1;
1592 state.notifications.splice(index, 0, clone);
1593 },
1594
1595 // update by it's property
1596 updateNotificationProperty: function updateNotificationProperty(state, payload) {
1597 state.notifications[payload.index][payload.property] = payload.value;
1598 },
1599
1600 updateNotification: function updateNotification(state, payload) {
1601 state.notifications[payload.index] = payload.value;
1602 },
1603
1604 updateIntegration: function updateIntegration(state, payload) {
1605 // console.log(payload);
1606 // console.log(state.integrations[payload.index]);
1607 // state.integrations[payload.index] = payload.value;
1608 Vue.set(state.integrations, payload.index, payload.value);
1609
1610 // state.integrations.splice(payload.index, 0, payload.value);
1611 },
1612
1613 // add new form field element to column field
1614 add_column_inner_field_element: function add_column_inner_field_element(state, payload) {
1615 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1616 return field.id === payload.toWhichColumnField;
1617 });
1618
1619 if (state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn] === undefined) {
1620 state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn] = [];
1621 }
1622
1623 if (state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn] !== undefined) {
1624 var innerColumnFields = state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn];
1625
1626 if (innerColumnFields.filter(function (innerField) {
1627 return innerField.name === payload.field.name;
1628 }).length <= 0) {
1629 state.form_fields[columnFieldIndex].inner_fields[payload.toWhichColumn].splice(payload.toIndex, 0, payload.field);
1630 }
1631 }
1632 },
1633
1634 move_column_inner_fields: function move_column_inner_fields(state, payload) {
1635 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1636 return field.id === payload.field_id;
1637 }),
1638 innerFields = payload.inner_fields,
1639 mergedFields = [];
1640
1641 Object.keys(innerFields).forEach(function (column) {
1642 // clear column-1, column-2 and column-3 fields if move_to specified column-1
1643 // add column-1, column-2 and column-3 fields to mergedFields, later mergedFields will move to column-1 field
1644 if (payload.move_to === "column-1") {
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 // clear column-2 and column-3 fields if move_to specified column-2
1654 // add column-2 and column-3 fields to mergedFields, later mergedFields will move to column-2 field
1655 if (payload.move_to === "column-2") {
1656 if (column === "column-2" || column === "column-3") {
1657 innerFields[column].forEach(function (field) {
1658 mergedFields.push(field);
1659 });
1660
1661 // clear current column inner fields
1662 state.form_fields[columnFieldIndex].inner_fields[column].splice(0, innerFields[column].length);
1663 }
1664 }
1665 });
1666
1667 // move inner fields to specified column
1668 if (mergedFields.length !== 0) {
1669 mergedFields.forEach(function (field) {
1670 state.form_fields[columnFieldIndex].inner_fields[payload.move_to].splice(0, 0, field);
1671 });
1672 }
1673 },
1674
1675 // sorting inside column field
1676 swap_column_field_elements: function swap_column_field_elements(state, payload) {
1677 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1678 return field.id === payload.field_id;
1679 }),
1680 fieldObj = state.form_fields[columnFieldIndex].inner_fields[payload.fromColumn][payload.fromIndex];
1681
1682 if (payload.fromColumn !== payload.toColumn) {
1683 // add the field object to the target column
1684 state.form_fields[columnFieldIndex].inner_fields[payload.toColumn].splice(payload.toIndex, 0, fieldObj);
1685
1686 // remove the field index from the source column
1687 state.form_fields[columnFieldIndex].inner_fields[payload.fromColumn].splice(payload.fromIndex, 1);
1688 } else {
1689 state.form_fields[columnFieldIndex].inner_fields[payload.toColumn].swap(payload.fromIndex, payload.toIndex);
1690 }
1691 },
1692
1693 // open field settings panel
1694 open_column_field_settings: function open_column_field_settings(state, payload) {
1695 var field = payload.column_field;
1696
1697 if ('field-options' === state.current_panel && field.id === state.editing_field_id) {
1698 return;
1699 }
1700
1701 if (field) {
1702 state.editing_field_id = 0;
1703 state.current_panel = 'field-options';
1704 state.editing_field_type = 'column_field';
1705 state.editing_column_field_id = payload.field_id;
1706 state.edting_field_column = payload.column;
1707 state.editing_inner_field_index = payload.index;
1708
1709 setTimeout(function () {
1710 state.editing_field_id = field.id;
1711 }, 400);
1712 }
1713 },
1714
1715 clone_column_field_element: function clone_column_field_element(state, payload) {
1716 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1717 return field.id === payload.field_id;
1718 });
1719
1720 var field = _.find(state.form_fields[columnFieldIndex].inner_fields[payload.toColumn], function (item) {
1721 return parseInt(item.id) === parseInt(payload.column_field_id);
1722 });
1723
1724 var clone = $.extend(true, {}, field),
1725 index = parseInt(payload.index) + 1;
1726
1727 clone.id = payload.new_id;
1728 clone.name = clone.name + '_copy';
1729 clone.is_new = true;
1730
1731 state.form_fields[columnFieldIndex].inner_fields[payload.toColumn].splice(index, 0, clone);
1732 },
1733
1734 // delete a column field
1735 delete_column_field_element: function delete_column_field_element(state, payload) {
1736 var columnFieldIndex = state.form_fields.findIndex(function (field) {
1737 return field.id === payload.field_id;
1738 });
1739
1740 state.current_panel = 'form-fields';
1741 state.form_fields[columnFieldIndex].inner_fields[payload.fromColumn].splice(payload.index, 1);
1742 }
1743 }
1744 });
1745
1746 // 1. Define route components.
1747 weForms.routeComponents.FormHome = { template: '<div><router-view class="child"></router-view></div>' };
1748 weForms.routeComponents.SingleForm = { template: '#tmpl-wpuf-form-editor' };
1749 weForms.routeComponents.FormEntriesHome = {
1750 template: '<div><router-view class="grand-child"></router-view></div>'
1751 };
1752
1753 /**
1754 * Parse the route array and bind required components
1755 *
1756 * This changes the weForms.routes array and changes the components
1757 * so we can use weForms.routeComponents.{compontent} component.
1758 *
1759 * @param {array} routes
1760 *
1761 * @return {void}
1762 */
1763 function parseRouteComponent(routes) {
1764
1765 for (var i = 0; i < routes.length; i++) {
1766 if (_typeof(routes[i].children) === 'object') {
1767
1768 parseRouteComponent(routes[i].children);
1769
1770 if (typeof routes[i].component !== 'undefined') {
1771 routes[i].component = weForms.routeComponents[routes[i].component];
1772 }
1773 } else {
1774 routes[i].component = weForms.routeComponents[routes[i].component];
1775 }
1776 }
1777 }
1778
1779 // mutate the localized array
1780 parseRouteComponent(weForms.routes);
1781
1782 // 3. Create the router instance and pass the `routes` option
1783 var router = new VueRouter({
1784 routes: weForms.routes,
1785 scrollBehavior: function scrollBehavior(to, from, savedPosition) {
1786 if (savedPosition) {
1787 return savedPosition;
1788 } else {
1789 return { x: 0, y: 0 };
1790 }
1791 }
1792 });
1793
1794 window.weFormsBuilderisDirty = false;
1795
1796 router.beforeEach(function (to, from, next) {
1797 // show warning if builder has unsaved changes
1798 if (window.weFormsBuilderisDirty) {
1799 if (confirm(wpuf_form_builder.i18n.unsaved_changes + ' ' + wpuf_form_builder.i18n.areYouSureToLeave)) {
1800 window.weFormsBuilderisDirty = false;
1801 } else {
1802 next(from.path);
1803 return false;
1804 }
1805 }
1806
1807 next();
1808 });
1809
1810 var app = new Vue({
1811 router: router,
1812 store: wpuf_form_builder_store
1813 }).$mount('#wpuf-contact-form-app');
1814
1815 // Admin menu hack
1816 var menuRoot = $('#toplevel_page_weforms');
1817
1818 menuRoot.on('click', 'a', function () {
1819 var self = $(this);
1820
1821 $('ul.wp-submenu li', menuRoot).removeClass('current');
1822
1823 if (self.hasClass('wp-has-submenu')) {
1824 $('li.wp-first-item', menuRoot).addClass('current');
1825 } else {
1826 self.parents('li').addClass('current');
1827 }
1828 });
1829
1830 $(function () {
1831
1832 // select the current sub menu on page load
1833 var current_url = window.location.href;
1834 var current_path = current_url.substr(current_url.indexOf('admin.php'));
1835
1836 $('ul.wp-submenu a', menuRoot).each(function (index, el) {
1837 if ($(el).attr('href') === current_path) {
1838 $(el).parent().addClass('current');
1839 return;
1840 }
1841 });
1842 });
1843 })(jQuery);
1844