.circleci
assets
css
fonts
img
js
gateways
lib
addons.js
addons.min.js
admin-notices.js
admin-notices.min.js
admin-screen.js
admin-screen.min.js
admin.js
admin.min.js
app.js
app.min.js
checkout-form-editor-modal.js
checkout-form-editor-modal.min.js
checkout-forms-editor.js
checkout-forms-editor.min.js
checkout.js
checkout.min.js
cookie-helpers.js
cookie-helpers.min.js
customizer.js
customizer.min.js
dashboard-statistics.js
dashboard-statistics.min.js
edit-placeholders.js
edit-placeholders.min.js
email-edit-page.js
email-edit-page.min.js
event-view-page.js
event-view-page.min.js
fields.js
fields.min.js
functions.js
functions.min.js
gutenberg-support.js
gutenberg-support.min.js
jumper.js
jumper.min.js
legacy-signup.js
legacy-signup.min.js
list-tables.js
list-tables.min.js
screenshot-scraper.js
screenshot-scraper.min.js
selectizer.js
selectizer.min.js
setup-wizard-polyfill.js
setup-wizard-polyfill.min.js
setup-wizard.js
setup-wizard.min.js
site-maintenance.js
site-maintenance.min.js
sso.js
sso.min.js
support.js
support.min.js
tax-rates.js
tax-rates.min.js
tax-statistics.js
tax-statistics.min.js
template-previewer.js
template-previewer.min.js
template-switching.js
template-switching.min.js
thank-you.js
thank-you.min.js
tours.js
tours.min.js
url-preview.js
url-preview.min.js
view-logs.js
view-logs.min.js
visits-counter.js
visits-counter.min.js
vue-apps.js
vue-apps.min.js
webhook-list-page.js
webhook-list-page.min.js
webhook-page.js
webhook-page.min.js
wubox.js
wubox.min.js
bin
data
inc
lang
patches
tests
views
.gitignore
.phpcs.xml.dist
LICENSE
autoload.php
composer.json
composer.lock
constants.php
loco.xml
phpunit.xml.dist
readme.txt
sunrise.php
uninstall.php
wp-multisite-waas.php
232 lines
4.7 KiB
JavaScript
232 lines
4.7 KiB
JavaScript
/* eslint-disable no-lonely-if */
|
|
/* global Vue, wu_block_ui, ajaxurl, wu_placeholdersl10n */
|
|
(function($) {
|
|
|
|
$(document).ready(function() {
|
|
|
|
/**
|
|
* Vue
|
|
*/
|
|
if ($('#wu-template-placeholders').length) {
|
|
|
|
window.wu_placeholders = new Vue({
|
|
el: '#wu-template-placeholders',
|
|
data: {
|
|
tax_category: 'default',
|
|
switching: false,
|
|
creating: false,
|
|
create_name: '',
|
|
toggle: false,
|
|
loading: true,
|
|
saving: false,
|
|
initialLoading: true,
|
|
error: false,
|
|
changed: false,
|
|
data: {
|
|
placeholders: [],
|
|
},
|
|
delete: [],
|
|
saveMessage: '',
|
|
errorMessage: '',
|
|
rate_type: 'standard_rate',
|
|
},
|
|
watch: {
|
|
data: {
|
|
deep: true,
|
|
handler() {
|
|
|
|
if (this.initialLoading) {
|
|
|
|
this.initialLoading = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
},
|
|
loading(new_value) {
|
|
|
|
if (new_value === true) {
|
|
|
|
window.wu_blocked_table = wu_block_ui('table.wp-list-table');
|
|
|
|
} else {
|
|
|
|
if (typeof window.wu_blocked_table !== 'undefined') {
|
|
|
|
window.wu_blocked_table.unblock();
|
|
|
|
} // end if;
|
|
|
|
} // end if;
|
|
|
|
},
|
|
},
|
|
mounted() {
|
|
|
|
this.loading = true;
|
|
|
|
this.pull_data(true);
|
|
|
|
$('.wu-tooltip-vue').tipTip();
|
|
|
|
},
|
|
created() {
|
|
|
|
// Create the event.
|
|
const event = document.createEvent('Event');
|
|
|
|
// Define that the event name is 'build'.
|
|
event.initEvent('vue_loaded', true, true);
|
|
|
|
event.vue = this;
|
|
|
|
// target can be any Element or other EventTarget.
|
|
window.dispatchEvent(event);
|
|
|
|
},
|
|
computed: {
|
|
selected() {
|
|
|
|
return $(this.data.placeholders).filter(function(index, item) {
|
|
|
|
return item.selected;
|
|
|
|
});
|
|
|
|
},
|
|
},
|
|
methods: {
|
|
refresh(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.loading = true;
|
|
|
|
this.pull_data();
|
|
|
|
},
|
|
select_all(event) {
|
|
|
|
const toggle = $(event.target).is(':checked');
|
|
|
|
this.data.placeholders = $.map(this.data.placeholders, function(item) {
|
|
|
|
item.selected = toggle;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
},
|
|
pull_data() {
|
|
|
|
const that = this;
|
|
|
|
jQuery.getJSON(ajaxurl + '?action=wu_get_placeholders').done(function(response) {
|
|
|
|
that.loading = false;
|
|
|
|
that.data = response.data;
|
|
|
|
})
|
|
.fail(function(error) {
|
|
|
|
that.loading = false;
|
|
|
|
that.error = true;
|
|
|
|
that.errorMessage = error.statusText;
|
|
|
|
});
|
|
|
|
},
|
|
add_row() {
|
|
|
|
Vue.set(this.data, 'placeholders', this.data.placeholders.concat([
|
|
{
|
|
placeholder: '',
|
|
content: '',
|
|
selected: false,
|
|
},
|
|
]));
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
delete_rows() {
|
|
|
|
this.delete = this.delete.concat(this.selected.get());
|
|
|
|
// eslint-disable-next-line no-alert
|
|
const are_you_sure = confirm(wu_placeholdersl10n.confirm_message);
|
|
|
|
if (are_you_sure) {
|
|
|
|
const cleaned_list = $(this.data.placeholders).filter(function(index, item) {
|
|
|
|
return ! item.selected;
|
|
|
|
});
|
|
|
|
Vue.set(this.data, 'placeholders', cleaned_list.get());
|
|
|
|
this.$forceUpdate();
|
|
|
|
} // end if
|
|
|
|
},
|
|
save() {
|
|
|
|
const that = this;
|
|
|
|
that.saving = true;
|
|
|
|
$.post({
|
|
url: ajaxurl + '?action=wu_save_placeholders&' + $('#nonce_form').serialize(),
|
|
data: JSON.stringify({
|
|
placeholders: that.data.placeholders,
|
|
}),
|
|
dataType: 'json',
|
|
contentType: 'application/json; charset=utf-8',
|
|
}).success(function(data) {
|
|
|
|
that.saving = false;
|
|
|
|
that.changed = false;
|
|
|
|
that.delete = [];
|
|
|
|
that.saveMessage = data.message;
|
|
|
|
if (data.code === 'success') {
|
|
|
|
that.loading = true;
|
|
|
|
that.initialLoading = true;
|
|
|
|
that.pull_data();
|
|
|
|
}
|
|
|
|
setInterval(function() {
|
|
|
|
that.saveMessage = '';
|
|
|
|
}, 6000);
|
|
|
|
});
|
|
|
|
},
|
|
},
|
|
});
|
|
|
|
} // end if;
|
|
|
|
});
|
|
|
|
}(jQuery));
|