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

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