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

1,701 lines 56.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 var _typeof2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
5 var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
6 return typeof obj === "undefined" ? "undefined" : _typeof2(obj);
7 } : function (obj) {
8 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof2(obj);
9 };
10
11 /*!
12 weForms - v1.3.4
13 Generated: 2019-01-16 (1547644353022)
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 };
1230 /* ./assets/spa/components/weforms-settings/index.js */
1231 weForms.routeComponents.Settings = {
1232 template: '#tmpl-wpuf-weforms-settings',
1233 mixins: [weForms.mixins.Loading, weForms.mixins.Cookie],
1234 data: function data() {
1235 return {
1236 loading: false,
1237 settings: {
1238 email_gateway: 'wordpress',
1239 credit: false,
1240 permission: 'manage_options',
1241 gateways: {
1242 sendgrid: '',
1243 mailgun: '',
1244 sparkpost: ''
1245 },
1246 recaptcha: {
1247 type: 'v2',
1248 key: '',
1249 secret: ''
1250 }
1251 },
1252
1253 activeTab: 'general'
1254 };
1255 },
1256
1257 computed: {
1258
1259 is_pro: function is_pro() {
1260 return 'true' === weForms.is_pro;
1261 }
1262 },
1263
1264 created: function created() {
1265 this.fetchSettings();
1266
1267 if (this.getCookie('weforms_settings_active_tab')) {
1268 this.activeTab = this.getCookie('weforms_settings_active_tab');
1269 }
1270 },
1271
1272 methods: {
1273
1274 makeActive: function makeActive(val) {
1275 this.activeTab = val;
1276 },
1277
1278 isActiveTab: function isActiveTab(val) {
1279 return this.activeTab === val;
1280 },
1281
1282 fetchSettings: function fetchSettings() {
1283 var self = this;
1284
1285 self.loading = true;
1286
1287 wp.ajax.send('weforms_get_settings', {
1288 data: {
1289 _wpnonce: weForms.nonce
1290 },
1291
1292 success: function success(response) {
1293
1294 if (response === undefined) {
1295 return;
1296 }
1297
1298 // set defaults if undefined
1299 $.each(self.settings, function (key, value) {
1300 if (response[key] === undefined) {
1301 response[key] = value;
1302 }
1303 });
1304
1305 self.settings = response;
1306 },
1307
1308 complete: function complete() {
1309 self.loading = false;
1310 }
1311 });
1312 },
1313
1314 saveSettings: function saveSettings(target) {
1315 var self = this;
1316
1317 $(target).addClass('updating-message');
1318
1319 wp.ajax.send('weforms_save_settings', {
1320 data: {
1321 settings: JSON.stringify(self.settings),
1322 _wpnonce: weForms.nonce
1323 },
1324
1325 success: function success(response) {
1326 toastr.options.timeOut = 1000;
1327 toastr.success('Settings has been updated');
1328 },
1329
1330 error: function error(_error16) {
1331 console.log(_error16);
1332 },
1333
1334 complete: function complete() {
1335 $(target).removeClass('updating-message');
1336 }
1337 });
1338 },
1339
1340 post: function post(action, data, _success) {
1341 data = data || {};
1342 _success = _success || function () {};
1343 data._wpnonce = weForms.nonce;
1344
1345 wp.ajax.send(action, {
1346 data: data,
1347
1348 success: function success(response) {
1349 _success(response);
1350 },
1351
1352 error: function error(_error17) {
1353 console.log(_error17);
1354 },
1355
1356 complete: function complete() {}
1357 });
1358 }
1359 },
1360
1361 watch: {
1362 activeTab: function activeTab(value) {
1363 this.setCookie('weforms_settings_active_tab', value, '365');
1364 }
1365 }
1366 };
1367 /* ./assets/spa/app.js */
1368 if (!Array.prototype.hasOwnProperty('swap')) {
1369 Array.prototype.swap = function (from, to) {
1370 this.splice(to, 0, this.splice(from, 1)[0]);
1371 };
1372 }
1373
1374 Vue.component('datepicker', {
1375 template: '<input type="text" v-bind:value="value" />',
1376 props: ['value'],
1377 mounted: function mounted() {
1378 var self = this;
1379
1380 $(this.$el).datetimepicker({
1381 dateFormat: 'yy-mm-dd',
1382 timeFormat: "HH:mm:ss",
1383 onClose: this.onClose
1384 });
1385 },
1386
1387 methods: {
1388 onClose: function onClose(date) {
1389 this.$emit('input', date);
1390 }
1391 }
1392 });
1393
1394 Vue.component('weforms-colorpicker', {
1395 template: '<input type="text" v-bind:value="value" />',
1396 props: ['value'],
1397 mounted: function mounted() {
1398 var self = this;
1399
1400 $(this.$el).wpColorPicker({
1401 change: this.onChange
1402 });
1403 },
1404
1405 methods: {
1406 onChange: function onChange(event, ui) {
1407 this.$emit('input', ui.color.toString());
1408 }
1409 }
1410 });
1411
1412 // check if an element is visible in browser viewport
1413 function is_element_in_viewport(el) {
1414 if (typeof jQuery === "function" && el instanceof jQuery) {
1415 el = el[0];
1416 }
1417
1418 var rect = el.getBoundingClientRect();
1419
1420 return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1421 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1422 ;
1423 }
1424
1425 /**
1426 * Vuex Store data
1427 */
1428 var wpuf_form_builder_store = new Vuex.Store({
1429 state: {
1430 post: {},
1431 form_fields: [],
1432 panel_sections: wpuf_form_builder.panel_sections,
1433 field_settings: wpuf_form_builder.field_settings,
1434 notifications: [],
1435 settings: {},
1436 integrations: {},
1437 current_panel: 'form-fields',
1438 editing_field_id: 0 // editing form field id
1439 },
1440
1441 mutations: {
1442 set_form_fields: function set_form_fields(state, form_fields) {
1443 Vue.set(state, 'form_fields', form_fields);
1444 },
1445
1446 set_form_post: function set_form_post(state, post) {
1447 Vue.set(state, 'post', post);
1448 },
1449
1450 set_form_notification: function set_form_notification(state, value) {
1451 Vue.set(state, 'notifications', value);
1452 },
1453
1454 set_form_integrations: function set_form_integrations(state, value) {
1455 Vue.set(state, 'integrations', value);
1456 },
1457
1458 set_form_settings: function set_form_settings(state, value) {
1459 Vue.set(state, 'settings', value);
1460 },
1461
1462 // set the current panel
1463 set_current_panel: function set_current_panel(state, panel) {
1464 if ('field-options' !== state.current_panel && 'field-options' === panel && state.form_fields.length) {
1465 state.editing_field_id = state.form_fields[0].id;
1466 }
1467
1468 state.current_panel = panel;
1469
1470 // reset editing field id
1471 if ('form-fields' === panel) {
1472 state.editing_field_id = 0;
1473 }
1474 },
1475
1476 // add show property to every panel section
1477 panel_add_show_prop: function panel_add_show_prop(state) {
1478 state.panel_sections.map(function (section, index) {
1479 if (!section.hasOwnProperty('show')) {
1480 Vue.set(state.panel_sections[index], 'show', true);
1481 }
1482 });
1483 },
1484
1485 // toggle panel sections
1486 panel_toggle: function panel_toggle(state, index) {
1487 state.panel_sections[index].show = !state.panel_sections[index].show;
1488 },
1489
1490 // open field settings panel
1491 open_field_settings: function open_field_settings(state, field_id) {
1492 var field = state.form_fields.filter(function (item) {
1493 return parseInt(field_id) === parseInt(item.id);
1494 });
1495
1496 if ('field-options' === state.current_panel && field[0].id === state.editing_field_id) {
1497 return;
1498 }
1499
1500 if (field.length) {
1501 state.editing_field_id = 0;
1502 state.current_panel = 'field-options';
1503
1504 setTimeout(function () {
1505 state.editing_field_id = field[0].id;
1506 }, 400);
1507 }
1508 },
1509
1510 update_editing_form_field: function update_editing_form_field(state, payload) {
1511 var editing_field = _.find(state.form_fields, function (item) {
1512 return parseInt(item.id) === parseInt(payload.editing_field_id);
1513 });
1514
1515 editing_field[payload.field_name] = payload.value;
1516 },
1517
1518 // add new form field element
1519 add_form_field_element: function add_form_field_element(state, payload) {
1520 state.form_fields.splice(payload.toIndex, 0, payload.field);
1521
1522 // bring newly added element into viewport
1523 Vue.nextTick(function () {
1524 var el = $('#form-preview-stage .wpuf-form .field-items').eq(payload.toIndex);
1525
1526 if (el && !is_element_in_viewport(el.get(0))) {
1527 $('#builder-stage section').scrollTo(el, 800, { offset: -50 });
1528 }
1529 });
1530 },
1531
1532 // sorting inside stage
1533 swap_form_field_elements: function swap_form_field_elements(state, payload) {
1534 state.form_fields.swap(payload.fromIndex, payload.toIndex);
1535 },
1536
1537 clone_form_field_element: function clone_form_field_element(state, payload) {
1538 var field = _.find(state.form_fields, function (item) {
1539 return parseInt(item.id) === parseInt(payload.field_id);
1540 });
1541
1542 var clone = $.extend(true, {}, field),
1543 index = parseInt(payload.index) + 1;
1544
1545 clone.id = payload.new_id;
1546 clone.name = clone.name + '_copy';
1547 clone.is_new = true;
1548
1549 state.form_fields.splice(index, 0, clone);
1550 },
1551
1552 // delete a field
1553 delete_form_field_element: function delete_form_field_element(state, index) {
1554 state.current_panel = 'form-fields';
1555 state.form_fields.splice(index, 1);
1556 },
1557
1558 // set fields for a panel section
1559 set_panel_section_fields: function set_panel_section_fields(state, payload) {
1560 var section = _.find(state.panel_sections, function (item) {
1561 return item.id === payload.id;
1562 });
1563
1564 section.fields = payload.fields;
1565 },
1566
1567 // notifications
1568 addNotification: function addNotification(state, payload) {
1569 state.notifications.push(_.clone(payload));
1570 },
1571
1572 deleteNotification: function deleteNotification(state, index) {
1573 state.notifications.splice(index, 1);
1574 },
1575
1576 cloneNotification: function cloneNotification(state, index) {
1577 var clone = $.extend(true, {}, state.notifications[index]);
1578
1579 index = parseInt(index) + 1;
1580 state.notifications.splice(index, 0, clone);
1581 },
1582
1583 // update by it's property
1584 updateNotificationProperty: function updateNotificationProperty(state, payload) {
1585 state.notifications[payload.index][payload.property] = payload.value;
1586 },
1587
1588 updateNotification: function updateNotification(state, payload) {
1589 state.notifications[payload.index] = payload.value;
1590 },
1591
1592 updateIntegration: function updateIntegration(state, payload) {
1593 // console.log(payload);
1594 // console.log(state.integrations[payload.index]);
1595 // state.integrations[payload.index] = payload.value;
1596 Vue.set(state.integrations, payload.index, payload.value);
1597
1598 // state.integrations.splice(payload.index, 0, payload.value);
1599 }
1600 }
1601 });
1602
1603 // 1. Define route components.
1604 weForms.routeComponents.FormHome = { template: '<div><router-view class="child"></router-view></div>' };
1605 weForms.routeComponents.SingleForm = { template: '#tmpl-wpuf-form-editor' };
1606 weForms.routeComponents.FormEntriesHome = {
1607 template: '<div><router-view class="grand-child"></router-view></div>'
1608 };
1609
1610 /**
1611 * Parse the route array and bind required components
1612 *
1613 * This changes the weForms.routes array and changes the components
1614 * so we can use weForms.routeComponents.{compontent} component.
1615 *
1616 * @param {array} routes
1617 *
1618 * @return {void}
1619 */
1620 function parseRouteComponent(routes) {
1621
1622 for (var i = 0; i < routes.length; i++) {
1623 if (_typeof(routes[i].children) === 'object') {
1624
1625 parseRouteComponent(routes[i].children);
1626
1627 if (typeof routes[i].component !== 'undefined') {
1628 routes[i].component = weForms.routeComponents[routes[i].component];
1629 }
1630 } else {
1631 routes[i].component = weForms.routeComponents[routes[i].component];
1632 }
1633 }
1634 }
1635
1636 // mutate the localized array
1637 parseRouteComponent(weForms.routes);
1638
1639 // 3. Create the router instance and pass the `routes` option
1640 var router = new VueRouter({
1641 routes: weForms.routes,
1642 scrollBehavior: function scrollBehavior(to, from, savedPosition) {
1643 if (savedPosition) {
1644 return savedPosition;
1645 } else {
1646 return { x: 0, y: 0 };
1647 }
1648 }
1649 });
1650
1651 window.weFormsBuilderisDirty = false;
1652
1653 router.beforeEach(function (to, from, next) {
1654 // show warning if builder has unsaved changes
1655 if (window.weFormsBuilderisDirty) {
1656 if (confirm(wpuf_form_builder.i18n.unsaved_changes + ' ' + wpuf_form_builder.i18n.areYouSureToLeave)) {
1657 window.weFormsBuilderisDirty = false;
1658 } else {
1659 next(from.path);
1660 return false;
1661 }
1662 }
1663
1664 next();
1665 });
1666
1667 var app = new Vue({
1668 router: router,
1669 store: wpuf_form_builder_store
1670 }).$mount('#wpuf-contact-form-app');
1671
1672 // Admin menu hack
1673 var menuRoot = $('#toplevel_page_weforms');
1674
1675 menuRoot.on('click', 'a', function () {
1676 var self = $(this);
1677
1678 $('ul.wp-submenu li', menuRoot).removeClass('current');
1679
1680 if (self.hasClass('wp-has-submenu')) {
1681 $('li.wp-first-item', menuRoot).addClass('current');
1682 } else {
1683 self.parents('li').addClass('current');
1684 }
1685 });
1686
1687 $(function () {
1688
1689 // select the current sub menu on page load
1690 var current_url = window.location.href;
1691 var current_path = current_url.substr(current_url.indexOf('admin.php'));
1692
1693 $('ul.wp-submenu a', menuRoot).each(function (index, el) {
1694 if ($(el).attr('href') === current_path) {
1695 $(el).parent().addClass('current');
1696 return;
1697 }
1698 });
1699 });
1700 })(jQuery);
1701