PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.7
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.7
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 / form-builder-components.js

form-builder-components.js in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.6.7, at assets/js/form-builder-components.js

715 lines 23.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 /* assets/js/utils/jquery-siaf-start.js */
4 ;(function ($) {
5 'use strict';
6
7 /* ./assets/components/dynamic-field/index.js */
8
9 Vue.component('field-dynamic-field', {
10 mixins: [wpuf_mixins.option_field_mixin],
11 template: '#tmpl-wpuf-dynamic-field',
12 data: function data() {
13 return {
14 dynamic: {
15 status: false,
16 param_name: ''
17 }
18 };
19 },
20 computed: {
21 dynamic: function dynamic() {
22 return this.editing_form_field.dynamic;
23 },
24 editing_field: function editing_field() {
25 return this.editing_form_field;
26 }
27 },
28
29 created: function created() {
30 this.dynamic = $.extend(false, this.dynamic, this.editing_form_field.dynamic);
31 },
32
33 methods: {},
34
35 watch: {
36 dynamic: function dynamic() {
37 this.update_value('dynamic', this.dynamic);
38 }
39 }
40 });
41
42 /* ./assets/components/field-name/index.js */
43 Vue.component('field-name', {
44 template: '#tmpl-wpuf-field-name',
45
46 mixins: [wpuf_mixins.option_field_mixin],
47
48 computed: {
49 value: {
50 get: function get() {
51 return this.editing_form_field[this.option_field.name];
52 },
53
54 set: function set(value) {
55 this.update_value(this.option_field.name, value);
56 }
57 }
58 },
59
60 methods: {
61 on_focusout: function on_focusout(e) {
62 wpuf_form_builder.event_hub.$emit('field-text-focusout', e, this);
63 },
64 on_keyup: function on_keyup(e) {
65 wpuf_form_builder.event_hub.$emit('field-text-keyup', e, this);
66 },
67 insertValue: function insertValue(type, field, property) {
68 var value = field !== undefined ? '{' + type + ':' + field + '}' : '{' + type + '}';
69 this.editing_form_field[property.name][property.type] = value;
70 }
71 }
72 });
73
74 /* ./assets/components/field-text-with-tag/index.js */
75 Vue.component('field-text-with-tag', {
76 template: '#tmpl-wpuf-field-text-with-tag',
77
78 mixins: [wpuf_mixins.option_field_mixin],
79
80 computed: {
81 value: {
82 get: function get() {
83 return this.editing_form_field[this.option_field.name];
84 },
85
86 set: function set(value) {
87 this.update_value(this.option_field.name, value);
88 }
89 }
90 },
91
92 methods: {
93 on_focusout: function on_focusout(e) {
94 wpuf_form_builder.event_hub.$emit('field-text-focusout', e, this);
95 },
96 on_keyup: function on_keyup(e) {
97 wpuf_form_builder.event_hub.$emit('field-text-keyup', e, this);
98 },
99 insertValue: function insertValue(type, field, property) {
100 var value = field !== undefined ? '{' + type + ':' + field + '}' : '{' + type + '}';
101 this.value = value;
102 }
103 }
104 });
105
106 /* ./assets/components/form-date_field/index.js */
107 /**
108 * Field template: Date
109 */
110 Vue.component('form-date_field', {
111 template: '#tmpl-wpuf-form-date_field',
112
113 mixins: [wpuf_mixins.form_field_mixin]
114 });
115
116 /* ./assets/components/form-name_field/index.js */
117 /**
118 * Field template: First Name
119 */
120 Vue.component('form-name_field', {
121 template: '#tmpl-wpuf-form-name_field',
122
123 mixins: [wpuf_mixins.form_field_mixin]
124 });
125
126 /* ./assets/components/form-notification/index.js */
127 Vue.component('wpuf-cf-form-notification', {
128 template: '#tmpl-wpuf-form-notification',
129 mixins: [weForms.mixins.Loading],
130 data: function data() {
131 return {
132 editing: false,
133 editingIndex: 0
134 };
135 },
136
137 computed: {
138 is_pro: function is_pro() {
139 return 'true' === weForms.is_pro;
140 },
141 has_sms: function has_sms() {
142 return 'true' === weForms.has_sms;
143 },
144 pro_link: function pro_link() {
145 return wpuf_form_builder.pro_link;
146 },
147 notifications: function notifications() {
148 return this.$store.state.notifications;
149 },
150
151 hasNotifications: function hasNotifications() {
152 return Object.keys(this.$store.state.notifications).length;
153 }
154 },
155
156 methods: {
157 addNew: function addNew() {
158 this.$store.commit('addNotification', wpuf_form_builder.defaultNotification);
159 },
160
161 editItem: function editItem(index) {
162 this.editing = true;
163 this.editingIndex = index;
164 },
165
166 editDone: function editDone() {
167 this.editing = false;
168
169 this.$store.commit('updateNotification', {
170 index: this.editingIndex,
171 value: this.notifications[this.editingIndex]
172 });
173
174 jQuery('.advanced-field-wrap').slideUp('fast');
175 },
176
177 deleteItem: function deleteItem(index) {
178 if (confirm('Are you sure')) {
179 this.editing = false;
180 this.$store.commit('deleteNotification', index);
181 this.$emit('deleteNotification', index);
182 }
183 },
184
185 toggelNotification: function toggelNotification(index) {
186 this.$store.commit('updateNotificationProperty', {
187 index: index,
188 property: 'active',
189 value: !this.notifications[index].active
190 });
191 },
192
193 duplicate: function duplicate(index) {
194 this.$store.commit('cloneNotification', index);
195 },
196
197 toggleAdvanced: function toggleAdvanced() {
198 jQuery('.advanced-field-wrap').slideToggle('fast');
199 },
200
201 insertValue: function insertValue(type, field, property) {
202 var notification = this.notifications[this.editingIndex],
203 value = field !== undefined ? '{' + type + ':' + field + '}' : '{' + type + '}';
204
205 notification[property] = notification[property] + value;
206 },
207
208 insertValueEditor: function insertValueEditor(type, field, property) {
209 var value = field !== undefined ? '{' + type + ':' + field + '}' : '{' + type + '}';
210 this.$emit('insertValueEditor', value);
211 }
212 }
213 });
214
215 /* ./assets/components/integration/index.js */
216 Vue.component('wpuf-integration', {
217 template: '#tmpl-wpuf-integration',
218
219 computed: {
220
221 integrations: function integrations() {
222 return wpuf_form_builder.integrations;
223 },
224
225 hasIntegrations: function hasIntegrations() {
226 return Object.keys(this.integrations).length;
227 },
228
229 store: function store() {
230 return this.$store.state.integrations;
231 },
232
233 pro_link: function pro_link() {
234 return wpuf_form_builder.pro_link;
235 }
236 },
237
238 methods: {
239
240 getIntegration: function getIntegration(id) {
241 return this.integrations[id];
242 },
243
244 getIntegrationSettings: function getIntegrationSettings(id) {
245 // find settings in store, otherwise take from default integration settings
246 return this.store[id] || this.getIntegration(id).settings;
247 },
248
249 isActive: function isActive(id) {
250 if (!this.isAvailable(id)) {
251 return false;
252 }
253
254 return this.getIntegrationSettings(id).enabled === true;
255 },
256
257 isAvailable: function isAvailable(id) {
258 return this.integrations[id] && this.integrations[id].pro ? false : true;
259 },
260
261 toggleState: function toggleState(id, target) {
262 if (!this.isAvailable(id)) {
263 this.alert_pro_feature(id);
264 return;
265 }
266
267 // toggle the enabled state
268 var settings = this.getIntegrationSettings(id);
269
270 settings.enabled = !this.isActive(id);
271
272 this.$store.commit('updateIntegration', {
273 index: id,
274 value: settings
275 });
276
277 $(target).toggleClass('checked');
278 },
279
280 alert_pro_feature: function alert_pro_feature(id) {
281 var title = this.getIntegration(id).title;
282
283 swal({
284 title: '<i class="fa fa-lock"></i> ' + title + ' <br>' + this.i18n.is_a_pro_feature,
285 text: this.i18n.pro_feature_msg,
286 type: '',
287 showCancelButton: true,
288 cancelButtonText: this.i18n.close,
289 confirmButtonColor: '#46b450',
290 confirmButtonText: this.i18n.upgrade_to_pro
291 }).then(function (is_confirm) {
292 if (is_confirm) {
293 window.open(wpuf_form_builder.pro_link, '_blank');
294 }
295 }, function () {});
296 },
297
298 showHide: function showHide(target) {
299 $(target).closest('.wpuf-integration').toggleClass('collapsed');
300 },
301
302 openModal: function openModal(target) {
303 $(target).parents('.wpuf-integration').find('.wf-modal').addClass('wf-modal-open');
304 },
305
306 hideModal: function hideModal(target) {
307 $(target).parents('.wf-modal').removeClass('wf-modal-open');
308 },
309
310 save_form_builder: function save_form_builder(target) {
311 $('.weforms-save-form-builder').trigger('click');
312 this.hideModal(target);
313 }
314
315 }
316 });
317
318 /* ./assets/components/integration-erp/index.js */
319 Vue.component('wpuf-integration-erp', {
320 template: '#tmpl-wpuf-integration-erp',
321 mixins: [wpuf_mixins.integration_mixin],
322
323 methods: {
324 insertValue: function insertValue(type, field, property) {
325 var value = field !== undefined ? '{' + type + ':' + field + '}' : '{' + type + '}';
326
327 this.settings.fields[property] = value;
328 }
329 }
330 });
331 /* ./assets/components/integration-slack/index.js */
332 Vue.component('wpuf-integration-slack', {
333 template: '#tmpl-wpuf-integration-slack',
334 mixins: [wpuf_mixins.integration_mixin]
335 });
336 /* ./assets/components/integration-sprout-invoices/index.js */
337 Vue.component('wpuf-integration-sprout-invoices', {
338 template: '#tmpl-wpuf-integration-sprout-invoices',
339 mixins: [wpuf_mixins.integration_mixin],
340
341 methods: {
342 insertValue: function insertValue(type, field, property) {
343 var value = field !== undefined ? '{' + type + ':' + field + '}' : '{' + type + '}';
344 console.log(value);
345 this.settings.fields[property] = value;
346 }
347 }
348 });
349
350 /* ./assets/components/merge-tags/index.js */
351 Vue.component('wpuf-merge-tags', {
352 template: '#tmpl-wpuf-merge-tags',
353 props: {
354 field: [String, Number, Object],
355 filter: {
356 type: String,
357 default: null
358 },
359 fieldsonly: {
360 type: Boolean,
361 default: false
362 }
363 },
364
365 data: function data() {
366 return {
367 type: null
368 };
369 },
370
371 mounted: function mounted() {
372
373 // hide if clicked outside
374 $('body').on('click', function (event) {
375 if (!$(event.target).closest('.wpuf-merge-tag-wrap').length) {
376 $(".wpuf-merge-tags").hide();
377 }
378 });
379 },
380
381 computed: {
382 form_fields: function form_fields() {
383 var template = this.filter,
384 fields = this.$store.state.form_fields;
385
386 if (template !== null) {
387 return fields.filter(function (item) {
388 return item.template === template;
389 });
390 }
391
392 // remove the action/hidden fields
393 return fields.filter(function (item) {
394 return !_.contains(['action_hook', 'custom_hidden_field'], item.template);
395 });
396 }
397
398 },
399
400 methods: {
401 toggleFields: function toggleFields(event) {
402 $(event.target).parent().siblings('.wpuf-merge-tags').toggle('fast');
403 },
404
405 insertField: function insertField(type, field) {
406 this.$emit('insert', type, field, this.field);
407 }
408 }
409 });
410
411 /* ./assets/components/modal/index.js */
412 Vue.component('wpuf-modal', {
413 template: '#tmpl-wpuf-modal',
414 props: {
415 show: Boolean,
416 onClose: Function
417 },
418
419 mounted: function mounted() {
420 var self = this;
421
422 $('body').on('keydown', function (e) {
423 if (self.show && e.keyCode === 27) {
424 self.closeModal();
425 }
426 });
427 },
428
429 methods: {
430 closeModal: function closeModal() {
431 if (typeof this.onClose !== 'undefined') {
432 this.onClose();
433 } else {
434 this.$emit('hideModal');
435 }
436 }
437 }
438 });
439 /* ./assets/components/template-modal/index.js */
440 Vue.component('wpuf-template-modal', {
441 template: '#tmpl-wpuf-template-modal',
442
443 props: {
444 show: Boolean,
445 onClose: Function
446 },
447
448 data: function data() {
449 return {
450 loading: false,
451 category: 'all'
452 };
453 },
454
455 methods: {
456
457 blankForm: function blankForm(target) {
458 this.createForm('blank', target);
459 },
460
461 createForm: function createForm(form, target) {
462 var self = this;
463
464 // already on a request?
465 if (self.loading) {
466 return;
467 }
468
469 self.loading = true;
470
471 $(target).addClass('updating-message');
472
473 wp.ajax.send('weforms_contact_form_template', {
474 data: {
475 template: form,
476 _wpnonce: weForms.nonce
477 },
478
479 success: function success(response) {
480 self.$router.push({
481 name: 'edit',
482 params: { id: response.id }
483 });
484 },
485
486 error: function error(_error) {},
487
488 complete: function complete() {
489 self.loading = false;
490
491 $(target).removeClass('updating-message');
492 }
493 });
494 }
495 }
496 });
497
498 /* ./assets/components/weforms-text-editor/index.js */
499 Vue.component('weforms-text-editor', {
500 template: '#tmpl-wpuf-weforms-text-editor',
501
502 props: {
503 value: {
504 type: String,
505 required: true
506 },
507
508 i18n: {
509 type: Object,
510 required: true
511 },
512
513 editingIndex: {
514 type: Number,
515 required: true
516 }
517 },
518
519 data: function data() {
520 return {
521 editorId: _.clone(Date.now()),
522 fileFrame: null,
523 shortcodes: weForms.shortcodes
524 };
525 },
526 mounted: function mounted() {
527 var vm = this;
528 this.setupEditor();
529
530 this.$parent.$on('deleteNotification', function () {
531 setTimeout(function () {
532 if (vm.editor) {
533 vm.editor.setContent(vm.value);
534 }
535 }, 500);
536 });
537 },
538 beforeDestroy: function beforeDestroy() {
539 this.$parent.$off('insertValueEditor');
540 this.$parent.$off('deleteNotification');
541 },
542
543
544 methods: {
545 setupEditor: function setupEditor() {
546 var vm = this;
547 window.tinymce.init({
548 selector: '#wefroms-tinymce-' + this.editorId,
549 branding: false,
550 height: 150,
551 menubar: false,
552 convert_urls: false,
553 theme: 'modern',
554 skin: 'lightgray',
555 content_css: weForms.assetsURL + '/css/customizer.css',
556 fontsize_formats: '10px 11px 13px 14px 16px 18px 22px 25px 30px 36px 40px 45px 50px 60px 65px 70px 75px 80px',
557 font_formats: 'Arial=arial,helvetica,sans-serif;' + 'Comic Sans MS=comic sans ms,sans-serif;' + 'Courier New=courier new,courier;' + 'Georgia=georgia,palatino;' + 'Lucida=Lucida Sans Unicode, Lucida Grande, sans-serif;' + 'Tahoma=tahoma,arial,helvetica,sans-serif;' + 'Times New Roman=times new roman,times;' + 'Trebuchet MS=trebuchet ms,geneva;' + 'Verdana=verdana,geneva;',
558 plugins: 'textcolor colorpicker wplink wordpress code hr wpeditimage',
559 toolbar: ['shortcodes bold italic underline bullist numlist alignleft aligncenter alignjustify alignright link image', 'formatselect forecolor backcolor blockquote hr code', 'fontselect fontsizeselect removeformat undo redo'],
560 setup: function setup(editor) {
561
562 vm.editor = editor;
563
564 var shortcodeMenuItems = [];
565
566 _.forEach(vm.shortcodes, function (shortcodeObj, shortcodeType) {
567 shortcodeMenuItems.push({
568 text: shortcodeObj.title,
569 classes: 'menu-section-title'
570 });
571
572 _.forEach(shortcodeObj.codes, function (codeObj, shortcode) {
573 shortcodeMenuItems.push({
574 text: codeObj.title,
575 onclick: function onclick() {
576 var code = '[' + shortcodeType + ':' + shortcode + ']';
577
578 if (codeObj.default) {
579 code = '[' + shortcodeType + ':' + shortcode + ' default="' + codeObj.default + '"]';
580 }
581
582 if (codeObj.text) {
583 code = '[' + shortcodeType + ':' + shortcode + ' text="' + codeObj.text + '"]';
584 }
585
586 if (codeObj.plainText) {
587 code = codeObj.text;
588 }
589
590 editor.insertContent(code);
591 }
592 });
593 });
594 });
595
596 // editor.addButton('shortcodes', {
597 // type: 'menubutton',
598 // icon: 'shortcode dashicons dashicons-editor-code',
599 // tooltip: 'Shortcodes',
600 // menu: shortcodeMenuItems
601 // });
602
603 // editor.addButton('image', {
604 // icon: 'image',
605 // onclick() {
606 // vm.browseImage(editor);
607 // }
608 // });
609
610 // editor change triggers
611 editor.on('change keyup NodeChange', function () {
612 vm.$emit('input', editor.getContent());
613 });
614
615 vm.$parent.$on('insertValueEditor', function (value) {
616 editor.insertContent(value);
617 });
618 }
619 });
620 },
621 browseImage: function browseImage(editor) {
622 var vm = this;
623 var selectedFile = {
624 id: 0,
625 url: '',
626 type: ''
627 };
628
629 if (vm.fileFrame) {
630 vm.fileFrame.open();
631 return;
632 }
633
634 var fileStates = [new wp.media.controller.Library({
635 library: wp.media.query(),
636 multiple: false,
637 title: vm.i18n.selectAnImage,
638 priority: 20,
639 filterable: 'uploaded'
640 })];
641
642 vm.fileFrame = wp.media({
643 title: vm.i18n.selectAnImage,
644 library: {
645 type: ''
646 },
647 button: {
648 text: vm.i18n.selectAnImage
649 },
650 multiple: false,
651 states: fileStates
652 });
653
654 vm.fileFrame.on('select', function () {
655 var selection = vm.fileFrame.state().get('selection');
656
657 selection.map(function (image) {
658 image = image.toJSON();
659
660 if (image.id) {
661 selectedFile.id = image.id;
662 }
663
664 if (image.url) {
665 selectedFile.url = image.url;
666 }
667
668 if (image.type) {
669 selectedFile.type = image.type;
670 }
671
672 vm.insertImage(editor, selectedFile);
673
674 return null;
675 });
676 });
677
678 vm.fileFrame.on('ready', function () {
679 vm.fileFrame.uploader.options.uploader.params = {
680 type: 'wefroms-image-uploader'
681 };
682 });
683
684 vm.fileFrame.open();
685 },
686 insertImage: function insertImage(editor, image) {
687 if (!image.id || image.type !== 'image') {
688 this.alert({
689 type: 'error',
690 text: this.i18n.pleaseSelectAnImage
691 });
692
693 return;
694 }
695
696 var img = '<img src="' + image.url + '" alt="' + image.alt + '" title="' + image.title + '" style="max-width: 100%; height: auto;">';
697
698 editor.insertContent(img);
699 }
700 },
701
702 watch: {
703 editingIndex: function editingIndex(new_val, old_val) {
704 if (!this.editor) {
705 this.setupEditor();
706 } else {
707 this.editor.setContent(this.value);
708 }
709 }
710 }
711 });
712
713 /* assets/js/utils/jquery-siaf-end.js */
714 })(jQuery);
715