Merge branch 'master' into subtree
[fanfix.git] / src / be / nikiroo / fanfix / library / web / 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 index(boolean banner, List<Template> content) {
38 String favicon = "favicon.ico";
39 String icon = Instance.getInstance().getUiConfig()
40 .getString(UiConfig.PROGRAM_ICON);
41 if (icon != null) {
42 favicon = "icon_" + icon.replace("-", "_") + ".png";
43 }
44
45 Template index = new Template(getClass(), "index.html") //
46 .set("title", "Fanfix") //
47 .set("favicon", favicon) //
48 .set("content", content) //
49 ;
50
51 if (banner) {
52 index.set("banner", new Template(getClass(), "index.banner.html") //
53 .set("favicon", favicon) //
54 .set("version", Version.getCurrentVersion().toString()) //
55 );
56 } else {
57 index.set("banner", "");
58 }
59
60 return index;
61 }
62
63 public Template login(String url) {
64 return new Template(getClass(), "login.html") //
65 .set("url", url) //
66 ;
67 }
68
69 public Template message(String message, boolean error) {
70 return new Template(getClass(), "message.html") //
71 .set("class", error ? "message error" : "message") //
72 .set("message", message) //
73 ;
74 }
75
76 public Template browser(String selectedValue, String filter,
77 List<Template> selects) {
78 return new Template(getClass(), "browser.html") //
79 .set("sourcesSelected",
80 "sources".equals(selectedValue) ? "selected='selected'"
81 : "") //
82 .set("authorsSelected",
83 "authors".equals(selectedValue) ? "selected='selected'"
84 : "") //
85 .set("tagsSelected",
86 "tags".equals(selectedValue) ? "selected='selected'"
87 : "") //
88 .set("filter", filter) //
89 .set("selects", selects) //
90 ;
91 }
92
93 public Template browserOption(String name, String value,
94 String selectedValue) {
95 return new Template(getClass(), "browser.option.html") //
96 .set("value", value) //
97 .set("selected",
98 value.equals(selectedValue) ? "selected='selected'"
99 : "") //
100 .set("name", name) //
101 ;
102 }
103
104 public Template browserSelect(String name, String value,
105 List<Template> options) {
106 return new Template(getClass(), "browser.select.html") //
107 .set("name", name) //
108 .set("value", value) //
109 .set("options", options) //
110 ;
111 }
112
113 public Template viewer(Template browser, List<Template> booklines) {
114 // TODO
115 return null;
116 }
117
118 public Template viewerImage(String src, String href, String zoomStyle) {
119 return new Template(getClass(), "viewer.image.html") //
120 .set("src", src) //
121 .set("href", href) //
122 .set("zoomStyle", zoomStyle) //
123 ;
124 }
125
126 public Template viewerText(List<Template> desc, List<Template> content) {
127 return new Template(getClass(), "viewer.text.html") //
128 .set("desc", desc) //
129 .set("content", content) //
130 ;
131 }
132
133 public Template viewerLink(String name, String link, String className) {
134 return new Template(getClass(), "viewer.link.html") //
135 .set("link", link) //
136 .set("class", className) //
137 .set("name", name) //
138 ;
139 }
140
141 public Template viewerNavbar(int current, List<Template> links,
142 String hrefFirst, String hrefPrevious, String hrefNext,
143 String hrefLast, boolean disabledFirst, boolean disabledPrevious,
144 boolean disabledNext, boolean disabledLast) {
145 return new Template(getClass(), "viewer.navbar.html") //
146 .set("disabledFirst",
147 disabledFirst ? "disabled='disabled'" : "") //
148 .set("disabledPrevious",
149 disabledPrevious ? "disabled='disabled'" : "") //
150 .set("disabledNext", disabledNext ? "disabled='disabled'" : "") //
151 .set("disabledLast", disabledLast ? "disabled='disabled'" : "") //
152 .set("hrefFirst", hrefFirst) //
153 .set("hrefPrevious", hrefPrevious) //
154 .set("hrefNext", hrefNext) //
155 .set("hrefLast", hrefLast) //
156 .set("current", Integer.toString(current)) //
157 .set("links", links) //
158 ;
159 }
160
161 // numberOfButtons = 4 or 1 or the moment
162 public Template viewerOptionbar(int numberOfButtons,
163 List<Template> buttons) {
164 return new Template(getClass(), "viewer.optionbar.html") //
165 .set("classSize", "s" + numberOfButtons) //
166 .set("buttons", buttons) //
167 ;
168 }
169
170 public Template viewerOptionbarButton(String value, String href,
171 String className, boolean disabled) {
172 return new Template(getClass(), "viewer.optionbar.button.html") //
173 .set("disabled", disabled ? "disabled='disabled'" : "") //
174 .set("class", className) //
175 .set("href", href) //
176 .set("value", value) //
177 ;
178 }
179 }