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

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