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

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