lab3 next step
This commit is contained in:
parent
cc4ce94782
commit
060d8225b8
@ -69,33 +69,13 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Book</th>
|
||||
<th scope="col">Category</th>
|
||||
<th scope="col">Author</th>
|
||||
<th scope="col">Gener</th>
|
||||
<th scope="col">ISBN</th>
|
||||
<th scope="col">Price</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><img src="png/books/capital.jpg" class="w-100 img-fluid"
|
||||
id="tabel_car"></th>
|
||||
<td>Capital</td>
|
||||
<td>Marks K.</td>
|
||||
<td>Philosofy</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><img src="png/books/capital.jpg" class="w-100 img-fluid"
|
||||
id="tabel_car"></th>
|
||||
<td>Capital</td>
|
||||
<td>Marks K.</td>
|
||||
<td>Philosofy</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><img src="png/books/capital.jpg" class="w-100 img-fluid"
|
||||
id="tabel_car"></th>
|
||||
<td>Capital</td>
|
||||
<td>Marks K.</td>
|
||||
<td>Philosofy</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@ -132,18 +112,22 @@
|
||||
<input id="name" name="name" class="form-control" type="text" placeholder="Name"
|
||||
required />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<input id="author" name="author" class="form-control" type="text" placeholder="Author"
|
||||
required />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label" for="price">Price</label>
|
||||
<input id="price" name="price" class="form-control" type="number" value="0.00"
|
||||
min="1000.00" step="0.50" required>
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label" for="count">Number</label>
|
||||
<label class="form-label" for="count">ISBN</label>
|
||||
<input id="count" name="count" class="form-control" type="number" value="0" min="1"
|
||||
step="1" required>
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label" for="image">Изображение</label>
|
||||
<label class="form-label" for="image">Image</label>
|
||||
<input id="image" type="file" name="image" class="form-control" accept="image/*">
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
|
File diff suppressed because one or more lines are too long
@ -19,6 +19,8 @@ const modalTitle = document.getElementById('items-update-title');
|
||||
function resetValues() {
|
||||
cntrls.lineId.value = '';
|
||||
cntrls.itemsType.value = '';
|
||||
cntrls.author.value = '';
|
||||
cntrls.name.value = '';
|
||||
cntrls.price.value = parseFloat(0).toFixed(2);
|
||||
cntrls.count.value = 0;
|
||||
cntrls.image.value = '';
|
||||
@ -36,6 +38,7 @@ export function showUpdateModal(item) {
|
||||
if (item) {
|
||||
cntrls.lineId.value = item.id;
|
||||
cntrls.itemsType.value = item.itemsId;
|
||||
cntrls.author.value = item.author;
|
||||
cntrls.price.value = item.price;
|
||||
cntrls.count.value = item.count;
|
||||
// заполнение превью
|
||||
|
@ -5,12 +5,13 @@ const serverUrl = 'http://localhost:8081';
|
||||
|
||||
// функция возвращает объект нужной структуры для отправки на сервер
|
||||
// eslint-disable-next-line require-jsdoc
|
||||
function createLineObject(item, price, count, image) {
|
||||
function createLineObject(item, author, price, count, image) {
|
||||
return {
|
||||
itemsId: item,
|
||||
price: parseFloat(price).toFixed(2),
|
||||
author,
|
||||
count,
|
||||
sum: parseFloat(price * count).toFixed(2),
|
||||
price: parseFloat(price).toFixed(2),
|
||||
image,
|
||||
};
|
||||
}
|
||||
@ -49,8 +50,8 @@ export async function getLine(id) {
|
||||
// обращение к серверу для создания записи (post)
|
||||
// объект отправляется в теле запроса (body)
|
||||
// eslint-disable-next-line require-jsdoc
|
||||
export async function createLine(item, price, count, image) {
|
||||
const itemObject = createLineObject(item, price, count, image);
|
||||
export async function createLine(item, author, price, count, image) {
|
||||
const itemObject = createLineObject(item, author, price, count, image);
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
|
@ -9,6 +9,8 @@ export const cntrls = {
|
||||
form: document.getElementById('items-form'),
|
||||
lineId: document.getElementById('items-line-id'),
|
||||
itemsType: document.getElementById('item'),
|
||||
author: document.getElementById('author'),
|
||||
name: document.getElementById('name'),
|
||||
price: document.getElementById('price'),
|
||||
count: document.getElementById('count'),
|
||||
image: document.getElementById('image'),
|
||||
@ -88,9 +90,9 @@ export function createTableRow(item, index, editCallback, editPageCallback, dele
|
||||
|
||||
row.appendChild(rowNumber);
|
||||
row.appendChild(createTableColumn(item.items.name));
|
||||
row.appendChild(createTableColumn(parseFloat(item.price).toFixed(2)));
|
||||
row.appendChild(createTableColumn(item.author));
|
||||
row.appendChild(createTableColumn(item.count));
|
||||
row.appendChild(createTableColumn(parseFloat(item.sum).toFixed(2)));
|
||||
row.appendChild(createTableColumn(parseFloat(item.price).toFixed(2)));
|
||||
// редактировать в модальном окне
|
||||
row.appendChild(createTableAnchor('fa-pencil', editCallback));
|
||||
// редактировать на странице page-edit
|
||||
|
@ -59,10 +59,10 @@ async function drawLinesTable() {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-jsdoc
|
||||
async function addLine(item, price, count, image) {
|
||||
async function addLine(item, author, price, count, image) {
|
||||
console.info('Try to add item');
|
||||
// вызов метода REST API для добавления записи
|
||||
const data = await createLine(item, price, count, image);
|
||||
const data = await createLine(item, author, price, count, image);
|
||||
console.info('Added');
|
||||
console.info(data);
|
||||
// загрузка и заполнение table
|
||||
@ -70,10 +70,10 @@ async function addLine(item, price, count, image) {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-jsdoc
|
||||
async function editLine(id, item, price, count, image) {
|
||||
async function editLine(id, item, author, price, count, image) {
|
||||
console.info('Try to update item');
|
||||
// вызов метода REST API для обновления записи
|
||||
const data = await updateLine(id, item, price, count, image);
|
||||
const data = await updateLine(id, item, author, price, count, image);
|
||||
console.info('Updated');
|
||||
console.info(data);
|
||||
// загрузка и заполнение table
|
||||
@ -199,6 +199,7 @@ export function linesForm() {
|
||||
if (!currentId) {
|
||||
await addLine(
|
||||
cntrls.itemsType.value,
|
||||
cntrls.author.value,
|
||||
cntrls.price.value,
|
||||
cntrls.count.value,
|
||||
imageBase64,
|
||||
@ -207,6 +208,7 @@ export function linesForm() {
|
||||
await editLine(
|
||||
currentId,
|
||||
cntrls.itemsType.value,
|
||||
cntrls.author.value,
|
||||
cntrls.price.value,
|
||||
cntrls.count.value,
|
||||
imageBase64,
|
||||
@ -249,6 +251,7 @@ export async function linesPageForm() {
|
||||
const line = await getLine(currentId);
|
||||
// заполнение формы для редактирования
|
||||
cntrls.itemsType.value = line.itemsId;
|
||||
cntrls.author.value = line.author;
|
||||
cntrls.price.value = line.price;
|
||||
cntrls.count.value = line.count;
|
||||
// заполнение превью
|
||||
@ -300,6 +303,7 @@ export async function linesPageForm() {
|
||||
if (!currentId) {
|
||||
await addLine(
|
||||
cntrls.itemsType.value,
|
||||
cntrls.author.value,
|
||||
cntrls.price.value,
|
||||
cntrls.count.value,
|
||||
imageBase64,
|
||||
@ -308,6 +312,7 @@ export async function linesPageForm() {
|
||||
await editLine(
|
||||
currentId,
|
||||
cntrls.itemsType.value,
|
||||
cntrls.author.value,
|
||||
cntrls.price.value,
|
||||
cntrls.count.value,
|
||||
imageBase64,
|
||||
|
Loading…
Reference in New Issue
Block a user