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

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