PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.7
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.7
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / assets / js / spa-app.js

spa-app.js in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.3.7, at assets/js/spa-app.js

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