weblib: use templates for all html
[fanfix.git] / src / be / nikiroo / fanfix / library / web / templates / WebLibraryServerTemplates.java
index ba4deb83f290739407822fc4933802633fb5bf0e..59e7020c62fa6254ff3c20da3e0a4aa939031b22 100644 (file)
@@ -7,9 +7,19 @@ import be.nikiroo.fanfix.bundles.UiConfig;
 import be.nikiroo.fanfix.library.Template;
 import be.nikiroo.utils.Version;
 
+/**
+ * Utility class to retrieve and fill HTML templates for Fanfix web server.
+ * 
+ * @author niki
+ */
 public class WebLibraryServerTemplates {
        static private WebLibraryServerTemplates instance = new WebLibraryServerTemplates();
 
+       /**
+        * Get the (unique) instance of this {@link WebLibraryServerTemplates}.
+        * 
+        * @return the (unique) instance
+        */
        static public WebLibraryServerTemplates getInstance() {
                return instance;
        }
@@ -34,6 +44,45 @@ public class WebLibraryServerTemplates {
                ;
        }
 
+       public Template index(boolean banner, List<Template> content) {
+               String favicon = "favicon.ico";
+               String icon = Instance.getInstance().getUiConfig()
+                               .getString(UiConfig.PROGRAM_ICON);
+               if (icon != null) {
+                       favicon = "icon_" + icon.replace("-", "_") + ".png";
+               }
+
+               Template index = new Template(getClass(), "index.html") //
+                               .set("title", "Fanfix") //
+                               .set("favicon", favicon) //
+                               .set("content", content) //
+               ;
+
+               if (banner) {
+                       index.set("banner", new Template(getClass(), "index.banner.html") //
+                                       .set("favicon", favicon) //
+                                       .set("version", Version.getCurrentVersion().toString()) //
+                       );
+               } else {
+                       index.set("banner", "");
+               }
+
+               return index;
+       }
+
+       public Template login(String url) {
+               return new Template(getClass(), "login.html") //
+                               .set("url", url) //
+               ;
+       }
+
+       public Template message(String message, boolean error) {
+               return new Template(getClass(), "message.html") //
+                               .set("class", error ? "message error" : "message") //
+                               .set("message", message) //
+               ;
+       }
+
        public Template browser(String selectedValue, String filter,
                        List<Template> selects) {
                return new Template(getClass(), "browser.html") //
@@ -71,35 +120,21 @@ public class WebLibraryServerTemplates {
                ;
        }
 
-       public Template index(boolean banner, List<Template> content) {
-               String favicon = "favicon.ico";
-               String icon = Instance.getInstance().getUiConfig()
-                               .getString(UiConfig.PROGRAM_ICON);
-               if (icon != null) {
-                       favicon = "icon_" + icon.replace("-", "_") + ".png";
-               }
-
-               Template index = new Template(getClass(), "index.html") //
-                               .set("title", "Fanfix") //
-                               .set("favicon", favicon) //
-                               .set("content", content) //
+       public Template viewerDesc(String title, String href, String cover,
+                       List<Template> desclines) {
+               return new Template(getClass(), "viewer.desc.html") //
+                               .set("title", title) //
+                               .set("href", href) //
+                               .set("cover", cover) //
+                               .set("details", desclines) //
                ;
-
-               if (banner) {
-                       index.set("banner", new Template(getClass(), "index.banner.html") //
-                                       .set("favicon", favicon) //
-                                       .set("version", Version.getCurrentVersion().toString()) //
-                       );
-               } else {
-                       index.set("banner", "");
-               }
-
-               return index;
        }
 
-       public Template viewer(Template browser, List<Template> booklines) {
-               // TODO
-               return null;
+       public Template viewerDescline(String key, String value) {
+               return new Template(getClass(), "viewer.descline.html") //
+                               .set("key", key) //
+                               .set("value", value) //
+               ;
        }
 
        public Template viewerImage(String src, String href, String zoomStyle) {
@@ -110,17 +145,17 @@ public class WebLibraryServerTemplates {
                ;
        }
 
-       public Template viewerText(List<Template> desc, List<Template> content) {
+       public Template viewerText(Template desc, String content) {
                return new Template(getClass(), "viewer.text.html") //
                                .set("desc", desc) //
                                .set("content", content) //
                ;
        }
 
-       public Template viewerLink(String name, String link, String className) {
+       public Template viewerLink(String name, String link, boolean selected) {
                return new Template(getClass(), "viewer.link.html") //
                                .set("link", link) //
-                               .set("class", className) //
+                               .set("class", selected ? "selected" : "") //
                                .set("name", name) //
                ;
        }
@@ -145,7 +180,7 @@ public class WebLibraryServerTemplates {
                ;
        }
 
-       // numberOfButtons = 4 or 1 or the moment
+       // supported numberOfButtons = 4 or 1 or the moment
        public Template viewerOptionbar(int numberOfButtons,
                        List<Template> buttons) {
                return new Template(getClass(), "viewer.optionbar.html") //