doc
[nikiroo-utils.git] / templates / WebLibraryServerTemplates.java
1 package be.nikiroo.fanfix.library.web.templates;
2
3 import java.util.List;
4
5 import be.nikiroo.fanfix.Instance;
6 import be.nikiroo.fanfix.bundles.UiConfig;
7 import be.nikiroo.fanfix.library.Template;
8 import be.nikiroo.utils.Version;
9
10 public class WebLibraryServerTemplates {
11 static private WebLibraryServerTemplates instance = new WebLibraryServerTemplates();
12
13 static public WebLibraryServerTemplates getInstance() {
14 return instance;
15 }
16
17 public Template bookline(String luid, String href, String title,
18 String author, boolean cached) {
19
20 String cachedClass = "cached";
21 String cachedValue = "◉";
22 if (!cached) {
23 cachedClass = "uncached";
24 cachedValue = "○";
25 }
26
27 return new Template(getClass(), "bookline.html") //
28 .set("href", href) //
29 .set("cachedClass", cachedClass) //
30 .set("cached", cachedValue) //
31 .set("luid", luid) //
32 .set("title", title) //
33 .set("author", author) //
34 ;
35 }
36
37 public Template browser(String selectedValue, String filter,
38 List<Template> selects) {
39 return new Template(getClass(), "browser.html") //
40 .set("sourcesSelected",
41 "sources".equals(selectedValue) ? "selected='selected'"
42 : "") //
43 .set("authorsSelected",
44 "authors".equals(selectedValue) ? "selected='selected'"
45 : "") //
46 .set("tagsSelected",
47 "tags".equals(selectedValue) ? "selected='selected'"
48 : "") //
49 .set("filter", filter) //
50 .set("selects", selects) //
51 ;
52 }
53
54 public Template browserOption(String name, String value,
55 String selectedValue) {
56 return new Template(getClass(), "browser.option.html") //
57 .set("value", value) //
58 .set("selected",
59 value.equals(selectedValue) ? "selected='selected'"
60 : "") //
61 .set("name", name) //
62 ;
63 }
64
65 public Template browserSelect(String name, String value,
66 List<Template> options) {
67 return new Template(getClass(), "browser.select.html") //
68 .set("name", name) //
69 .set("value", value) //
70 .set("options", options) //
71 ;
72 }
73
74 public Template index(boolean banner, List<Template> content) {
75 String favicon = "favicon.ico";
76 String icon = Instance.getInstance().getUiConfig()
77 .getString(UiConfig.PROGRAM_ICON);
78 if (icon != null) {
79 favicon = "icon_" + icon.replace("-", "_") + ".png";
80 }
81
82 Template index = new Template(getClass(), "index.html") //
83 .set("title", "Fanfix") //
84 .set("favicon", favicon) //
85 .set("content", content) //
86 ;
87
88 if (banner) {
89 index.set("banner", new Template(getClass(), "index.banner.html") //
90 .set("favicon", favicon) //
91 .set("version", Version.getCurrentVersion().toString()) //
92 );
93 } else {
94 index.set("banner", "");
95 }
96
97 return index;
98 }
99
100 public Template viewer(Template browser, List<Template> booklines) {
101 // TODO
102 return null;
103 }
104
105 public Template viewerImage(String src, String href, String zoomStyle) {
106 return new Template(getClass(), "viewer.image.html") //
107 .set("src", src) //
108 .set("href", href) //
109 .set("zoomStyle", zoomStyle) //
110 ;
111 }
112
113 public Template viewerText(List<Template> desc, List<Template> content) {
114 return new Template(getClass(), "viewer.text.html") //
115 .set("desc", desc) //
116 .set("content", content) //
117 ;
118 }
119
120 public Template viewerLink(String name, String link, String className) {
121 return new Template(getClass(), "viewer.link.html") //
122 .set("link", link) //
123 .set("class", className) //
124 .set("name", name) //
125 ;
126 }
127
128 public Template viewerNavbar(int current, List<Template> links,
129 String hrefFirst, String hrefPrevious, String hrefNext,
130 String hrefLast, boolean disabledFirst, boolean disabledPrevious,
131 boolean disabledNext, boolean disabledLast) {
132 return new Template(getClass(), "viewer.navbar.html") //
133 .set("disabledFirst",
134 disabledFirst ? "disabled='disabled'" : "") //
135 .set("disabledPrevious",
136 disabledPrevious ? "disabled='disabled'" : "") //
137 .set("disabledNext", disabledNext ? "disabled='disabled'" : "") //
138 .set("disabledLast", disabledLast ? "disabled='disabled'" : "") //
139 .set("hrefFirst", hrefFirst) //
140 .set("hrefPrevious", hrefPrevious) //
141 .set("hrefNext", hrefNext) //
142 .set("hrefLast", hrefLast) //
143 .set("current", Integer.toString(current)) //
144 .set("links", links) //
145 ;
146 }
147
148 // numberOfButtons = 4 or 1 or the moment
149 public Template viewerOptionbar(int numberOfButtons,
150 List<Template> buttons) {
151 return new Template(getClass(), "viewer.optionbar.html") //
152 .set("classSize", "s" + numberOfButtons) //
153 .set("buttons", buttons) //
154 ;
155 }
156
157 public Template viewerOptionbarButton(String value, String href,
158 String className, boolean disabled) {
159 return new Template(getClass(), "viewer.optionbar.button.html") //
160 .set("disabled", disabled ? "disabled='disabled'" : "") //
161 .set("class", className) //
162 .set("href", href) //
163 .set("value", value) //
164 ;
165 }
166 }