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

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

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