feat: colorpicker

This commit is contained in:
gdamms 2022-06-01 15:05:12 +02:00
parent 8850924f19
commit a39d06a405
4 changed files with 22 additions and 3 deletions

View file

@ -92,7 +92,7 @@ public class PixelService {
@Path("{id}/modify/") @Path("{id}/modify/")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void modify(@PathParam("id") Long id, @CookieParam("JSESSIONID") Cookie cookie, public void modify(@PathParam("id") Long id, @CookieParam("JSESSIONID") Cookie cookie,
@FormParam("red") int red, @FormParam("green") int green, @FormParam("blue") int blue, @FormParam("red") int red, @FormParam("green") int green, @FormParam("blue") int blue,@FormParam("color") String color,
@FormParam("price") int price, @FormParam("description") String description) { @FormParam("price") int price, @FormParam("description") String description) {
// on récupère le pixel de la db via son id // on récupère le pixel de la db via son id
Pixel pixel = em.find(Pixel.class, id); Pixel pixel = em.find(Pixel.class, id);
@ -103,7 +103,9 @@ public class PixelService {
if (user.equals(pixel.getOwner())) { if (user.equals(pixel.getOwner())) {
pixel.setPrice(price); pixel.setPrice(price);
pixel.setDescription(description); pixel.setDescription(description);
pixel.setColor(String.format("%02X%02X%02X", red, green, blue)); //pixel.setColor(String.format("%02X%02X%02X", red, green, blue));
String colorDisplay = color.substring(1,color.length());
pixel.setColor(colorDisplay);
// on ajoute la transaction // on ajoute la transaction
Date now = new Date(System.currentTimeMillis()); Date now = new Date(System.currentTimeMillis());

View file

@ -10,6 +10,8 @@
<script src="js/pixels.js"></script> <script src="js/pixels.js"></script>
<script src="js/user.js"></script> <script src="js/user.js"></script>
<script src="js/loaded.js"></script> <script src="js/loaded.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/mdbassit/Coloris@latest/dist/coloris.min.css"/>
<script src="https://cdn.jsdelivr.net/gh/mdbassit/Coloris@latest/dist/coloris.min.js"></script>
</head> </head>
<body onload="pageLoaded();"> <body onload="pageLoaded();">
@ -179,6 +181,8 @@
/> />
</div> </div>
<input type="text" name="color" id="colorpicker" data-coloris>
<div> <div>
<label>Description</label> <label>Description</label>
<input <input

View file

@ -1,5 +1,15 @@
// fonction qui s'execute quand la page a finie de charger // fonction qui s'execute quand la page a finie de charger
function pageLoaded() { function pageLoaded() {
Coloris({
alpha: false
});
// document.addEventListener('coloris:pick', event => {
// console.log('New color', event.detail.color);
// });
document.forms["pay-form"].addEventListener("submit", (event) => { document.forms["pay-form"].addEventListener("submit", (event) => {
event.preventDefault(); event.preventDefault();
fetch(event.target.action, { fetch(event.target.action, {

View file

@ -80,6 +80,9 @@ function updateModifyForm(pixel) {
let price = document.getElementById("modify-price"); let price = document.getElementById("modify-price");
price.value = pixel.price; price.value = pixel.price;
let colorpicker = document.getElementById("colorpicker")
colorpicker.value = "#" + pixel.color
let color = hexToRgb(pixel.color); let color = hexToRgb(pixel.color);
let red = document.getElementById("modify-red"); let red = document.getElementById("modify-red");