-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshopkeeper.html
210 lines (191 loc) · 7.52 KB
/
shopkeeper.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopkeeper Portal - Manage Books</title>
<link rel="stylesheet" href="styles.css">
<style>
.table-container {
display: flex;
justify-content: center;
margin-top: 20px;
}
table {
border-collapse: collapse;
width: 80%;
text-align: center;
}
th, td {
padding: 10px;
border: 1px solid black;
}
th {
background-color: #f2f2f2;
}
td {
background-color: #fff;
}
.quantity-controls {
display: flex;
justify-content: center;
align-items: center;
}
.quantity-controls button {
margin: 0 5px;
}
.message-icon {
position: absolute;
top: 10px;
right: 10px;
}
.message-icon img {
width: 40px;
cursor: pointer;
}
</style>
</head>
<body>
<header>
<h1>Manage Books</h1>
<nav>
<a href="shopkeeper-requests.html">View Book Requests</a>
<a href="shopkeeper-feedback.html">View Customer Feedback</a>
</nav>
<a href="vendor.html" class="message-icon">
<img src="images/message-icon.png" alt="Cart">
</a>
</header>
<main>
<section id="bookManagement">
<h2>Available Books</h2>
<div class="table-container">
<table id="bookTable">
<thead>
<tr>
<th>Book Title</th>
<th>Price</th>
<th>Image</th>
<th>Quantity</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<!-- Books will be populated here -->
</tbody>
</table>
</div>
<h2>Add or Update Book</h2>
<form id="bookForm">
<label for="bookTitle">Book Title:</label>
<input type="text" id="bookTitle" required><br><br>
<label for="bookPrice">Price:</label>
<input type="text" id="bookPrice" required><br><br>
<label for="bookImage">Image URL:</label>
<input type="text" id="bookImage" required><br><br>
<label for="bookQuantity">Quantity:</label>
<input type="number" id="bookQuantity" min="1" required><br><br>
<button type="submit">Add/Update Book</button>
</form>
</section>
</main>
<footer>
<p>Book Automation Software © 2024</p>
</footer>
<script>
const predefinedBooks = [
{ title: 'The Great Gatsby', price: '$10.99', image: 'images/great-gatsby.jpg', quantity: 10 },
{ title: '1984', price: '$8.99', image: 'images/1984.jpg', quantity: 5 },
{ title: 'To Kill a Mockingbird', price: '$12.99', image: 'images/to-kill-a-mockingbird.jpg', quantity: 8 },
];
let books = [];
// Load existing books from localStorage or set predefined ones
document.addEventListener('DOMContentLoaded', function () {
const storedBooks = JSON.parse(localStorage.getItem('books'));
if (storedBooks && storedBooks.length > 0) {
books = storedBooks;
} else {
books = predefinedBooks;
localStorage.setItem('books', JSON.stringify(books));
}
renderBookTable();
});
function renderBookTable() {
const bookTableBody = document.querySelector('#bookTable tbody');
bookTableBody.innerHTML = '';
books.forEach((book, index) => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${book.title}</td>
<td>${book.price}</td>
<td><img src="${book.image}" alt="${book.title}" style="width:50px;height:75px;"></td>
<td>
<div class="quantity-controls">
<button class="decreaseBtn" data-index="${index}">-</button>
<span>${book.quantity}</span>
<button class="increaseBtn" data-index="${index}">+</button>
</div>
</td>
<td>
<button class="editBtn" data-index="${index}">Edit</button>
<button class="deleteBtn" data-index="${index}">Delete</button>
</td>
`;
bookTableBody.appendChild(row);
});
}
// Add or update book
document.getElementById('bookForm').addEventListener('submit', function (e) {
e.preventDefault();
const title = document.getElementById('bookTitle').value;
const price = document.getElementById('bookPrice').value;
const image = document.getElementById('bookImage').value;
const quantity = parseInt(document.getElementById('bookQuantity').value, 10);
const existingBookIndex = books.findIndex(book => book.title.toLowerCase() === title.toLowerCase());
if (existingBookIndex >= 0) {
books[existingBookIndex].price = price;
books[existingBookIndex].image = image;
books[existingBookIndex].quantity = quantity;
} else {
books.push({ title, price, image, quantity });
}
localStorage.setItem('books', JSON.stringify(books));
renderBookTable();
document.getElementById('bookForm').reset();
});
// Edit book
document.querySelector('#bookTable tbody').addEventListener('click', function (e) {
if (e.target.classList.contains('editBtn')) {
const index = e.target.getAttribute('data-index');
const book = books[index];
document.getElementById('bookTitle').value = book.title;
document.getElementById('bookPrice').value = book.price;
document.getElementById('bookImage').value = book.image;
document.getElementById('bookQuantity').value = book.quantity;
}
});
// Delete book
document.querySelector('#bookTable tbody').addEventListener('click', function (e) {
if (e.target.classList.contains('deleteBtn')) {
const index = e.target.getAttribute('data-index');
books.splice(index, 1);
localStorage.setItem('books', JSON.stringify(books));
renderBookTable();
}
});
// Adjust book quantity
document.querySelector('#bookTable tbody').addEventListener('click', function (e) {
const index = e.target.getAttribute('data-index');
if (e.target.classList.contains('increaseBtn')) {
books[index].quantity += 1;
} else if (e.target.classList.contains('decreaseBtn')) {
if (books[index].quantity > 0) {
books[index].quantity -= 1;
}
}
localStorage.setItem('books', JSON.stringify(books));
renderBookTable();
});
</script>
</body>
</html>