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

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