-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More fields dealt with - image in progress...
- Loading branch information
Showing
23 changed files
with
441 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function checkboxHelper(checkbox) | ||
{ | ||
checkbox.value = checkbox.checked; | ||
} | ||
|
||
function fileHelper(inputId, imgType, e) | ||
{ | ||
if(e.target.files && e.target.files[0] && e.target.files[0].size < 5242880) { | ||
const reader = new FileReader(); | ||
reader.onload = evt => { | ||
resizeImage(evt.target.result, imgType, 512, 1024, (r) => document.getElementById(inputId).value = r) | ||
} | ||
reader.readAsText(e.target.files[0]); | ||
} | ||
else | ||
{ | ||
alert("Impossible de d'envoyer l'image.") | ||
} | ||
} | ||
|
||
function resizeImage(imgBytes, imgType, maxWidth, maxHeight, cb) | ||
{ | ||
const blob = new Blob([byteArray]); | ||
|
||
const img = new Image(); | ||
const url = URL.createObjectURL(blob); | ||
|
||
img.onload = () => { | ||
const canvas = document.createElement('canvas'); | ||
const ctx = canvas.getContext('2d'); | ||
|
||
let width = img.width; | ||
let height = img.height; | ||
|
||
if (width > height) { | ||
if (width > maxWidth) { | ||
height *= maxWidth / width; | ||
width = maxWidth; | ||
} | ||
} else { | ||
if (height > maxHeight) { | ||
width *= maxHeight / height; | ||
height = maxHeight; | ||
} | ||
} | ||
|
||
canvas.width = width; | ||
canvas.height = height; | ||
|
||
ctx.drawImage(img, 0, 0, width, height); | ||
|
||
canvas.toBlob((resizedBlob) => { | ||
const reader = new FileReader(); | ||
reader.onload = function(event) { | ||
const resizedByteArray = new Uint8Array(event.target.result); | ||
cb(resizedByteArray); | ||
}; | ||
reader.readAsArrayBuffer(resizedBlob); | ||
}, imgType); | ||
|
||
URL.revokeObjectURL(url); | ||
}; | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace Models; | ||
|
||
class GenreModel | ||
{ | ||
public int $Id; | ||
public string $Name; | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/Utils/Components/FormAreaComponent/FormAreaComponent.php
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,30 @@ | ||
<?php | ||
|
||
namespace Utils\Components\FormAreaComponent; | ||
|
||
class FormAreaComponent | ||
{ | ||
public string $name; | ||
public string $label; | ||
public ?string $value; | ||
public ?string $placeholder; | ||
public bool $required; | ||
public bool $readOnly; | ||
|
||
public function __construct(string $name, string $label, ?string $placeholder = null, ?string $value = "", bool $required = true, bool $readOnly = false) | ||
{ | ||
$this->name = $name; | ||
$this->label = $label; | ||
$this->value = $value; | ||
$this->placeholder = $placeholder; | ||
$this->required = $required; | ||
$this->readOnly = $readOnly; | ||
} | ||
|
||
public function getRenderedComponent() | ||
{ | ||
ob_start(); | ||
include "FormAreaComponent.template.php"; | ||
return ob_get_clean(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Utils/Components/FormAreaComponent/FormAreaComponent.template.php
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,11 @@ | ||
<label> | ||
<span><?php echo $this->label; ?></span> | ||
<textarea | ||
name="<?php echo $this->name; ?>" | ||
placeholder="<?php echo $this->placeholder; ?>" | ||
rows="10" | ||
cols="100" | ||
<?php echo $this->required?"required":""; ?> | ||
<?php echo $this->readOnly?"readOnly":""; ?> | ||
><?php echo $this->value; ?></textarea> | ||
</label> |
32 changes: 32 additions & 0 deletions
32
src/Utils/Components/FormImageComponent/FormImageComponent.php
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,32 @@ | ||
<?php | ||
|
||
namespace Utils\Components\FormImageComponent; | ||
|
||
class FormImageComponent | ||
{ | ||
public string $name; | ||
public string $label; | ||
public ?string $value; | ||
public ?string $base64Value; | ||
public ?string $imgType; | ||
public bool $required; | ||
public bool $readOnly; | ||
|
||
public function __construct(string $name, string $label, ?string $value, ?string $base64Value, ?string $imgType, bool $required = true, bool $readOnly = true) | ||
{ | ||
$this->name = $name; | ||
$this->label = $label; | ||
$this->value = $value; | ||
$this->base64Value = $base64Value; | ||
$this->imgType = $imgType; | ||
$this->required = $required; | ||
$this->readOnly = $readOnly; | ||
} | ||
|
||
public function getRenderedComponent() | ||
{ | ||
ob_start(); | ||
include "FormImageComponent.template.php"; | ||
return ob_get_clean(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Utils/Components/FormImageComponent/FormImageComponent.template.php
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,11 @@ | ||
<label> | ||
<span><?php echo $this->label; ?></span> | ||
<textarea style="display: none;" id="<?php echo $this->name; ?>" name="<?php echo $this->name; ?>"><?php echo $this->value; ?></textarea> | ||
<input type="file" | ||
accept="image/*" | ||
onchange="fileHelper('<?php echo $this->name; ?>', event)" | ||
id="file-<?php echo $this->name; ?>" | ||
<?php echo $this->required?"required":""; ?> | ||
/> | ||
<img src="data:<?php echo $this->imgType; ?>;base64,<?php echo $this->base64Value; ?>" alt="Image preview"/> | ||
</label> |
Oops, something went wrong.