001package votorola.s.wic.count; // Copyright 2008-2010, 2012, Michael Allan.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
002
003import java.net.*;
004import java.util.*;
005import org.apache.wicket.model.*;
006import org.apache.wicket.markup.html.basic.*;
007import org.apache.wicket.markup.html.link.*;
008import org.apache.wicket.request.mapper.parameter.PageParameters;
009import votorola.a.*;
010import votorola.a.count.*;
011import votorola.a.web.wic.*;
012import votorola.g.*;
013import votorola.g.lang.*;
014import votorola.g.locale.*;
015import votorola.g.net.*;
016import votorola.g.web.wic.*;
017import votorola.g.util.*;
018
019import static votorola.a.voter.IDPair.NOBODY;
020
021
022/** The count engine overview page.  Query parameters for this page are:
023  *
024  * <table class='definition' style='margin-left:1em'>
025  *     <tr>
026  *         <th class='key'>Key</th>
027  *         <th>Value</th>
028  *         <th>Default</th>
029  *         </tr>
030  *     <tr><td class='key'>a</td>
031  *
032  *         <td>The area name (AREA) in a multi-area pollwiki.  This sets wiki file
033  *         File:AREALogo as the wgLogo image (top left), and wiki page AREA as its link
034  *         target.  This is only needed for use with a multi-area pollwiki.</td>
035  *
036  *         <td>Null, setting the {@linkplain PollService#wgLogoImageLocation() image} and
037  *         {@linkplain PollService#wgLogoLinkTarget() link} from the most recently requested
038  *         poll.</td>
039  *
040  *         </tr>
041  *     </table>
042  *
043  *     @see <a href='../../../../../a/web/wic/WP_CountEngine.html' target='_top'>WP_CountEngine.html</a>
044  */
045  @ThreadRestricted("wicket") @org.apache.wicket.devutils.stateless.StatelessComponent
046public final class WP_CountEngine extends VPageHTML implements TabbedPage
047{
048
049
050    /** Constructs a WP_CountEngine.
051      */
052    public WP_CountEngine( final PageParameters pP ) // bookmarkable page iff constructor public & (default|PageParameter)
053      throws java.io.IOException, javax.script.ScriptException, java.sql.SQLException
054    {
055        final VRequestCycle cycle = VRequestCycle.get();
056        final VoteServer.Run vsRun = VOWicket.get().vsRun();
057        final VoteServer vS = vsRun.voteServer();
058
059        final String pollName;
060        final String wgLogoLinkTarget;
061        {
062            final String imageLocation;
063            {
064                String name = VSession.get().scopePoll().getLastName();
065                final String a = pP.get( "a" ).toString();
066                if( a == null )
067                {
068                    if( name == null ) name = Poll.TEST_POLL_NAME;
069                    final PollService poll = vsRun.scopePoll().ensurePoll( name );
070                    imageLocation = poll.wgLogoImageLocation();
071                    wgLogoLinkTarget = poll.wgLogoLinkTarget();
072                }
073                else
074                {
075                    if( name != null && !name.startsWith( a )) // change of area
076                    {
077                        name = null;
078                        VSession.get().scopePoll().setLastName( name );
079                    }
080                    final String aEnc = MediaWiki.demiEncodedPageName( a, vS.pollwiki().maybeUgly() );
081                    imageLocation = vS.pollwiki().appendPageSpecifier( "Special:FilePath/" + aEnc
082                      + "Logo.png" ).toString();
083                    wgLogoLinkTarget = vS.pollwiki().appendPageSpecifier( aEnc ).toString();
084                }
085                pollName = name;
086            }
087            add( new WC_WGLogo( "wgLogo", imageLocation, wgLogoLinkTarget, cycle ));
088        }
089
090        add( new WC_NavigationHead( "navHead", WP_CountEngine.this, cycle ));
091        add( new WC_NavPile( "navPile", navTab(cycle), cycle ));
092
093        final BundleFormatter bunW = cycle.bunW();
094
095      // Title
096      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
097        final String shortTitle = bunW.l( "s.wic.count.WP_CountEngine.tab.shortTitle" );
098        add( new Label( "title", shortTitle + " " + vS.serverName() + "/" + vS.name() ));
099        add( new Label( "h", shortTitle ));
100
101      // Links to resources
102      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103        {
104            final String loc = vS.pollwiki().uri().toASCIIString();
105            final ExternalLink tr = new ExternalLink( "pollwiki", loc ); // JavaScript link
106            tr.add( new Label( "th", bunW.l( "s.wic.count.WP_CountEngine.pollwiki" )));
107            tr.add( new ExternalLink( "td", loc, URIX.httpStripped( loc ))); // ordinary link nested in JavaScript link
108            add( tr );
109        }
110        add( new Label( "thVoteServer", shortTitle ));
111        add( new Label( "tdVoteServer", URIX.httpStripped(
112          cycle.uriFor(WP_CountEngine.class).toString() )));
113    }
114
115
116
117   // ````````````````````````````````````````````````````````````````````````````````````
118   // init for early use
119
120
121    /** The left-hand navigation tab, fetching the overview page
122      * (an instance of WP_CountEngine).
123      */
124    public static final NavTab NAV_TAB = new NavTab()
125    {
126        private final Bookmark bookmark = new Bookmark( WP_CountEngine.class );
127        public @Override Bookmark bookmark() { return bookmark; }
128        public String shortTitle( VRequestCycle cycle )
129        {
130            return cycle.bunW().l( "s.wic.count.WP_CountEngine.tab.shortTitle" );
131        }
132    };
133
134
135
136   // ------------------------------------------------------------------------------------
137
138
139    /** The bar for navigating among the count engine pages.
140      */
141    public static NavBar navBar() { return navBar; }
142
143
144        private static final NavBar navBar = new NavBar()
145        {
146
147            public SuperTab superTab() { return superTab; } // "Polls"
148
149                private final SuperTab superTab = new SuperTab( this )
150                {
151                    public String shortTitle( VRequestCycle cycle )
152                    {
153                        return cycle.bunW().l( "s.wic.count.WP_CountEngine.superTab.shortTitle" );
154                    }
155                };
156
157
158            public List<NavTab> tabList() { return tabList; }
159
160                private final ArrayListU<NavTab> tabList = new ArrayListU<NavTab>( new NavTab[]
161                {
162                 // NAV_TAB.setNavBar( this ),
163                 //// this page is largely empty at present, so leave it out of the nav bar
164                    WP_Poll.NAV_TAB.setNavBar( this ),
165                    WP_Votespace.NAV_TAB.setNavBar( this ),
166                    WP_Rank.NAV_TAB.setNavBar( this ),
167                });
168        };
169
170
171
172   // - T a b b e d - P a g e ------------------------------------------------------------
173
174
175    /** @see #NAV_TAB
176      */
177    public NavTab navTab( VRequestCycle cycle ) { return NAV_TAB; }
178
179
180
181}