PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.3
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.2.3, at assets/js/form-builder-components.js

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