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

1,588 lines 52.8 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.8
13 Generated: 2018-06-01 (1527843697842)
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 form_settings: {},
601 respondent_points: 0,
602 answers: {}
603 };
604 },
605 created: function created() {
606 this.hideEmpty = this.hideEmptyStatus();
607 this.fetchData();
608 },
609 computed: {
610 hasFormFields: function hasFormFields() {
611 return Object.keys(this.entry.form_fields).length;
612 }
613 },
614 methods: {
615 fetchData: function fetchData() {
616 var self = this;
617
618 this.loading = true;
619
620 wp.ajax.send('weforms_form_entry_details', {
621 data: {
622 entry_id: self.$route.params.entryid,
623 form_id: self.$route.params.id,
624 _wpnonce: weForms.nonce
625 },
626 success: function success(response) {
627 self.loading = false;
628 self.entry = response;
629 self.hasEmpty = response.has_empty;
630 self.form_settings = response.form_settings;
631 self.respondent_points = response.respondent_points;
632 self.answers = response.answers;
633 },
634 error: function error(_error6) {
635 self.loading = false;
636 alert(_error6);
637 }
638 });
639 },
640
641 trashEntry: function trashEntry() {
642 var self = this;
643
644 if (!confirm(weForms.confirm)) {
645 return;
646 }
647
648 wp.ajax.send('weforms_form_entry_trash', {
649 data: {
650 entry_id: self.$route.params.entryid,
651 _wpnonce: weForms.nonce
652 },
653
654 success: function success() {
655 self.loading = false;
656
657 self.$router.push({ name: 'formEntries', params: { id: self.$route.params.id } });
658 },
659 error: function error(_error7) {
660 self.loading = false;
661 alert(_error7);
662 }
663 });
664 },
665
666 hideEmptyStatus: function hideEmptyStatus() {
667 return this.getCookie('weFormsEntryHideEmpty') === 'false' ? false : true;
668 }
669 },
670 watch: {
671 hideEmpty: function hideEmpty(value) {
672 this.setCookie('weFormsEntryHideEmpty', value, 356);
673 }
674 }
675 };
676
677 /* ./assets/spa/components/form-list-table/index.js */
678 Vue.component('form-list-table', {
679 template: '#tmpl-wpuf-form-list-table',
680 mixins: [weForms.mixins.Loading, weForms.mixins.Paginate, weForms.mixins.BulkAction],
681 data: function data() {
682 return {
683 loading: false,
684 index: 'ID',
685 items: [],
686 bulkDeleteAction: 'weforms_form_delete_bulk'
687 };
688 },
689 created: function created() {
690 this.fetchData();
691 },
692 computed: {
693 is_pro: function is_pro() {
694 return 'true' === weForms.is_pro;
695 },
696 has_payment: function has_payment() {
697 return 'true' === weForms.has_payment;
698 }
699 },
700
701 methods: {
702 fetchData: function fetchData() {
703 var self = this;
704
705 this.loading = true;
706
707 wp.ajax.send('weforms_form_list', {
708 data: {
709 _wpnonce: weForms.nonce,
710 page: self.currentPage
711 },
712 success: function success(response) {
713 self.loading = false;
714 self.items = response.forms;
715 self.totalItems = response.meta.total;
716 self.totalPage = response.meta.pages;
717 },
718 error: function error(_error8) {
719 self.loading = false;
720 alert(_error8);
721 }
722 });
723 },
724
725 deleteForm: function deleteForm(index) {
726 var self = this;
727
728 if (confirm('Are you sure?')) {
729 self.loading = true;
730
731 wp.ajax.send('weforms_form_delete', {
732 data: {
733 form_id: this.items[index].id,
734 _wpnonce: weForms.nonce
735 },
736 success: function success(response) {
737 self.items.splice(index, 1);
738 self.loading = false;
739 },
740 error: function error(_error9) {
741 alert(_error9);
742 self.loading = false;
743 }
744 });
745 }
746 },
747
748 duplicate: function duplicate(form_id, index) {
749 var self = this;
750
751 this.loading = true;
752
753 wp.ajax.send('weforms_form_duplicate', {
754 data: {
755 form_id: form_id,
756 _wpnonce: weForms.nonce
757 },
758 success: function success(response) {
759 self.items.splice(0, 0, response);
760 self.loading = false;
761 },
762 error: function error(_error10) {
763 alert(_error10);
764 self.loading = false;
765 }
766 });
767 },
768
769 handleBulkAction: function handleBulkAction() {
770 if ('-1' === this.bulkAction) {
771 alert('Please chose a bulk action to perform');
772 return;
773 }
774
775 if ('delete' === this.bulkAction) {
776 if (!this.checkedItems.length) {
777 alert('Please select atleast one form to delete.');
778 return;
779 }
780
781 if (confirm('Are you sure to delete the forms?')) {
782 this.deleteBulk();
783 }
784 }
785 }
786 }
787 });
788 /* ./assets/spa/components/form-payments/index.js */
789 weForms.routeComponents.FormPayments = {
790 props: {
791 id: [String, Number]
792 },
793 template: '#tmpl-wpuf-form-payments',
794 data: function data() {
795 return {
796 form_title: 'Loading...'
797 };
798 }
799 };
800
801 /* ./assets/spa/components/home-page/index.js */
802 weForms.routeComponents.Home = {
803 template: '#tmpl-wpuf-home-page',
804
805 data: function data() {
806 return {
807 showTemplateModal: false
808 };
809 },
810
811 methods: {
812 displayModal: function displayModal() {
813 this.showTemplateModal = true;
814 },
815
816 closeModal: function closeModal() {
817 this.showTemplateModal = false;
818 }
819 }
820 };
821
822 /* ./assets/spa/components/tools/index.js */
823 weForms.routeComponents.Tools = {
824 template: '#tmpl-wpuf-tools',
825 mixins: [weForms.mixins.Tabs, weForms.mixins.Loading],
826 data: function data() {
827 return {
828 activeTab: 'export',
829 exportType: 'all',
830 loading: false,
831 forms: [],
832 importButton: 'Import',
833 currentStatus: 0,
834 responseMessage: '',
835 logs: [],
836 ximport: {
837 current: '',
838 title: '',
839 action: '',
840 message: '',
841 type: 'updated',
842 refs: {}
843 }
844 };
845 },
846
847 computed: {
848
849 isInitial: function isInitial() {
850 return this.currentStatus === 0;
851 },
852
853 isSaving: function isSaving() {
854 return this.currentStatus === 1;
855 },
856
857 isSuccess: function isSuccess() {
858 return this.currentStatus === 2;
859 },
860
861 isFailed: function isFailed() {
862 return this.currentStatus === 3;
863 },
864
865 hasRefs: function hasRefs() {
866 return Object.keys(this.ximport.refs).length;
867 },
868 hasLogs: function hasLogs() {
869 return Object.keys(this.logs).length;
870 }
871 },
872
873 created: function created() {
874 this.fetchData();
875 this.fetchLogs();
876 },
877
878 methods: {
879 fetchLogs: function fetchLogs(target) {
880 var self = this;
881
882 self.startLoading(target);
883
884 wp.ajax.send('weforms_read_logs', {
885 data: {
886 _wpnonce: weForms.nonce
887 },
888 success: function success(response) {
889 self.stopLoading(target);
890 self.logs = response;
891 }, error: function error() {
892 self.stopLoading(target);
893 self.logs = [];
894 }
895 });
896 },
897 deleteLogs: function deleteLogs(target) {
898 var self = this;
899
900 if (confirm('Are you sure to clear the log file?')) {
901
902 self.startLoading(target);
903
904 wp.ajax.send('weforms_delete_logs', {
905 data: {
906 _wpnonce: weForms.nonce
907 },
908 success: function success(response) {
909 self.logs = [];
910 self.stopLoading(target);
911 self.fetchLogs();
912 },
913 error: function error(response) {
914 self.logs = [];
915 self.stopLoading(target);
916 self.fetchLogs();
917 }
918 });
919 }
920 },
921 stopLoading: function stopLoading(target) {
922 target = $(target);
923
924 if (target.is('button')) {
925 target.removeClass('updating-message').find('span').show();
926 } else if (target.is('span')) {
927 target.show().parent().removeClass('updating-message');
928 }
929 },
930 startLoading: function startLoading(target) {
931
932 target = $(target);
933
934 if (target.is('button')) {
935 target.addClass('updating-message').find('span').hide();
936 } else if (target.is('span')) {
937 target.hide().parent().addClass('updating-message');
938 }
939 },
940 fetchData: function fetchData() {
941 var self = this;
942
943 this.loading = true;
944
945 wp.ajax.send('weforms_form_names', {
946 data: {
947 _wpnonce: weForms.nonce
948 },
949 success: function success(response) {
950 // console.log(response);
951 self.loading = false;
952 self.forms = response;
953 },
954 error: function error(_error11) {
955 self.loading = false;
956 alert(_error11);
957 }
958 });
959 },
960
961 importForm: function importForm(fieldName, fileList, event) {
962 if (!fileList.length) {
963 return;
964 }
965
966 var formData = new FormData();
967 var self = this;
968
969 formData.append(fieldName, fileList[0], fileList[0].name);
970 formData.append('action', 'weforms_import_form');
971 formData.append('_wpnonce', weForms.nonce);
972
973 self.currentStatus = 1;
974
975 $.ajax({
976 type: "POST",
977 url: window.ajaxurl,
978 data: formData,
979 processData: false,
980 contentType: false,
981 success: function success(response) {
982 self.responseMessage = response.data;
983
984 if (response.success) {
985 self.currentStatus = 2;
986 } else {
987 self.currentStatus = 3;
988 }
989
990 // reset the value
991 $(event.target).val('');
992 },
993
994 error: function error(errResponse) {
995 console.log(errResponse);
996 self.currentStatus = 3;
997 },
998
999 complete: function complete() {
1000 $(event.target).val('');
1001 }
1002 });
1003 },
1004
1005 importx: function importx(target, plugin) {
1006 var button = $(target);
1007 var self = this;
1008
1009 self.ximport.current = plugin;
1010 button.addClass('updating-message').text(button.data('importing'));
1011
1012 wp.ajax.send('weforms_import_xforms_' + plugin, {
1013 data: {
1014 _wpnonce: weForms.nonce
1015 },
1016
1017 success: function success(response) {
1018 self.ximport.title = response.title;
1019 self.ximport.message = response.message;
1020 self.ximport.action = response.action;
1021 self.ximport.refs = response.refs;
1022 },
1023
1024 error: function error(_error12) {
1025 alert(_error12.message);
1026 },
1027
1028 complete: function complete() {
1029 button.removeClass('updating-message').text(button.data('original'));
1030 }
1031 });
1032 },
1033
1034 replaceX: function replaceX(target, type) {
1035 var button = $(target);
1036 var self = this;
1037
1038 button.addClass('updating-message');
1039
1040 wp.ajax.send('weforms_import_xreplace_' + self.ximport.current, {
1041 data: {
1042 type: type,
1043 _wpnonce: weForms.nonce
1044 },
1045
1046 success: function success(response) {
1047 if ('replace' === button.data('type')) {
1048 alert(response);
1049 }
1050 },
1051
1052 error: function error(_error13) {
1053 alert(_error13);
1054 },
1055
1056 complete: function complete() {
1057 self.ximport.current = '';
1058 self.ximport.title = '';
1059 }
1060 });
1061 }
1062 }
1063 };
1064
1065 /* ./assets/spa/components/transactions/index.js */
1066 weForms.routeComponents.Transactions = {
1067 template: '#tmpl-wpuf-transactions',
1068 data: function data() {
1069 return {
1070 selected: 0,
1071 no_transactions: false,
1072 forms: {},
1073 form_title: 'Loading...'
1074 };
1075 },
1076
1077 created: function created() {
1078 this.get_forms();
1079 },
1080
1081 methods: {
1082 get_forms: function get_forms() {
1083 var self = this;
1084
1085 wp.ajax.send('weforms_form_list', {
1086 data: {
1087 _wpnonce: weForms.nonce,
1088 page: self.currentPage,
1089 filter: 'transactions'
1090 },
1091 success: function success(response) {
1092
1093 if (Object.keys(response.forms).length) {
1094 self.forms = response.forms;
1095 self.selected = self.forms[Object.keys(self.forms)[0]].id;
1096 } else {
1097 self.form_title = 'No transaction found';
1098 self.no_transactions = true;
1099 }
1100 },
1101 error: function error(_error14) {
1102 alert(_error14);
1103 }
1104 });
1105 }
1106 }
1107 };
1108
1109 /* ./assets/spa/components/weforms-page-help/index.js */
1110 weForms.routeComponents.Help = {
1111 template: '#tmpl-wpuf-weforms-page-help'
1112 };
1113 /* ./assets/spa/components/weforms-premium/index.js */
1114 weForms.routeComponents.Premium = {
1115 template: '#tmpl-wpuf-weforms-premium'
1116 };
1117 /* ./assets/spa/components/weforms-settings/index.js */
1118 weForms.routeComponents.Settings = {
1119 template: '#tmpl-wpuf-weforms-settings',
1120 mixins: [weForms.mixins.Loading, weForms.mixins.Cookie],
1121 data: function data() {
1122 return {
1123 loading: false,
1124 settings: {
1125 email_gateway: 'wordpress',
1126 credit: false,
1127 permission: 'manage_options',
1128 gateways: {
1129 sendgrid: '',
1130 mailgun: '',
1131 sparkpost: ''
1132 },
1133 recaptcha: {
1134 type: 'v2',
1135 key: '',
1136 secret: ''
1137 }
1138 },
1139
1140 activeTab: 'general'
1141 };
1142 },
1143
1144 computed: {
1145
1146 is_pro: function is_pro() {
1147 return 'true' === weForms.is_pro;
1148 }
1149 },
1150
1151 created: function created() {
1152 this.fetchSettings();
1153
1154 if (this.getCookie('weforms_settings_active_tab')) {
1155 this.activeTab = this.getCookie('weforms_settings_active_tab');
1156 }
1157 },
1158
1159 methods: {
1160
1161 makeActive: function makeActive(val) {
1162 this.activeTab = val;
1163 },
1164
1165 isActiveTab: function isActiveTab(val) {
1166 return this.activeTab === val;
1167 },
1168
1169 fetchSettings: function fetchSettings() {
1170 var self = this;
1171
1172 self.loading = true;
1173
1174 wp.ajax.send('weforms_get_settings', {
1175 data: {
1176 _wpnonce: weForms.nonce
1177 },
1178
1179 success: function success(response) {
1180
1181 if (response === undefined) {
1182 return;
1183 }
1184
1185 // set defaults if undefined
1186 $.each(self.settings, function (key, value) {
1187 if (response[key] === undefined) {
1188 response[key] = value;
1189 }
1190 });
1191
1192 self.settings = response;
1193 },
1194
1195 complete: function complete() {
1196 self.loading = false;
1197 }
1198 });
1199 },
1200
1201 saveSettings: function saveSettings(target) {
1202 var self = this;
1203
1204 $(target).addClass('updating-message');
1205
1206 wp.ajax.send('weforms_save_settings', {
1207 data: {
1208 settings: JSON.stringify(self.settings),
1209 _wpnonce: weForms.nonce
1210 },
1211
1212 success: function success(response) {
1213 toastr.options.timeOut = 1000;
1214 toastr.success('Settings has been updated');
1215 },
1216
1217 error: function error(_error15) {
1218 console.log(_error15);
1219 },
1220
1221 complete: function complete() {
1222 $(target).removeClass('updating-message');
1223 }
1224 });
1225 },
1226
1227 post: function post(action, data, _success) {
1228 data = data || {};
1229 _success = _success || function () {};
1230 data._wpnonce = weForms.nonce;
1231
1232 wp.ajax.send(action, {
1233 data: data,
1234
1235 success: function success(response) {
1236 _success(response);
1237 },
1238
1239 error: function error(_error16) {
1240 console.log(_error16);
1241 },
1242
1243 complete: function complete() {}
1244 });
1245 }
1246 },
1247
1248 watch: {
1249 activeTab: function activeTab(value) {
1250 this.setCookie('weforms_settings_active_tab', value, '365');
1251 }
1252 }
1253 };
1254 /* ./assets/spa/app.js */
1255 if (!Array.prototype.hasOwnProperty('swap')) {
1256 Array.prototype.swap = function (from, to) {
1257 this.splice(to, 0, this.splice(from, 1)[0]);
1258 };
1259 }
1260
1261 Vue.component('datepicker', {
1262 template: '<input type="text" v-bind:value="value" />',
1263 props: ['value'],
1264 mounted: function mounted() {
1265 var self = this;
1266
1267 $(this.$el).datetimepicker({
1268 dateFormat: 'yy-mm-dd',
1269 timeFormat: "HH:mm:ss",
1270 onClose: this.onClose
1271 });
1272 },
1273
1274 methods: {
1275 onClose: function onClose(date) {
1276 this.$emit('input', date);
1277 }
1278 }
1279 });
1280
1281 Vue.component('weforms-colorpicker', {
1282 template: '<input type="text" v-bind:value="value" />',
1283 props: ['value'],
1284 mounted: function mounted() {
1285 var self = this;
1286
1287 $(this.$el).wpColorPicker({
1288 change: this.onChange
1289 });
1290 },
1291
1292 methods: {
1293 onChange: function onChange(event, ui) {
1294 this.$emit('input', ui.color.toString());
1295 }
1296 }
1297 });
1298
1299 // check if an element is visible in browser viewport
1300 function is_element_in_viewport(el) {
1301 if (typeof jQuery === "function" && el instanceof jQuery) {
1302 el = el[0];
1303 }
1304
1305 var rect = el.getBoundingClientRect();
1306
1307 return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1308 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1309 ;
1310 }
1311
1312 /**
1313 * Vuex Store data
1314 */
1315 var wpuf_form_builder_store = new Vuex.Store({
1316 state: {
1317 post: {},
1318 form_fields: [],
1319 panel_sections: wpuf_form_builder.panel_sections,
1320 field_settings: wpuf_form_builder.field_settings,
1321 notifications: [],
1322 settings: {},
1323 integrations: {},
1324 current_panel: 'form-fields',
1325 editing_field_id: 0 // editing form field id
1326 },
1327
1328 mutations: {
1329 set_form_fields: function set_form_fields(state, form_fields) {
1330 Vue.set(state, 'form_fields', form_fields);
1331 },
1332
1333 set_form_post: function set_form_post(state, post) {
1334 Vue.set(state, 'post', post);
1335 },
1336
1337 set_form_notification: function set_form_notification(state, value) {
1338 Vue.set(state, 'notifications', value);
1339 },
1340
1341 set_form_integrations: function set_form_integrations(state, value) {
1342 Vue.set(state, 'integrations', value);
1343 },
1344
1345 set_form_settings: function set_form_settings(state, value) {
1346 Vue.set(state, 'settings', value);
1347 },
1348
1349 // set the current panel
1350 set_current_panel: function set_current_panel(state, panel) {
1351 if ('field-options' !== state.current_panel && 'field-options' === panel && state.form_fields.length) {
1352 state.editing_field_id = state.form_fields[0].id;
1353 }
1354
1355 state.current_panel = panel;
1356
1357 // reset editing field id
1358 if ('form-fields' === panel) {
1359 state.editing_field_id = 0;
1360 }
1361 },
1362
1363 // add show property to every panel section
1364 panel_add_show_prop: function panel_add_show_prop(state) {
1365 state.panel_sections.map(function (section, index) {
1366 if (!section.hasOwnProperty('show')) {
1367 Vue.set(state.panel_sections[index], 'show', true);
1368 }
1369 });
1370 },
1371
1372 // toggle panel sections
1373 panel_toggle: function panel_toggle(state, index) {
1374 state.panel_sections[index].show = !state.panel_sections[index].show;
1375 },
1376
1377 // open field settings panel
1378 open_field_settings: function open_field_settings(state, field_id) {
1379 var field = state.form_fields.filter(function (item) {
1380 return parseInt(field_id) === parseInt(item.id);
1381 });
1382
1383 if ('field-options' === state.current_panel && field[0].id === state.editing_field_id) {
1384 return;
1385 }
1386
1387 if (field.length) {
1388 state.editing_field_id = 0;
1389 state.current_panel = 'field-options';
1390
1391 setTimeout(function () {
1392 state.editing_field_id = field[0].id;
1393 }, 400);
1394 }
1395 },
1396
1397 update_editing_form_field: function update_editing_form_field(state, payload) {
1398 var editing_field = _.find(state.form_fields, function (item) {
1399 return parseInt(item.id) === parseInt(payload.editing_field_id);
1400 });
1401
1402 editing_field[payload.field_name] = payload.value;
1403 },
1404
1405 // add new form field element
1406 add_form_field_element: function add_form_field_element(state, payload) {
1407 state.form_fields.splice(payload.toIndex, 0, payload.field);
1408
1409 // bring newly added element into viewport
1410 Vue.nextTick(function () {
1411 var el = $('#form-preview-stage .wpuf-form .field-items').eq(payload.toIndex);
1412
1413 if (el && !is_element_in_viewport(el.get(0))) {
1414 $('#builder-stage section').scrollTo(el, 800, { offset: -50 });
1415 }
1416 });
1417 },
1418
1419 // sorting inside stage
1420 swap_form_field_elements: function swap_form_field_elements(state, payload) {
1421 state.form_fields.swap(payload.fromIndex, payload.toIndex);
1422 },
1423
1424 clone_form_field_element: function clone_form_field_element(state, payload) {
1425 var field = _.find(state.form_fields, function (item) {
1426 return parseInt(item.id) === parseInt(payload.field_id);
1427 });
1428
1429 var clone = $.extend(true, {}, field),
1430 index = parseInt(payload.index) + 1;
1431
1432 clone.id = payload.new_id;
1433 clone.name = clone.name + '_copy';
1434 clone.is_new = true;
1435
1436 state.form_fields.splice(index, 0, clone);
1437 },
1438
1439 // delete a field
1440 delete_form_field_element: function delete_form_field_element(state, index) {
1441 state.current_panel = 'form-fields';
1442 state.form_fields.splice(index, 1);
1443 },
1444
1445 // set fields for a panel section
1446 set_panel_section_fields: function set_panel_section_fields(state, payload) {
1447 var section = _.find(state.panel_sections, function (item) {
1448 return item.id === payload.id;
1449 });
1450
1451 section.fields = payload.fields;
1452 },
1453
1454 // notifications
1455 addNotification: function addNotification(state, payload) {
1456 state.notifications.push(_.clone(payload));
1457 },
1458
1459 deleteNotification: function deleteNotification(state, index) {
1460 state.notifications.splice(index, 1);
1461 },
1462
1463 cloneNotification: function cloneNotification(state, index) {
1464 var clone = $.extend(true, {}, state.notifications[index]);
1465
1466 index = parseInt(index) + 1;
1467 state.notifications.splice(index, 0, clone);
1468 },
1469
1470 // update by it's property
1471 updateNotificationProperty: function updateNotificationProperty(state, payload) {
1472 state.notifications[payload.index][payload.property] = payload.value;
1473 },
1474
1475 updateNotification: function updateNotification(state, payload) {
1476 state.notifications[payload.index] = payload.value;
1477 },
1478
1479 updateIntegration: function updateIntegration(state, payload) {
1480 // console.log(payload);
1481 // console.log(state.integrations[payload.index]);
1482 // state.integrations[payload.index] = payload.value;
1483 Vue.set(state.integrations, payload.index, payload.value);
1484
1485 // state.integrations.splice(payload.index, 0, payload.value);
1486 }
1487 }
1488 });
1489
1490 // 1. Define route components.
1491 weForms.routeComponents.FormHome = { template: '<div><router-view class="child"></router-view></div>' };
1492 weForms.routeComponents.SingleForm = { template: '#tmpl-wpuf-form-editor' };
1493 weForms.routeComponents.FormEntriesHome = {
1494 template: '<div><router-view class="grand-child"></router-view></div>'
1495 };
1496
1497 /**
1498 * Parse the route array and bind required components
1499 *
1500 * This changes the weForms.routes array and changes the components
1501 * so we can use weForms.routeComponents.{compontent} component.
1502 *
1503 * @param {array} routes
1504 *
1505 * @return {void}
1506 */
1507 function parseRouteComponent(routes) {
1508
1509 for (var i = 0; i < routes.length; i++) {
1510 if (_typeof(routes[i].children) === 'object') {
1511
1512 parseRouteComponent(routes[i].children);
1513
1514 if (typeof routes[i].component !== 'undefined') {
1515 routes[i].component = weForms.routeComponents[routes[i].component];
1516 }
1517 } else {
1518 routes[i].component = weForms.routeComponents[routes[i].component];
1519 }
1520 }
1521 }
1522
1523 // mutate the localized array
1524 parseRouteComponent(weForms.routes);
1525
1526 // 3. Create the router instance and pass the `routes` option
1527 var router = new VueRouter({
1528 routes: weForms.routes,
1529 scrollBehavior: function scrollBehavior(to, from, savedPosition) {
1530 if (savedPosition) {
1531 return savedPosition;
1532 } else {
1533 return { x: 0, y: 0 };
1534 }
1535 }
1536 });
1537
1538 window.weFormsBuilderisDirty = false;
1539
1540 router.beforeEach(function (to, from, next) {
1541 // show warning if builder has unsaved changes
1542 if (window.weFormsBuilderisDirty) {
1543 if (confirm(wpuf_form_builder.i18n.unsaved_changes + ' ' + wpuf_form_builder.i18n.areYouSureToLeave)) {
1544 window.weFormsBuilderisDirty = false;
1545 } else {
1546 next(from.path);
1547 return false;
1548 }
1549 }
1550
1551 next();
1552 });
1553
1554 var app = new Vue({
1555 router: router,
1556 store: wpuf_form_builder_store
1557 }).$mount('#wpuf-contact-form-app');
1558
1559 // Admin menu hack
1560 var menuRoot = $('#toplevel_page_weforms');
1561
1562 menuRoot.on('click', 'a', function () {
1563 var self = $(this);
1564
1565 $('ul.wp-submenu li', menuRoot).removeClass('current');
1566
1567 if (self.hasClass('wp-has-submenu')) {
1568 $('li.wp-first-item', menuRoot).addClass('current');
1569 } else {
1570 self.parents('li').addClass('current');
1571 }
1572 });
1573
1574 $(function () {
1575
1576 // select the current sub menu on page load
1577 var current_url = window.location.href;
1578 var current_path = current_url.substr(current_url.indexOf('admin.php'));
1579
1580 $('ul.wp-submenu a', menuRoot).each(function (index, el) {
1581 if ($(el).attr('href') === current_path) {
1582 $(el).parent().addClass('current');
1583 return;
1584 }
1585 });
1586 });
1587 })(jQuery);
1588