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

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