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
|
package reading.component.index
import scala.util.Random
import scalacss.Defaults._
import scalacss.ScalatagsCss._
import scalatags.JsDom.all._
import reading.component.index.style.{ BookDetail => BookStyle }
import reading.component.widget.AnimateMethod
import reading.models.{ Book, Program }
object BookDetail {
val componentId = s"books${Random.nextInt}"
def apply(book: Book, parentId: String, onClose: => Unit): Frag = {
val titleParts = if (book.parts > 1) s", ${book.parts} volumes" else ""
val grades = book.programs.map(Program.grade(_)).distinct.sorted
AnimateMethod.fadeIn(componentId)
div(
BookStyle.render,
BookStyle.detail,
id := componentId,
img(
BookStyle.cover,
src := s"cover/${book.title}.jpg",
alt := s"${book.title}, ${book.author}"
),
div(
BookStyle.presentation,
div(BookStyle.title, s"${book.title}$titleParts"),
div(BookStyle.author, book.author),
book.resume match {
case Some(resume) =>
p(BookStyle.resume, raw(resume))
case _ =>
span("")
},
dl(
BookStyle.definitions,
grades.map { grade =>
val programs = book.programs.filter(p => Program.grade(p) == grade).sorted
val pp = grade.prettyPrint
definition(pp, pp, programs.map(p => s"« ${p.prettyPrint} »"))
},
if (book.themes.nonEmpty) {
definition("thème", "thèmes", book.themes.sorted.map(_.prettyPrint))
},
if (book.genres.nonEmpty) {
definition("genre", "genres", book.genres.sorted.map(_.prettyPrint))
},
definition("niveau", "niveaux", Seq(book.level.prettyPrint))
),
button(
BookStyle.close,
onclick := (() => onClose),
"Fermer"
)
)
)
}
private def definition(key: String, pluralKey: String, values: Seq[String]): Seq[Frag] = {
val term = if (values.length > 1) pluralKey else key
Seq(
dt(BookStyle.definitionTerm, s"${term.capitalize} :"),
dd(BookStyle.definitionDescription, values.mkString(", "))
)
}
}
|