Skip to content

Commit c958d86

Browse files
committed
little functionality
1 parent d35b348 commit c958d86

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/main/resources/views/books/books.html

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
table {
1111
width: 100%;
1212
border-collapse: collapse;
13+
margin-bottom: 20px;
1314
}
1415
tr {
1516
border: solid;
@@ -18,13 +19,16 @@
1819
h1 {
1920
text-align: center;
2021
}
22+
#rightSide {
23+
display: none;
24+
}
2125
</style>
2226
</head>
2327
<body>
2428

2529
<h1>My Library &ndash; List of books</h1>
2630

27-
<table>
31+
<table id="booksTable">
2832
<thead>
2933
<tr>
3034
<th> ID</th>
@@ -35,7 +39,7 @@ <h1>My Library &ndash; List of books</h1>
3539
</tr>
3640
</thead>
3741
<tbody>
38-
<tr th:each="book : *{books}">
42+
<tr th:each="book : *{books}" th:id=${book.id} th:onclick="showDetail([[${book.id}]], [[${book.title}]], [[${book.pages}]], [[${book.year}]], [[${book.author.name}]]);">
3943
<td th:text="*{book.id}"></td>
4044
<td th:text="*{book.title}"></td>
4145
<td th:text="*{book.pages}"></td>
@@ -44,5 +48,44 @@ <h1>My Library &ndash; List of books</h1>
4448
</tr>
4549
</tbody>
4650
</table>
51+
52+
<div id="rightSide" >
53+
54+
<h2 id="bookTitle">Title</h2>
55+
<h3 id="bookAuthor">Author</h3>
56+
<p id="bookDescription">Description</p>
57+
</div>
58+
59+
<script th:inline="javascript">
60+
61+
var isResized = false;
62+
var lastId;
63+
function showDetail(id, title, page, year, author) {
64+
65+
if(isResized && lastId === id){
66+
document.getElementById('booksTable').style.width = "100%";
67+
document.getElementById('rightSide').style.display = "none";
68+
} else {
69+
document.getElementById('booksTable').style.width = "50%";
70+
document.getElementById('booksTable').style.float = "left";
71+
72+
document.getElementById('rightSide').style.float = "left";
73+
document.getElementById('rightSide').style.width = "40%";
74+
document.getElementById('rightSide').style.display = "block";
75+
document.getElementById('rightSide').style.margin= "1% 5% 1% 5%";
76+
77+
document.getElementById('bookTitle').innerHTML = title;
78+
document.getElementById('bookAuthor').innerHTML = author;
79+
document.getElementById('bookDescription').innerHTML = 'Year: ' + year + ', pages: ' + page;
80+
}
81+
82+
83+
84+
isResized = !isResized;
85+
lastId = id;
86+
}
87+
88+
89+
</script>
4790
</body>
4891
</html>

0 commit comments

Comments
 (0)