update from master
[nikiroo-utils.git] / library / web / templates / WebLibraryServerTemplates.java
CommitLineData
83001824
NR
1package be.nikiroo.fanfix.library.web.templates;
2
8639c60d
NR
3import java.util.List;
4
5import be.nikiroo.fanfix.Instance;
6import be.nikiroo.fanfix.bundles.UiConfig;
7import be.nikiroo.fanfix.library.Template;
8import be.nikiroo.utils.Version;
9
977f60a2
NR
10/**
11 * Utility class to retrieve and fill HTML templates for Fanfix web server.
12 *
13 * @author niki
14 */
83001824 15public class WebLibraryServerTemplates {
8639c60d
NR
16 static private WebLibraryServerTemplates instance = new WebLibraryServerTemplates();
17
977f60a2
NR
18 /**
19 * Get the (unique) instance of this {@link WebLibraryServerTemplates}.
20 *
21 * @return the (unique) instance
22 */
8639c60d
NR
23 static public WebLibraryServerTemplates getInstance() {
24 return instance;
25 }
26
27 public Template bookline(String luid, String href, String title,
28 String author, boolean cached) {
29
30 String cachedClass = "cached";
31 String cachedValue = "◉";
32 if (!cached) {
33 cachedClass = "uncached";
34 cachedValue = "○";
35 }
36
37 return new Template(getClass(), "bookline.html") //
38 .set("href", href) //
39 .set("cachedClass", cachedClass) //
40 .set("cached", cachedValue) //
41 .set("luid", luid) //
42 .set("title", title) //
43 .set("author", author) //
44 ;
45 }
46
074a8325
NR
47 public Template index(boolean banner, List<Template> content) {
48 String favicon = "favicon.ico";
49 String icon = Instance.getInstance().getUiConfig()
50 .getString(UiConfig.PROGRAM_ICON);
51 if (icon != null) {
52 favicon = "icon_" + icon.replace("-", "_") + ".png";
53 }
54
55 Template index = new Template(getClass(), "index.html") //
56 .set("title", "Fanfix") //
57 .set("favicon", favicon) //
58 .set("content", content) //
59 ;
60
61 if (banner) {
62 index.set("banner", new Template(getClass(), "index.banner.html") //
63 .set("favicon", favicon) //
64 .set("version", Version.getCurrentVersion().toString()) //
65 );
66 } else {
67 index.set("banner", "");
68 }
69
70 return index;
71 }
72
73 public Template login(String url) {
74 return new Template(getClass(), "login.html") //
75 .set("url", url) //
76 ;
77 }
78
79 public Template message(String message, boolean error) {
80 return new Template(getClass(), "message.html") //
81 .set("class", error ? "message error" : "message") //
82 .set("message", message) //
83 ;
84 }
85
8639c60d
NR
86 public Template browser(String selectedValue, String filter,
87 List<Template> selects) {
88 return new Template(getClass(), "browser.html") //
89 .set("sourcesSelected",
90 "sources".equals(selectedValue) ? "selected='selected'"
91 : "") //
92 .set("authorsSelected",
93 "authors".equals(selectedValue) ? "selected='selected'"
94 : "") //
95 .set("tagsSelected",
96 "tags".equals(selectedValue) ? "selected='selected'"
97 : "") //
98 .set("filter", filter) //
99 .set("selects", selects) //
100 ;
101 }
102
103 public Template browserOption(String name, String value,
104 String selectedValue) {
105 return new Template(getClass(), "browser.option.html") //
106 .set("value", value) //
107 .set("selected",
108 value.equals(selectedValue) ? "selected='selected'"
109 : "") //
110 .set("name", name) //
111 ;
112 }
113
114 public Template browserSelect(String name, String value,
115 List<Template> options) {
116 return new Template(getClass(), "browser.select.html") //
117 .set("name", name) //
118 .set("value", value) //
119 .set("options", options) //
120 ;
121 }
122
977f60a2
NR
123 public Template viewerDesc(String title, String href, String cover,
124 List<Template> desclines) {
125 return new Template(getClass(), "viewer.desc.html") //
126 .set("title", title) //
127 .set("href", href) //
128 .set("cover", cover) //
129 .set("details", desclines) //
130 ;
131 }
132
133 public Template viewerDescline(String key, String value) {
134 return new Template(getClass(), "viewer.descline.html") //
135 .set("key", key) //
136 .set("value", value) //
137 ;
8639c60d
NR
138 }
139
140 public Template viewerImage(String src, String href, String zoomStyle) {
141 return new Template(getClass(), "viewer.image.html") //
142 .set("src", src) //
143 .set("href", href) //
144 .set("zoomStyle", zoomStyle) //
145 ;
146 }
147
977f60a2 148 public Template viewerText(Template desc, String content) {
8639c60d
NR
149 return new Template(getClass(), "viewer.text.html") //
150 .set("desc", desc) //
151 .set("content", content) //
152 ;
153 }
154
977f60a2 155 public Template viewerLink(String name, String link, boolean selected) {
8639c60d
NR
156 return new Template(getClass(), "viewer.link.html") //
157 .set("link", link) //
977f60a2 158 .set("class", selected ? "selected" : "") //
8639c60d
NR
159 .set("name", name) //
160 ;
161 }
162
163 public Template viewerNavbar(int current, List<Template> links,
164 String hrefFirst, String hrefPrevious, String hrefNext,
165 String hrefLast, boolean disabledFirst, boolean disabledPrevious,
166 boolean disabledNext, boolean disabledLast) {
167 return new Template(getClass(), "viewer.navbar.html") //
168 .set("disabledFirst",
169 disabledFirst ? "disabled='disabled'" : "") //
170 .set("disabledPrevious",
171 disabledPrevious ? "disabled='disabled'" : "") //
172 .set("disabledNext", disabledNext ? "disabled='disabled'" : "") //
173 .set("disabledLast", disabledLast ? "disabled='disabled'" : "") //
174 .set("hrefFirst", hrefFirst) //
175 .set("hrefPrevious", hrefPrevious) //
176 .set("hrefNext", hrefNext) //
177 .set("hrefLast", hrefLast) //
178 .set("current", Integer.toString(current)) //
179 .set("links", links) //
180 ;
181 }
182
977f60a2 183 // supported numberOfButtons = 4 or 1 or the moment
8639c60d
NR
184 public Template viewerOptionbar(int numberOfButtons,
185 List<Template> buttons) {
186 return new Template(getClass(), "viewer.optionbar.html") //
187 .set("classSize", "s" + numberOfButtons) //
188 .set("buttons", buttons) //
189 ;
190 }
191
192 public Template viewerOptionbarButton(String value, String href,
193 String className, boolean disabled) {
194 return new Template(getClass(), "viewer.optionbar.button.html") //
195 .set("disabled", disabled ? "disabled='disabled'" : "") //
196 .set("class", className) //
197 .set("href", href) //
198 .set("value", value) //
199 ;
200 }
83001824 201}