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

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