| 1 |
/*! |
| 2 |
weForms - v1.0.0-beta.3 |
| 3 |
Generated: 2017-08-19 (1503138238582) |
| 4 |
*/ |
| 5 |
|
| 6 |
;(function($) { |
| 7 |
/* ./assets/spa/components/component-table/index.js */ |
| 8 |
Vue.component( 'wpuf-table', { |
| 9 |
template: '#tmpl-wpuf-component-table', |
| 10 |
mixins: [weForms.mixins.Loading, weForms.mixins.Paginate, weForms.mixins.BulkAction], |
| 11 |
props: { |
| 12 |
action: String, |
| 13 |
id: [String, Number] |
| 14 |
}, |
| 15 |
|
| 16 |
data: function() { |
| 17 |
return { |
| 18 |
loading: false, |
| 19 |
columns: [], |
| 20 |
items: [], |
| 21 |
ajaxAction: this.action, |
| 22 |
nonce: weForms.nonce, |
| 23 |
index: 'id', |
| 24 |
bulkDeleteAction: 'weforms_form_entry_trash_bulk' |
| 25 |
}; |
| 26 |
}, |
| 27 |
|
| 28 |
created: function() { |
| 29 |
this.fetchData(); |
| 30 |
}, |
| 31 |
|
| 32 |
computed: { |
| 33 |
columnLength: function() { |
| 34 |
return Object.keys(this.columns).length; |
| 35 |
}, |
| 36 |
}, |
| 37 |
methods: { |
| 38 |
|
| 39 |
fetchData: function() { |
| 40 |
var self = this; |
| 41 |
|
| 42 |
this.loading = true; |
| 43 |
|
| 44 |
wp.ajax.send( self.action, { |
| 45 |
data: { |
| 46 |
id: self.id, |
| 47 |
page: self.currentPage, |
| 48 |
_wpnonce: weForms.nonce |
| 49 |
}, |
| 50 |
success: function(response) { |
| 51 |
self.loading = false; |
| 52 |
self.columns = response.columns; |
| 53 |
self.items = response.entries; |
| 54 |
self.form_title = response.form_title; |
| 55 |
self.totalItems = response.pagination.total; |
| 56 |
self.totalPage = response.pagination.pages; |
| 57 |
|
| 58 |
self.$emit('ajaxsuccess', response); |
| 59 |
}, |
| 60 |
error: function(error) { |
| 61 |
self.loading = false; |
| 62 |
alert(error); |
| 63 |
} |
| 64 |
}); |
| 65 |
}, |
| 66 |
|
| 67 |
handleBulkAction: function() { |
| 68 |
if ( '-1' === this.bulkAction ) { |
| 69 |
alert( 'Please chose a bulk action to perform' ); |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
if ( 'delete' === this.bulkAction ) { |
| 74 |
if ( ! this.checkedItems.length ) { |
| 75 |
alert( 'Please select atleast one entry to delete.' ); |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
if ( confirm( 'Are you sure to delete the entries?' ) ) { |
| 80 |
this.deleteBulk(); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
} ); |
| 86 |
|
| 87 |
/* ./assets/spa/components/form-builder/index.js */ |
| 88 |
weForms.routeComponents.FormEditComponent = { |
| 89 |
template: '#tmpl-wpuf-form-builder', |
| 90 |
mixins: wpuf_form_builder_mixins(wpuf_mixins.root), |
| 91 |
data: function() { |
| 92 |
return { |
| 93 |
is_form_saving: false, |
| 94 |
is_form_saved: false, |
| 95 |
is_form_switcher: false, |
| 96 |
post_title_editing: false, |
| 97 |
loading: false, |
| 98 |
activeTab: 'editor', |
| 99 |
activeSettingsTab: 'form', |
| 100 |
}; |
| 101 |
}, |
| 102 |
|
| 103 |
watch: { |
| 104 |
loading: function(value) { |
| 105 |
if ( value ) { |
| 106 |
NProgress.configure({ parent: '#wpadminbar' }); |
| 107 |
NProgress.start(); |
| 108 |
} else { |
| 109 |
NProgress.done(); |
| 110 |
} |
| 111 |
}, |
| 112 |
|
| 113 |
}, |
| 114 |
|
| 115 |
created: function() { |
| 116 |
this.fetchForm(); |
| 117 |
|
| 118 |
this.$store.commit('panel_add_show_prop'); |
| 119 |
|
| 120 |
/** |
| 121 |
* This is the event hub we'll use in every |
| 122 |
* component to communicate between them |
| 123 |
*/ |
| 124 |
wpuf_form_builder.event_hub = new Vue(); |
| 125 |
}, |
| 126 |
|
| 127 |
computed: { |
| 128 |
current_panel: function () { |
| 129 |
return this.$store.state.current_panel; |
| 130 |
}, |
| 131 |
|
| 132 |
post: function () { |
| 133 |
return this.$store.state.post; |
| 134 |
}, |
| 135 |
|
| 136 |
form_fields_count: function () { |
| 137 |
return this.$store.state.form_fields.length; |
| 138 |
}, |
| 139 |
|
| 140 |
form_fields: function () { |
| 141 |
return this.$store.state.form_fields; |
| 142 |
}, |
| 143 |
|
| 144 |
notifications: function() { |
| 145 |
return this.$store.state.notifications; |
| 146 |
}, |
| 147 |
|
| 148 |
integrations: function() { |
| 149 |
return this.$store.state.integrations; |
| 150 |
}, |
| 151 |
|
| 152 |
settings: function() { |
| 153 |
return this.$store.state.settings; |
| 154 |
} |
| 155 |
}, |
| 156 |
|
| 157 |
mounted: function () { |
| 158 |
|
| 159 |
var clipboard = new window.Clipboard('.form-id'); |
| 160 |
$(".form-id").tooltip(); |
| 161 |
|
| 162 |
var self = this; |
| 163 |
|
| 164 |
this.isDirty = false; |
| 165 |
this.started = true; |
| 166 |
|
| 167 |
clipboard.on('success', function(e) { |
| 168 |
// Show copied tooltip |
| 169 |
$(e.trigger) |
| 170 |
.attr('data-original-title', 'Copied!') |
| 171 |
.tooltip('show'); |
| 172 |
|
| 173 |
// Reset the copied tooltip |
| 174 |
setTimeout(function() { |
| 175 |
$(e.trigger).tooltip('hide') |
| 176 |
.attr('data-original-title', self.i18n.copy_shortcode); |
| 177 |
}, 1000); |
| 178 |
|
| 179 |
e.clearSelection(); |
| 180 |
}); |
| 181 |
}, |
| 182 |
|
| 183 |
methods: { |
| 184 |
|
| 185 |
makeActive: function(val) { |
| 186 |
this.activeTab = val; |
| 187 |
}, |
| 188 |
|
| 189 |
isActiveTab: function(val) { |
| 190 |
return this.activeTab === val; |
| 191 |
}, |
| 192 |
|
| 193 |
isActiveSettingsTab: function(val) { |
| 194 |
return this.activeSettingsTab === val; |
| 195 |
}, |
| 196 |
|
| 197 |
makeActiveSettingsTab: function(val) { |
| 198 |
this.activeSettingsTab = val; |
| 199 |
}, |
| 200 |
|
| 201 |
fetchForm: function() { |
| 202 |
var self = this; |
| 203 |
|
| 204 |
self.loading = true; |
| 205 |
|
| 206 |
wp.ajax.send( 'weforms_get_form', { |
| 207 |
data: { |
| 208 |
form_id: this.$route.params.id, |
| 209 |
_wpnonce: weForms.nonce |
| 210 |
}, |
| 211 |
success: function(response) { |
| 212 |
|
| 213 |
self.$store.commit('set_form_post', response.post); |
| 214 |
self.$store.commit('set_form_fields', response.form_fields); |
| 215 |
self.$store.commit('set_form_notification', response.notifications); |
| 216 |
self.$store.commit('set_form_settings', response.settings); |
| 217 |
|
| 218 |
// if nothing saved in the form, it provides an empty array |
| 219 |
// but we expect to be an object |
| 220 |
if ( response.integrations.length !== undefined ) { |
| 221 |
self.$store.commit('set_form_integrations', {}); |
| 222 |
} else { |
| 223 |
self.$store.commit('set_form_integrations', response.integrations); |
| 224 |
} |
| 225 |
}, |
| 226 |
error: function(error) { |
| 227 |
alert(error); |
| 228 |
}, |
| 229 |
|
| 230 |
complete: function() { |
| 231 |
self.loading = false; |
| 232 |
} |
| 233 |
}); |
| 234 |
}, |
| 235 |
|
| 236 |
// set current sidebar panel |
| 237 |
set_current_panel: function (panel) { |
| 238 |
this.$store.commit('set_current_panel', panel); |
| 239 |
}, |
| 240 |
|
| 241 |
// save form builder data |
| 242 |
save_form_builder: function () { |
| 243 |
var self = this; |
| 244 |
|
| 245 |
if (_.isFunction(this.validate_form_before_submit) && !this.validate_form_before_submit()) { |
| 246 |
|
| 247 |
this.warn({ |
| 248 |
text: this.validation_error_msg |
| 249 |
}); |
| 250 |
|
| 251 |
return; |
| 252 |
} |
| 253 |
|
| 254 |
self.is_form_saving = true; |
| 255 |
self.set_current_panel('form-fields'); |
| 256 |
|
| 257 |
wp.ajax.send('wpuf_form_builder_save_form', { |
| 258 |
data: { |
| 259 |
form_data: $('#wpuf-form-builder').serialize(), |
| 260 |
form_fields: JSON.stringify(self.form_fields), |
| 261 |
notifications: JSON.stringify(self.notifications), |
| 262 |
settings: JSON.stringify(self.settings), |
| 263 |
integrations: JSON.stringify(self.integrations), |
| 264 |
}, |
| 265 |
|
| 266 |
success: function (response) { |
| 267 |
if (response.form_fields) { |
| 268 |
self.$store.commit('set_form_fields', response.form_fields); |
| 269 |
} |
| 270 |
|
| 271 |
self.is_form_saving = false; |
| 272 |
self.is_form_saved = true; |
| 273 |
|
| 274 |
toastr.success(self.i18n.saved_form_data); |
| 275 |
}, |
| 276 |
|
| 277 |
error: function () { |
| 278 |
self.is_form_saving = false; |
| 279 |
} |
| 280 |
}); |
| 281 |
} |
| 282 |
} |
| 283 |
}; |
| 284 |
|
| 285 |
/* ./assets/spa/components/form-entries/index.js */ |
| 286 |
weForms.routeComponents.FormEntries = { |
| 287 |
props: { |
| 288 |
id: [String, Number] |
| 289 |
}, |
| 290 |
template: '#tmpl-wpuf-form-entries', |
| 291 |
data: function() { |
| 292 |
return { |
| 293 |
form_title: 'Loading...' |
| 294 |
}; |
| 295 |
} |
| 296 |
}; |
| 297 |
/* ./assets/spa/components/form-entry-single/index.js */ |
| 298 |
weForms.routeComponents.FormEntriesSingle = { |
| 299 |
template: '#tmpl-wpuf-form-entry-single', |
| 300 |
mixins: [weForms.mixins.Loading], |
| 301 |
data: function() { |
| 302 |
return { |
| 303 |
loading: false, |
| 304 |
entry: { |
| 305 |
form_fields: {}, |
| 306 |
meta_data: {}, |
| 307 |
info: {} |
| 308 |
}, |
| 309 |
}; |
| 310 |
}, |
| 311 |
created: function() { |
| 312 |
this.fetchData(); |
| 313 |
}, |
| 314 |
computed: { |
| 315 |
hasFormFields: function() { |
| 316 |
return Object.keys(this.entry.form_fields).length; |
| 317 |
} |
| 318 |
}, |
| 319 |
methods: { |
| 320 |
fetchData: function() { |
| 321 |
var self = this; |
| 322 |
|
| 323 |
this.loading = true; |
| 324 |
|
| 325 |
wp.ajax.send( 'weforms_form_entry_details', { |
| 326 |
data: { |
| 327 |
entry_id: self.$route.params.entryid, |
| 328 |
_wpnonce: weForms.nonce |
| 329 |
}, |
| 330 |
success: function(response) { |
| 331 |
// console.log(response); |
| 332 |
self.loading = false; |
| 333 |
self.entry = response; |
| 334 |
}, |
| 335 |
error: function(error) { |
| 336 |
self.loading = false; |
| 337 |
alert(error); |
| 338 |
} |
| 339 |
}); |
| 340 |
}, |
| 341 |
|
| 342 |
trashEntry: function() { |
| 343 |
var self = this; |
| 344 |
|
| 345 |
if ( !confirm( weForms.confirm ) ) { |
| 346 |
return; |
| 347 |
} |
| 348 |
|
| 349 |
wp.ajax.send( 'weforms_form_entry_trash', { |
| 350 |
data: { |
| 351 |
entry_id: self.$route.params.entryid, |
| 352 |
_wpnonce: weForms.nonce |
| 353 |
}, |
| 354 |
|
| 355 |
success: function() { |
| 356 |
self.loading = false; |
| 357 |
|
| 358 |
self.$router.push({ name: 'formEntries', params: { id: self.$route.params.id }}); |
| 359 |
}, |
| 360 |
error: function(error) { |
| 361 |
self.loading = false; |
| 362 |
alert(error); |
| 363 |
} |
| 364 |
}); |
| 365 |
} |
| 366 |
} |
| 367 |
}; |
| 368 |
|
| 369 |
/* ./assets/spa/components/form-list-table/index.js */ |
| 370 |
Vue.component('form-list-table', { |
| 371 |
template: '#tmpl-wpuf-form-list-table', |
| 372 |
mixins: [weForms.mixins.Loading, weForms.mixins.Paginate, weForms.mixins.BulkAction], |
| 373 |
data: function() { |
| 374 |
return { |
| 375 |
loading: false, |
| 376 |
index: 'ID', |
| 377 |
items: [], |
| 378 |
bulkDeleteAction: 'weforms_form_delete_bulk' |
| 379 |
}; |
| 380 |
}, |
| 381 |
|
| 382 |
created: function() { |
| 383 |
this.fetchData(); |
| 384 |
}, |
| 385 |
|
| 386 |
methods: { |
| 387 |
fetchData: function() { |
| 388 |
var self = this; |
| 389 |
|
| 390 |
this.loading = true; |
| 391 |
|
| 392 |
wp.ajax.send( 'weforms_form_list', { |
| 393 |
data: { |
| 394 |
_wpnonce: weForms.nonce, |
| 395 |
page: self.currentPage, |
| 396 |
}, |
| 397 |
success: function(response) { |
| 398 |
self.loading = false; |
| 399 |
self.items = response.forms; |
| 400 |
self.totalItems = response.total; |
| 401 |
self.totalPage = response.pages; |
| 402 |
}, |
| 403 |
error: function(error) { |
| 404 |
self.loading = false; |
| 405 |
alert(error); |
| 406 |
} |
| 407 |
}); |
| 408 |
}, |
| 409 |
|
| 410 |
deleteForm: function(index) { |
| 411 |
var self = this; |
| 412 |
|
| 413 |
if (confirm('Are you sure?')) { |
| 414 |
self.loading = true; |
| 415 |
|
| 416 |
wp.ajax.send( 'weforms_form_delete', { |
| 417 |
data: { |
| 418 |
form_id: this.items[index].ID, |
| 419 |
_wpnonce: weForms.nonce |
| 420 |
}, |
| 421 |
success: function(response) { |
| 422 |
self.items.splice(index, 1); |
| 423 |
self.loading = false; |
| 424 |
}, |
| 425 |
error: function(error) { |
| 426 |
alert(error); |
| 427 |
self.loading = false; |
| 428 |
} |
| 429 |
}); |
| 430 |
} |
| 431 |
}, |
| 432 |
|
| 433 |
duplicate: function(form_id, index) { |
| 434 |
var self = this; |
| 435 |
|
| 436 |
this.loading = true; |
| 437 |
|
| 438 |
wp.ajax.send( 'weforms_form_duplicate', { |
| 439 |
data: { |
| 440 |
form_id: form_id, |
| 441 |
_wpnonce: weForms.nonce |
| 442 |
}, |
| 443 |
success: function(response) { |
| 444 |
self.items.splice(0, 0, response); |
| 445 |
self.loading = false; |
| 446 |
}, |
| 447 |
error: function(error) { |
| 448 |
alert(error); |
| 449 |
self.loading = false; |
| 450 |
} |
| 451 |
}); |
| 452 |
}, |
| 453 |
|
| 454 |
handleBulkAction: function() { |
| 455 |
if ( '-1' === this.bulkAction ) { |
| 456 |
alert( 'Please chose a bulk action to perform' ); |
| 457 |
return; |
| 458 |
} |
| 459 |
|
| 460 |
if ( 'delete' === this.bulkAction ) { |
| 461 |
if ( ! this.checkedItems.length ) { |
| 462 |
alert( 'Please select atleast one form to delete.' ); |
| 463 |
return; |
| 464 |
} |
| 465 |
|
| 466 |
if ( confirm( 'Are you sure to delete the forms?' ) ) { |
| 467 |
this.deleteBulk(); |
| 468 |
} |
| 469 |
} |
| 470 |
}, |
| 471 |
} |
| 472 |
}); |
| 473 |
/* ./assets/spa/components/home-page/index.js */ |
| 474 |
weForms.routeComponents.Home = { |
| 475 |
template: '#tmpl-wpuf-home-page', |
| 476 |
|
| 477 |
data: function() { |
| 478 |
return { |
| 479 |
showTemplateModal: false |
| 480 |
}; |
| 481 |
}, |
| 482 |
|
| 483 |
methods: { |
| 484 |
displayModal: function() { |
| 485 |
this.showTemplateModal = true; |
| 486 |
}, |
| 487 |
|
| 488 |
closeModal: function() { |
| 489 |
this.showTemplateModal = false; |
| 490 |
}, |
| 491 |
} |
| 492 |
}; |
| 493 |
|
| 494 |
/* ./assets/spa/components/tools/index.js */ |
| 495 |
weForms.routeComponents.Tools = { |
| 496 |
template: '#tmpl-wpuf-tools', |
| 497 |
mixins: [weForms.mixins.Tabs, weForms.mixins.Loading], |
| 498 |
data: function() { |
| 499 |
return { |
| 500 |
activeTab: 'export', |
| 501 |
exportType: 'all', |
| 502 |
loading: false, |
| 503 |
forms: [], |
| 504 |
importButton: 'Import', |
| 505 |
currentStatus: 0, |
| 506 |
responseMessage: '' |
| 507 |
}; |
| 508 |
}, |
| 509 |
|
| 510 |
computed: { |
| 511 |
|
| 512 |
isInitial() { |
| 513 |
return this.currentStatus === 0; |
| 514 |
}, |
| 515 |
|
| 516 |
isSaving() { |
| 517 |
return this.currentStatus === 1; |
| 518 |
}, |
| 519 |
|
| 520 |
isSuccess() { |
| 521 |
return this.currentStatus === 2; |
| 522 |
}, |
| 523 |
|
| 524 |
isFailed() { |
| 525 |
return this.currentStatus === 3; |
| 526 |
} |
| 527 |
}, |
| 528 |
|
| 529 |
created: function() { |
| 530 |
this.fetchData(); |
| 531 |
}, |
| 532 |
|
| 533 |
methods: { |
| 534 |
fetchData: function() { |
| 535 |
var self = this; |
| 536 |
|
| 537 |
this.loading = true; |
| 538 |
|
| 539 |
wp.ajax.send( 'weforms_form_names', { |
| 540 |
data: { |
| 541 |
_wpnonce: weForms.nonce |
| 542 |
}, |
| 543 |
success: function(response) { |
| 544 |
// console.log(response); |
| 545 |
self.loading = false; |
| 546 |
self.forms = response; |
| 547 |
}, |
| 548 |
error: function(error) { |
| 549 |
self.loading = false; |
| 550 |
alert(error); |
| 551 |
} |
| 552 |
}); |
| 553 |
}, |
| 554 |
|
| 555 |
importForm: function( fieldName, fileList, event ) { |
| 556 |
if ( !fileList.length ) { |
| 557 |
return; |
| 558 |
} |
| 559 |
|
| 560 |
var formData = new FormData(); |
| 561 |
var self = this; |
| 562 |
|
| 563 |
formData.append( fieldName, fileList[0], fileList[0].name); |
| 564 |
formData.append( 'action', 'weforms_import_form' ); |
| 565 |
formData.append( '_wpnonce', weForms.nonce ); |
| 566 |
|
| 567 |
self.currentStatus = 1; |
| 568 |
|
| 569 |
$.ajax({ |
| 570 |
type: "POST", |
| 571 |
url: window.ajaxurl, |
| 572 |
data: formData, |
| 573 |
processData: false, |
| 574 |
contentType: false, |
| 575 |
success: function(response) { |
| 576 |
self.responseMessage = response.data; |
| 577 |
|
| 578 |
if ( response.success ) { |
| 579 |
self.currentStatus = 2; |
| 580 |
} else { |
| 581 |
self.currentStatus = 3; |
| 582 |
} |
| 583 |
|
| 584 |
// reset the value |
| 585 |
$(event.target).val(''); |
| 586 |
}, |
| 587 |
|
| 588 |
error: function(errResponse) { |
| 589 |
console.log(errResponse); |
| 590 |
self.currentStatus = 3; |
| 591 |
}, |
| 592 |
|
| 593 |
complete: function() { |
| 594 |
$(event.target).val(''); |
| 595 |
} |
| 596 |
}); |
| 597 |
|
| 598 |
|
| 599 |
} |
| 600 |
} |
| 601 |
}; |
| 602 |
|
| 603 |
/* ./assets/spa/components/weforms-page-help/index.js */ |
| 604 |
weForms.routeComponents.Help = { |
| 605 |
template: '#tmpl-wpuf-weforms-page-help' |
| 606 |
}; |
| 607 |
/* ./assets/spa/components/weforms-premium/index.js */ |
| 608 |
weForms.routeComponents.Premium = { |
| 609 |
template: '#tmpl-wpuf-weforms-premium' |
| 610 |
}; |
| 611 |
/* ./assets/spa/components/weforms-settings/index.js */ |
| 612 |
weForms.routeComponents.Settings = { |
| 613 |
template: '#tmpl-wpuf-weforms-settings', |
| 614 |
mixins: [weForms.mixins.Loading], |
| 615 |
data: function() { |
| 616 |
return { |
| 617 |
loading: false, |
| 618 |
settings: { |
| 619 |
email_gateway: 'wordpress', |
| 620 |
gateways: { |
| 621 |
sendgrid: '', |
| 622 |
mailgun: '', |
| 623 |
sparkpost: '' |
| 624 |
}, |
| 625 |
recaptcha: { |
| 626 |
type: 'v2', |
| 627 |
key: '', |
| 628 |
secret: '' |
| 629 |
} |
| 630 |
} |
| 631 |
}; |
| 632 |
}, |
| 633 |
|
| 634 |
computed: { |
| 635 |
|
| 636 |
is_pro: function() { |
| 637 |
return 'true' === weForms.is_pro; |
| 638 |
} |
| 639 |
}, |
| 640 |
|
| 641 |
created: function() { |
| 642 |
this.fetchSettings(); |
| 643 |
}, |
| 644 |
|
| 645 |
methods: { |
| 646 |
|
| 647 |
fetchSettings: function() { |
| 648 |
var self = this; |
| 649 |
|
| 650 |
self.loading = true; |
| 651 |
|
| 652 |
wp.ajax.send('weforms_get_settings', { |
| 653 |
data: { |
| 654 |
_wpnonce: weForms.nonce |
| 655 |
}, |
| 656 |
|
| 657 |
success: function(response) { |
| 658 |
self.settings = response; |
| 659 |
}, |
| 660 |
|
| 661 |
complete: function() { |
| 662 |
self.loading = false; |
| 663 |
} |
| 664 |
}); |
| 665 |
}, |
| 666 |
|
| 667 |
saveSettings: function(target) { |
| 668 |
var self = this; |
| 669 |
|
| 670 |
$(target).addClass('updating-message'); |
| 671 |
|
| 672 |
wp.ajax.send('weforms_save_settings', { |
| 673 |
data: { |
| 674 |
settings: JSON.stringify(self.settings), |
| 675 |
_wpnonce: weForms.nonce |
| 676 |
}, |
| 677 |
|
| 678 |
success: function(response) { |
| 679 |
toastr.options.timeOut = 1000; |
| 680 |
toastr.success( 'Settings has been updated' ); |
| 681 |
}, |
| 682 |
|
| 683 |
error: function(error) { |
| 684 |
console.log(error); |
| 685 |
}, |
| 686 |
|
| 687 |
complete: function() { |
| 688 |
$(target).removeClass('updating-message'); |
| 689 |
} |
| 690 |
}); |
| 691 |
|
| 692 |
} |
| 693 |
} |
| 694 |
}; |
| 695 |
/* ./assets/spa/app.js */ |
| 696 |
if (!Array.prototype.hasOwnProperty('swap')) { |
| 697 |
Array.prototype.swap = function (from, to) { |
| 698 |
this.splice(to, 0, this.splice(from, 1)[0]); |
| 699 |
}; |
| 700 |
} |
| 701 |
|
| 702 |
Vue.component('datepicker', { |
| 703 |
template: '<input type="text" v-bind:value="value" v-on:input="$emit(\'input\', $event.target.value)" />', |
| 704 |
props: ['value'], |
| 705 |
mounted: function() { |
| 706 |
var self = this; |
| 707 |
|
| 708 |
$(this.$el).datetimepicker({ |
| 709 |
dateFormat: 'yy-mm-dd', |
| 710 |
timeFormat: "HH:mm:ss", |
| 711 |
onClose: this.onClose |
| 712 |
}); |
| 713 |
}, |
| 714 |
|
| 715 |
methods: { |
| 716 |
onClose: function(date) { |
| 717 |
this.$emit('input', date); |
| 718 |
} |
| 719 |
}, |
| 720 |
}); |
| 721 |
|
| 722 |
// check if an element is visible in browser viewport |
| 723 |
function is_element_in_viewport (el) { |
| 724 |
if (typeof jQuery === "function" && el instanceof jQuery) { |
| 725 |
el = el[0]; |
| 726 |
} |
| 727 |
|
| 728 |
var rect = el.getBoundingClientRect(); |
| 729 |
|
| 730 |
return ( |
| 731 |
rect.top >= 0 && |
| 732 |
rect.left >= 0 && |
| 733 |
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ |
| 734 |
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ |
| 735 |
); |
| 736 |
} |
| 737 |
|
| 738 |
/** |
| 739 |
* Vuex Store data |
| 740 |
*/ |
| 741 |
var wpuf_form_builder_store = new Vuex.Store({ |
| 742 |
state: { |
| 743 |
post: {}, |
| 744 |
form_fields: [], |
| 745 |
panel_sections: wpuf_form_builder.panel_sections, |
| 746 |
field_settings: wpuf_form_builder.field_settings, |
| 747 |
notifications: [], |
| 748 |
settings: {}, |
| 749 |
integrations: {}, |
| 750 |
current_panel: 'form-fields', |
| 751 |
editing_field_id: 0, // editing form field id |
| 752 |
}, |
| 753 |
|
| 754 |
mutations: { |
| 755 |
set_form_fields: function (state, form_fields) { |
| 756 |
Vue.set(state, 'form_fields', form_fields); |
| 757 |
}, |
| 758 |
|
| 759 |
set_form_post: function (state, post) { |
| 760 |
Vue.set(state, 'post', post); |
| 761 |
}, |
| 762 |
|
| 763 |
set_form_notification: function (state, value) { |
| 764 |
Vue.set(state, 'notifications', value); |
| 765 |
}, |
| 766 |
|
| 767 |
set_form_integrations: function (state, value) { |
| 768 |
Vue.set(state, 'integrations', value); |
| 769 |
}, |
| 770 |
|
| 771 |
set_form_settings: function (state, value) { |
| 772 |
Vue.set(state, 'settings', value); |
| 773 |
}, |
| 774 |
|
| 775 |
// set the current panel |
| 776 |
set_current_panel: function (state, panel) { |
| 777 |
if ('field-options' !== state.current_panel && |
| 778 |
'field-options' === panel && |
| 779 |
state.form_fields.length |
| 780 |
) { |
| 781 |
state.editing_field_id = state.form_fields[0].id; |
| 782 |
} |
| 783 |
|
| 784 |
state.current_panel = panel; |
| 785 |
|
| 786 |
// reset editing field id |
| 787 |
if ('form-fields' === panel) { |
| 788 |
state.editing_field_id = 0; |
| 789 |
} |
| 790 |
}, |
| 791 |
|
| 792 |
// add show property to every panel section |
| 793 |
panel_add_show_prop: function (state) { |
| 794 |
state.panel_sections.map(function (section, index) { |
| 795 |
if (!section.hasOwnProperty('show')) { |
| 796 |
Vue.set(state.panel_sections[index], 'show', true); |
| 797 |
} |
| 798 |
}); |
| 799 |
}, |
| 800 |
|
| 801 |
// toggle panel sections |
| 802 |
panel_toggle: function (state, index) { |
| 803 |
state.panel_sections[index].show = !state.panel_sections[index].show; |
| 804 |
}, |
| 805 |
|
| 806 |
// open field settings panel |
| 807 |
open_field_settings: function (state, field_id) { |
| 808 |
var field = state.form_fields.filter(function(item) { |
| 809 |
return parseInt(field_id) === parseInt(item.id); |
| 810 |
}); |
| 811 |
|
| 812 |
if ('field-options' === state.current_panel && field[0].id === state.editing_field_id) { |
| 813 |
return; |
| 814 |
} |
| 815 |
|
| 816 |
if (field.length) { |
| 817 |
state.editing_field_id = 0; |
| 818 |
state.current_panel = 'field-options'; |
| 819 |
|
| 820 |
setTimeout(function () { |
| 821 |
state.editing_field_id = field[0].id; |
| 822 |
}, 400); |
| 823 |
} |
| 824 |
}, |
| 825 |
|
| 826 |
update_editing_form_field: function (state, payload) { |
| 827 |
var editing_field = _.find(state.form_fields, function (item) { |
| 828 |
return parseInt(item.id) === parseInt(payload.editing_field_id); |
| 829 |
}); |
| 830 |
|
| 831 |
editing_field[payload.field_name] = payload.value; |
| 832 |
}, |
| 833 |
|
| 834 |
// add new form field element |
| 835 |
add_form_field_element: function (state, payload) { |
| 836 |
state.form_fields.splice(payload.toIndex, 0, payload.field); |
| 837 |
|
| 838 |
// bring newly added element into viewport |
| 839 |
Vue.nextTick(function () { |
| 840 |
var el = $('#form-preview-stage .wpuf-form .field-items').eq(payload.toIndex); |
| 841 |
|
| 842 |
if (el && !is_element_in_viewport(el.get(0))) { |
| 843 |
$('#builder-stage section').scrollTo(el, 800, {offset: -50}); |
| 844 |
} |
| 845 |
}); |
| 846 |
}, |
| 847 |
|
| 848 |
// sorting inside stage |
| 849 |
swap_form_field_elements: function (state, payload) { |
| 850 |
state.form_fields.swap(payload.fromIndex, payload.toIndex); |
| 851 |
}, |
| 852 |
|
| 853 |
clone_form_field_element: function (state, payload) { |
| 854 |
var field = _.find(state.form_fields, function (item) { |
| 855 |
return parseInt(item.id) === parseInt(payload.field_id); |
| 856 |
}); |
| 857 |
|
| 858 |
var clone = $.extend(true, {}, field), |
| 859 |
index = parseInt(payload.index) + 1; |
| 860 |
|
| 861 |
clone.id = payload.new_id; |
| 862 |
clone.name = clone.name + '_copy'; |
| 863 |
|
| 864 |
state.form_fields.splice(index, 0, clone); |
| 865 |
}, |
| 866 |
|
| 867 |
// delete a field |
| 868 |
delete_form_field_element: function (state, index) { |
| 869 |
state.current_panel = 'form-fields'; |
| 870 |
state.form_fields.splice(index, 1); |
| 871 |
}, |
| 872 |
|
| 873 |
// set fields for a panel section |
| 874 |
set_panel_section_fields: function (state, payload) { |
| 875 |
var section = _.find(state.panel_sections, function (item) { |
| 876 |
return item.id === payload.id; |
| 877 |
}); |
| 878 |
|
| 879 |
section.fields = payload.fields; |
| 880 |
}, |
| 881 |
|
| 882 |
// notifications |
| 883 |
addNotification: function(state, payload) { |
| 884 |
state.notifications.push(payload); |
| 885 |
}, |
| 886 |
|
| 887 |
deleteNotification: function(state, index) { |
| 888 |
state.notifications.splice(index, 1); |
| 889 |
}, |
| 890 |
|
| 891 |
cloneNotification: function(state, index) { |
| 892 |
var clone = $.extend(true, {}, state.notifications[index]); |
| 893 |
|
| 894 |
index = parseInt(index) + 1; |
| 895 |
state.notifications.splice(index, 0, clone); |
| 896 |
}, |
| 897 |
|
| 898 |
// update by it's property |
| 899 |
updateNotificationProperty: function(state, payload) { |
| 900 |
state.notifications[payload.index][payload.property] = payload.value; |
| 901 |
}, |
| 902 |
|
| 903 |
updateNotification: function(state, payload) { |
| 904 |
state.notifications[payload.index] = payload.value; |
| 905 |
}, |
| 906 |
|
| 907 |
updateIntegration: function(state, payload) { |
| 908 |
// console.log(payload); |
| 909 |
// console.log(state.integrations[payload.index]); |
| 910 |
// state.integrations[payload.index] = payload.value; |
| 911 |
Vue.set(state.integrations, payload.index, payload.value) |
| 912 |
|
| 913 |
// state.integrations.splice(payload.index, 0, payload.value); |
| 914 |
} |
| 915 |
} |
| 916 |
}); |
| 917 |
|
| 918 |
// 1. Define route components. |
| 919 |
weForms.routeComponents.FormHome = { template: '<div><router-view class="child"></router-view></div>' }; |
| 920 |
weForms.routeComponents.SingleForm = { template: '#tmpl-wpuf-form-editor' }; |
| 921 |
weForms.routeComponents.FormEntriesHome = { |
| 922 |
template: '<div><router-view class="grand-child"></router-view></div>', |
| 923 |
}; |
| 924 |
|
| 925 |
/** |
| 926 |
* Parse the route array and bind required components |
| 927 |
* |
| 928 |
* This changes the weForms.routes array and changes the components |
| 929 |
* so we can use weForms.routeComponents.{compontent} component. |
| 930 |
* |
| 931 |
* @param {array} routes |
| 932 |
* |
| 933 |
* @return {void} |
| 934 |
*/ |
| 935 |
function parseRouteComponent(routes) { |
| 936 |
|
| 937 |
for (var i = 0; i < routes.length; i++) { |
| 938 |
if ( typeof routes[i].children === 'object' ) { |
| 939 |
|
| 940 |
parseRouteComponent( routes[i].children ); |
| 941 |
|
| 942 |
if ( typeof routes[i].component !== 'undefined' ) { |
| 943 |
routes[i].component = weForms.routeComponents[ routes[i].component ]; |
| 944 |
} |
| 945 |
|
| 946 |
} else { |
| 947 |
routes[i].component = weForms.routeComponents[ routes[i].component ]; |
| 948 |
} |
| 949 |
} |
| 950 |
} |
| 951 |
|
| 952 |
// mutate the localized array |
| 953 |
parseRouteComponent(weForms.routes); |
| 954 |
|
| 955 |
// 3. Create the router instance and pass the `routes` option |
| 956 |
var router = new VueRouter({ |
| 957 |
routes: weForms.routes, |
| 958 |
scrollBehavior: function (to, from, savedPosition) { |
| 959 |
if (savedPosition) { |
| 960 |
return savedPosition |
| 961 |
} else { |
| 962 |
return { x: 0, y: 0 } |
| 963 |
} |
| 964 |
} |
| 965 |
}); |
| 966 |
|
| 967 |
var app = new Vue({ |
| 968 |
router, |
| 969 |
store: wpuf_form_builder_store |
| 970 |
}).$mount('#wpuf-contact-form-app') |
| 971 |
|
| 972 |
// Admin menu hack |
| 973 |
var menuRoot = $('#toplevel_page_weforms'); |
| 974 |
|
| 975 |
menuRoot.on('click', 'a', function() { |
| 976 |
var self = $(this); |
| 977 |
|
| 978 |
$('ul.wp-submenu li', menuRoot).removeClass('current'); |
| 979 |
|
| 980 |
if ( self.hasClass('wp-has-submenu') ) { |
| 981 |
$('li.wp-first-item', menuRoot).addClass('current'); |
| 982 |
} else { |
| 983 |
self.parents('li').addClass('current'); |
| 984 |
} |
| 985 |
}); |
| 986 |
|
| 987 |
$(function() { |
| 988 |
|
| 989 |
// select the current sub menu on page load |
| 990 |
var current_url = window.location.href; |
| 991 |
var current_path = current_url.substr( current_url.indexOf('admin.php') ); |
| 992 |
|
| 993 |
$('ul.wp-submenu a', menuRoot).each(function(index, el) { |
| 994 |
if ( $(el).attr( 'href' ) === current_path ) { |
| 995 |
$(el).parent().addClass('current'); |
| 996 |
return; |
| 997 |
} |
| 998 |
}); |
| 999 |
}); |
| 1000 |
|
| 1001 |
})(jQuery); |