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

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

368 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 weForms.routeComponents.FormEditComponent = {
2 template: '#tmpl-wpuf-form-builder',
3 mixins: wpuf_form_builder_mixins(wpuf_mixins.root),
4 data: function() {
5 return {
6 is_form_saving: false,
7 is_form_saved: false,
8 is_form_switcher: false,
9 post_title_editing: false,
10 loading: false,
11 activeTab: 'editor',
12 activeSettingsTab: 'form',
13 activePaymentTab: 'paypal',
14 };
15 },
16
17 watch: {
18 loading: function(value) {
19 if ( value ) {
20 NProgress.configure({ parent: '#wpadminbar' });
21 NProgress.start();
22 } else {
23 NProgress.done();
24 }
25 },
26 form_fields: {
27 handler: function() {
28 window.weFormsBuilderisDirty = true;
29 },
30 deep: true
31 },
32 notifications: {
33 handler: function() {
34 window.weFormsBuilderisDirty = true;
35 },
36 deep: true
37 },
38 integrations: {
39 handler: function() {
40 window.weFormsBuilderisDirty = true;
41 },
42 deep: true
43 },
44 settings: {
45 handler: function() {
46 window.weFormsBuilderisDirty = true;
47 },
48 deep: true
49 },
50 payment: {
51 handler: function() {
52 window.weFormsBuilderisDirty = true;
53 },
54 deep: true
55 },
56 },
57
58 created: function() {
59 this.set_current_panel('form-fields');
60 this.fetchForm();
61
62 this.$store.commit('panel_add_show_prop');
63
64 /**
65 * This is the event hub we'll use in every
66 * component to communicate between them
67 */
68 wpuf_form_builder.event_hub = new Vue();
69 },
70
71 computed: {
72 current_panel: function () {
73 return this.$store.state.current_panel;
74 },
75
76 post: function () {
77 return this.$store.state.post;
78 },
79
80 form_fields_count: function () {
81 return this.$store.state.form_fields.length;
82 },
83
84 form_fields: function () {
85 return this.$store.state.form_fields;
86 },
87
88 notifications: function() {
89 return this.$store.state.notifications;
90 },
91
92 integrations: function() {
93 return this.$store.state.integrations;
94 },
95
96 settings: function() {
97 return this.$store.state.settings;
98 },
99
100 payment: function() {
101 return this.$store.state.payment;
102 }
103 },
104
105 mounted: function () {
106
107 var clipboard = new window.Clipboard('.form-id');
108 $(".form-id").tooltip();
109
110 var self = this;
111
112 this.started = true;
113
114 clipboard.on('success', function(e) {
115 // Show copied tooltip
116 $(e.trigger)
117 .attr('data-original-title', 'Copied!')
118 .tooltip('show');
119
120 // Reset the copied tooltip
121 setTimeout(function() {
122 $(e.trigger).tooltip('hide')
123 .attr('data-original-title', self.i18n.copy_shortcode);
124 }, 1000);
125
126 e.clearSelection();
127 });
128
129 this.initSharingClipBoard();
130
131 setTimeout(function(){
132 window.weFormsBuilderisDirty = false;
133 },500);
134
135 window.onbeforeunload = function () {
136 if ( window.weFormsBuilderisDirty ) {
137 return self.i18n.unsaved_changes;
138 }
139 };
140 },
141
142 methods: {
143
144 makeActive: function(val) {
145 this.activeTab = val;
146 },
147
148 isActiveTab: function(val) {
149 return this.activeTab === val;
150 },
151
152 isActiveSettingsTab: function(val) {
153 return this.activeSettingsTab === val;
154 },
155
156 makeActiveSettingsTab: function(val) {
157 this.activeSettingsTab = val;
158 },
159
160 isActivePaymentTab: function(val) {
161 return this.activePaymentTab === val;
162 },
163
164 makeActivePaymentTab: function(val) {
165 this.activePaymentTab = val;
166 },
167
168 fetchForm: function() {
169 var self = this;
170
171 self.loading = true;
172
173 wp.ajax.send( 'weforms_get_form', {
174 data: {
175 form_id: this.$route.params.id,
176 _wpnonce: weForms.nonce
177 },
178 success: function(response) {
179
180 self.$store.commit('set_form_post', response.post);
181 self.$store.commit('set_form_fields', response.form_fields);
182 self.$store.commit('set_form_notification', response.notifications);
183 self.$store.commit('set_form_settings', response.settings);
184
185 // if nothing saved in the form, it provides an empty array
186 // but we expect to be an object
187 if ( response.integrations.length !== undefined ) {
188 self.$store.commit('set_form_integrations', {});
189 } else {
190 self.$store.commit('set_form_integrations', response.integrations);
191 }
192 },
193 error: function(error) {
194 alert(error);
195 },
196
197 complete: function() {
198 self.loading = false;
199 }
200 });
201 },
202
203 // set current sidebar panel
204 set_current_panel: function (panel) {
205 this.$store.commit('set_current_panel', panel);
206 },
207
208 // save form builder data
209 save_form_builder: function () {
210 var self = this;
211
212 if (_.isFunction(this.validate_form_before_submit) && !this.validate_form_before_submit()) {
213
214 this.warn({
215 text: this.validation_error_msg
216 });
217
218 return;
219 }
220
221 self.is_form_saving = true;
222 self.set_current_panel('form-fields');
223
224 wp.ajax.send('wpuf_form_builder_save_form', {
225 data: {
226 form_data: $('#wpuf-form-builder').serialize(),
227 form_fields: JSON.stringify(self.form_fields),
228 notifications: JSON.stringify(self.notifications),
229 settings: JSON.stringify(self.settings),
230 payment: JSON.stringify(self.payment),
231 integrations: JSON.stringify(self.integrations),
232 },
233
234 success: function (response) {
235 if (response.form_fields) {
236 self.$store.commit('set_form_fields', response.form_fields);
237 }
238
239 self.is_form_saving = false;
240 self.is_form_saved = true;
241
242 setTimeout(function(){
243 window.weFormsBuilderisDirty = false;
244 },500);
245
246 toastr.success(self.i18n.saved_form_data);
247 },
248
249 error: function () {
250 self.is_form_saving = false;
251 }
252 });
253 },
254
255
256 save_settings: function () {
257 toastr.options.preventDuplicates = true;
258 this.save_form_builder();
259 },
260
261 shareForm: function( site_url, post ) {
262
263 var self = this;
264
265 if( self.settings.sharing_on === 'on'){
266
267 var post_link = site_url + '?weforms=' + btoa( self.getSharingHash() + '_' + Math.floor(Date.now() / 1000) + '_' + post.ID);
268
269 swal({
270 title: self.i18n.shareYourForm,
271 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>',
272 showCloseButton: true,
273 showCancelButton: true,
274 confirmButtonClass: 'btn btn-success',
275 cancelButtonClass: 'btn btn-danger',
276 confirmButtonColor: '#d54e21',
277 confirmButtonText: self.i18n.disableSharing,
278 cancelButtonText: self.i18n.close,
279 focusCancel: true,
280
281 }).then(function () {
282 swal({
283 title: self.i18n.areYouSure,
284 html: "<p>"+self.i18n.areYouSureDesc+"</p>",
285 type: 'info',
286 confirmButtonColor: '#d54e21',
287 showCancelButton: true,
288 confirmButtonText: self.i18n.disable,
289 cancelButtonText: self.i18n.cancel,
290 }).then(function () {
291 self.disableSharing();
292 });
293 });
294
295 } else {
296
297 swal({
298 title: self.i18n.shareYourForm,
299 html: self.i18n.shareYourFormDesc,
300 type: 'info',
301 showCancelButton: true,
302 confirmButtonText: 'Enable',
303 cancelButtonText: 'Cancel',
304 }).then(function () {
305 self.enableSharing(site_url, post);
306 });
307
308 }
309 },
310
311 enableSharing: function(site_url, post){
312
313 this.settings.sharing_on = 'on';
314 this.save_settings();
315 this.shareForm(site_url, post);
316 },
317
318 disableSharing: function(){
319 this.settings.sharing_on = false;
320 this.save_settings();
321 },
322 getSharingHash: function(){
323
324 if( ! this.settings.sharing_hash ) {
325 this.settings.sharing_hash = this.makeRandomString(8);
326 this.save_settings();
327 }
328
329 return this.settings.sharing_hash;
330 },
331
332 makeRandomString: function(limit) {
333 limit = limit || 8;
334 var text = "";
335 var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
336
337 for (var i = 0; i < limit; i++){
338
339 text += possible.charAt(Math.floor(Math.random() * possible.length));
340 }
341
342 return text;
343 },
344
345 initSharingClipBoard: function(val) {
346 var clipboard2 = new window.Clipboard('.anonymous-share-btn');
347
348 $(".anonymous-share-btn").tooltip();
349
350 clipboard2.on('success', function(e) {
351 // Show copied tooltip
352 $(e.trigger)
353 .attr('data-original-title', 'Copied!')
354 .tooltip('show');
355
356 // Reset the copied tooltip
357 setTimeout(function() {
358 $(e.trigger).tooltip('hide')
359 .attr('data-original-title', 'Copy URL');
360 }, 1000);
361
362 e.clearSelection();
363 });
364 },
365
366 }
367 };
368