Version en ingles y español
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
const pllSettingsLicenses = {
|
||||
/**
|
||||
* Init.
|
||||
*/
|
||||
init: () => {
|
||||
if (document.readyState !== 'loading') {
|
||||
pllSettingsLicenses.ready();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', pllSettingsLicenses.ready);
|
||||
}
|
||||
},
|
||||
ready: () => {
|
||||
wp.hooks.addAction('pll_settings_saved', 'polylang-updater', pllSettingsLicenses.manageLicenses.onUpdate);
|
||||
pllSettingsLicenses.manageLicenses.display();
|
||||
},
|
||||
manageLicenses: {
|
||||
display: () => {
|
||||
const table = document.getElementById('pllu-licenses-table');
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
const action = table.getAttribute('data-action');
|
||||
const nonce = table.getAttribute('data-nonce');
|
||||
if (!action || !nonce) {
|
||||
return;
|
||||
}
|
||||
const urlParams = {
|
||||
action,
|
||||
_pll_nonce: nonce,
|
||||
pll_ajax_settings: 1
|
||||
};
|
||||
const url = wp.url.addQueryArgs(ajaxurl, urlParams);
|
||||
fetch(url).then(response => {
|
||||
return response.json();
|
||||
}).then(json => {
|
||||
if (!json.success) {
|
||||
return;
|
||||
}
|
||||
json.data.row.forEach(item => {
|
||||
table.insertAdjacentHTML('beforeend', item);
|
||||
});
|
||||
pllSettingsLicenses.manageLicenses.attachDeactivationEvent();
|
||||
});
|
||||
},
|
||||
attachDeactivationEvent: () => {
|
||||
let table = document.querySelector('#pllu-licenses-table');
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
table.addEventListener('click', el => {
|
||||
if (!el.target.classList.contains('pllu-deactivate-license')) {
|
||||
return;
|
||||
}
|
||||
const data = new FormData();
|
||||
data.set('action', 'pllu_deactivate_license');
|
||||
data.set('pll_ajax_settings', 1);
|
||||
data.set('id', el.target.id);
|
||||
data.set('_pll_nonce', document.querySelector('#_pll_nonce').value);
|
||||
|
||||
// POST request using fetch().
|
||||
fetch(ajaxurl, {
|
||||
method: "POST",
|
||||
body: data
|
||||
}).then(response => {
|
||||
return response.json();
|
||||
}).then(json => {
|
||||
if (!json.success) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Data comes from `License::get_form_field()`, where everything is escaped.
|
||||
const license = document.querySelector('#pllu-license-' + json.data.id);
|
||||
if (license) {
|
||||
license.outerHTML = json.data.html;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
onUpdate: response => {
|
||||
if ('pllu-license-update' === response.what) {
|
||||
const license = document.querySelector(`#pllu-license-${response.data}`);
|
||||
if (license) {
|
||||
license.outerHTML = response.supplemental.html;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
pllSettingsLicenses.init();
|
||||
+1
@@ -0,0 +1 @@
|
||||
const pllSettingsLicenses={init:()=>{"loading"!==document.readyState?pllSettingsLicenses.ready():document.addEventListener("DOMContentLoaded",pllSettingsLicenses.ready)},ready:()=>{wp.hooks.addAction("pll_settings_saved","polylang-updater",pllSettingsLicenses.manageLicenses.onUpdate),pllSettingsLicenses.manageLicenses.display()},manageLicenses:{display:()=>{const e=document.getElementById("pllu-licenses-table");if(!e)return;const t=e.getAttribute("data-action"),n=e.getAttribute("data-nonce");if(!t||!n)return;const s={action:t,_pll_nonce:n,pll_ajax_settings:1},a=wp.url.addQueryArgs(ajaxurl,s);fetch(a).then((e=>e.json())).then((t=>{t.success&&(t.data.row.forEach((t=>{e.insertAdjacentHTML("beforeend",t)})),pllSettingsLicenses.manageLicenses.attachDeactivationEvent())}))},attachDeactivationEvent:()=>{let e=document.querySelector("#pllu-licenses-table");e&&e.addEventListener("click",(e=>{if(!e.target.classList.contains("pllu-deactivate-license"))return;const t=new FormData;t.set("action","pllu_deactivate_license"),t.set("pll_ajax_settings",1),t.set("id",e.target.id),t.set("_pll_nonce",document.querySelector("#_pll_nonce").value),fetch(ajaxurl,{method:"POST",body:t}).then((e=>e.json())).then((e=>{if(!e.success)return;const t=document.querySelector("#pllu-license-"+e.data.id);t&&(t.outerHTML=e.data.html)}))}))},onUpdate:e=>{if("pllu-license-update"===e.what){const t=document.querySelector(`#pllu-license-${e.data}`);t&&(t.outerHTML=e.supplemental.html)}}}};pllSettingsLicenses.init();
|
||||
Reference in New Issue
Block a user