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

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