001    /*
002     * Apache License
003     * Version 2.0, January 2004
004     * http://www.apache.org/licenses/
005     *
006     * Copyright 2008-2010 by chenillekit.org
007     *
008     * Licensed under the Apache License, Version 2.0 (the "License");
009     * you may not use this file except in compliance with the License.
010     * You may obtain a copy of the License at
011     *
012     * http://www.apache.org/licenses/LICENSE-2.0
013     */
014    
015    package org.chenillekit.tapestry.core.components;
016    
017    import org.apache.tapestry5.BindingConstants;
018    import org.apache.tapestry5.ClientElement;
019    import org.apache.tapestry5.ComponentResources;
020    import org.apache.tapestry5.MarkupWriter;
021    import org.apache.tapestry5.annotations.Environmental;
022    import org.apache.tapestry5.annotations.Import;
023    import org.apache.tapestry5.annotations.Parameter;
024    import org.apache.tapestry5.annotations.SupportsInformalParameters;
025    import org.apache.tapestry5.ioc.annotations.Inject;
026    import org.apache.tapestry5.services.javascript.JavaScriptSupport;
027    
028    /**
029     * a expand-/pin-able side panel.
030     *
031     * @version $Id: SidePanel.java 674 2010-07-29 12:47:25Z homburgs $
032     */
033    @SupportsInformalParameters
034    @Import(library = {"../Chenillekit.js", "../Cookie.js", "SidePanel.js"}, stylesheet = {"SidePanel.css"})
035    public class SidePanel implements ClientElement
036    {
037            /**
038             * The id used to generate a page-unique client-side identifier for the component. If a component renders multiple
039             * times, a suffix will be appended to the to id to ensure uniqueness.
040             */
041            @Parameter(value = "prop:componentResources.id", defaultPrefix = BindingConstants.LITERAL)
042            private String clientId;
043    
044            /**
045             * if the panel height should be dynamic, you can place
046             * here the id  of the html element, on wich deliver size
047             * to the panel.
048             */
049            @Parameter(required = false, defaultPrefix = BindingConstants.LITERAL)
050            private String sizeElement;
051    
052            @Environmental
053            private JavaScriptSupport javascriptSupport;
054    
055            @Inject
056            private ComponentResources resources;
057    
058            private String assignedClientId;
059    
060            void setupRender()
061            {
062                    assignedClientId = javascriptSupport.allocateClientId(clientId);
063            }
064    
065            void beginRender(MarkupWriter writer)
066            {
067                    writer.element("div", "id", getClientId(), "class", "ck_sidepanel");
068                    resources.renderInformalParameters(writer);
069                    writer.element("div", "class", "ck_sidepanel-panel");
070                    writer.element("div", "class", "ck_sidepanel-toggler");
071                    writer.end();
072                    writer.end();
073                    writer.element("div", "class", "ck_sidepanel-content", "style", "display: none;");
074                    writer.element("div", "class", "ck_sidepanel-pinner-bar");
075                    writer.element("div", "class", "ck_sidepanel-pinner");
076                    writer.end();
077                    writer.end();
078            }
079    
080            void afterRender(MarkupWriter writer)
081            {
082                    writer.end();
083                    writer.end();
084                    javascriptSupport.addScript("new Ck.SidePanel('%s','%s');", getClientId(), sizeElement);
085            }
086    
087            /**
088             * Returns a unique id for the element. This value will be unique for any given rendering of a
089             * page. This value is intended for use as the id attribute of the client-side element, and will
090             * be used with any DHTML/Ajax related JavaScript.
091             */
092            public String getClientId()
093            {
094                    return assignedClientId;
095            }
096    }