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

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