-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bouton to edit page on listing (product / category and CMS)
- Loading branch information
1 parent
baf862f
commit 7b6a624
Showing
4 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
const addPrettyButton = (btnGroupClass = '.btn-group-action', endpoint, idEndpointTarget) => { | ||
let btnGroups = document.querySelectorAll(btnGroupClass); | ||
btnGroups.forEach(btnGroup => { | ||
let id_cms = parseInt(btnGroup.closest('tr').querySelector(idEndpointTarget).textContent); | ||
|
||
// Début de la sélection | ||
let newElement = document.createElement('a'); | ||
newElement.innerHTML = "<img width='30' src='"+prettyblocks_logo+"' alt='edit in prettyblocks'>"; | ||
newElement.dataset.endpoint = endpoint; | ||
newElement.dataset.idEndpoint = id_cms; | ||
newElement.dataset.action = "open_in_prettyblocks"; | ||
// Fin de la sélection | ||
btnGroup.prepend(newElement); | ||
}); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function() { | ||
|
||
// CMS LIST Button | ||
if (document.body.classList.contains('admincmscontent')) { | ||
addPrettyButton('.btn-group-action', 'cms', '.column-id_cms'); | ||
} | ||
|
||
// Product LIST Button | ||
if (document.body.classList.contains('adminproducts')) { | ||
addPrettyButton('.btn-group-action', 'product', '.column-id_product'); | ||
} | ||
if (document.body.classList.contains('admincategories')) { | ||
addPrettyButton('.btn-group-action', 'category', '.column-id_category'); | ||
} | ||
|
||
|
||
// Début de la sélection | ||
let prettyBlocksButtons = document.querySelectorAll('[data-action="open_in_prettyblocks"]'); | ||
// Fin de la sélection | ||
prettyBlocksButtons.forEach(button => { | ||
button.addEventListener('click', function(event) { | ||
event.preventDefault(); | ||
// Ajoutez ici le code à exécuter lors du clic sur le bouton | ||
let endpoint = button.dataset.endpoint; | ||
let idEndpoint = button.dataset.idEndpoint; | ||
let action = button.dataset.action; | ||
let url = prettyblocks_route_generator; | ||
|
||
// Début de la sélection | ||
fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
endpoint: endpoint, | ||
id: idEndpoint, | ||
}), | ||
}) | ||
.then(response => response.json()) | ||
.then(data => window.open(data.url, '_self')); | ||
// Fin de la sélection | ||
}); | ||
}); | ||
|
||
|
||
}) |