Coverage Report - org.equanda.tapestry5.components.JSPager
 
Classes in this File Line Coverage Branch Coverage Complexity
JSPager
0%
0/25
0%
0/2
0
 
 1  
 /**
 2  
  * This file is part of the equanda project.
 3  
  *
 4  
  * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 7  
  *
 8  
  * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
 9  
  * ANY KIND, either express or implied. See the License for the specific language governing rights and
 10  
  * limitations under the License.
 11  
  *
 12  
  * Alternatively, the contents of this file may be used under the terms of
 13  
  * either the GNU General Public License Version 2 or later (the "GPL"), or
 14  
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 15  
  * in which case the provisions of the GPL or the LGPL are applicable instead
 16  
  * of those above. If you wish to allow use of your version of this file only
 17  
  * under the terms of either the GPL or the LGPL, and not to allow others to
 18  
  * use your version of this file under the terms of the MPL, indicate your
 19  
  * decision by deleting the provisions above and replace them with the notice
 20  
  * and other provisions required by the GPL or the LGPL. If you do not delete
 21  
  * the provisions above, a recipient may use your version of this file under
 22  
  * the terms of any one of the MPL, the GPL or the LGPL.
 23  
  */
 24  
 
 25  
 package org.equanda.tapestry5.components;
 26  
 
 27  
 import org.apache.tapestry5.MarkupWriter;
 28  
 import org.apache.tapestry5.RenderSupport;
 29  
 import org.apache.tapestry5.annotations.*;
 30  
 import org.apache.tapestry5.ioc.annotations.Inject;
 31  
 import org.apache.tapestry5.json.JSONObject;
 32  
 import org.apache.tapestry5.services.Environment;
 33  
 
 34  
 import java.util.List;
 35  
 
 36  
 /**
 37  
  * Equanda modification of {@link org.apache.tapestry5.corelib.components.GridPager}
 38  
  * 
 39  
  * @author <a href="mailto:vladimir.tkachenko@gmail.com">Vladimir Tkachenko</a>
 40  
  */
 41  
 @IncludeStylesheet( value = { "classpath:/org/equanda/tapestry5/resources/jspager.css" } )
 42  
 @IncludeJavaScriptLibrary( value = { "classpath:/org/equanda/tapestry5/resources/jspager.js" } )
 43  0
 public class JSPager
 44  
 {
 45  
     /**
 46  
      * The source of the data displayed by the JSPagedLoop
 47  
      */
 48  
     @Parameter
 49  
     private List<Object> source;
 50  
 
 51  
     /**
 52  
      * The number of rows displayed per page.
 53  
      */
 54  
     @Parameter
 55  
     private int rowsPerPage;
 56  
 
 57  
     /**
 58  
      * Number of pages before and after the current page in the range. The pager always displays links for 2 * range + 1
 59  
      * pages, unless that's more than the total number of available pages.
 60  
      */
 61  
     @Parameter( "5" )
 62  
     private int range;
 63  
 
 64  
     // private int maxPages;
 65  
 
 66  
     @Environmental
 67  
     private RenderSupport renderSupport;
 68  
 
 69  
     @Inject
 70  
     private Environment environment;
 71  
 
 72  
     @BeginRender
 73  
     void render( MarkupWriter writer )
 74  
     {
 75  0
         JSPagedLoop pagedLoop = environment.peek( JSPagedLoop.class );
 76  
 
 77  0
         if ( pagedLoop != null )
 78  
         {
 79  
             /*int availableRows = source.size() - pagedLoop.getAddedRowCount();
 80  
 
 81  
             maxPages = ( ( availableRows - 1 ) / rowsPerPage ) + 1;
 82  
 
 83  
             if ( maxPages < 2 )
 84  
             {
 85  
                 return;
 86  
             }*/
 87  0
             String clientId = pagedLoop.getClientId().toLowerCase();
 88  
 
 89  0
             writer.element( "div", "class", "equanda_paged_loop_pager jspagedloop_pager_" + clientId );
 90  0
             writer.end();
 91  
 
 92  0
             JSONObject object = new JSONObject();
 93  0
             object.put( "range", range );
 94  
             // object.put( "maxPages", maxPages );
 95  0
             object.put( "rowsPerPage", rowsPerPage );
 96  0
             object.put( "lastIndex", 0 );
 97  0
             object.put( "currentPage", pagedLoop.getCurrentPage() );
 98  0
             object.put( "rowCount", source.size() );
 99  0
             object.put( "addedRowCount", pagedLoop.getAddedRowCount() );
 100  0
             object.put( "additionalRowCount", pagedLoop.getAdditionalRowCount() );
 101  0
             object.put( "currentPageFieldName", pagedLoop.getCurrentPageFieldName() );
 102  0
             object.put( "addedRowFieldName", pagedLoop.getAddedRowFieldName() );
 103  0
             object.put( "containerClass", "jspagedloop_pager_" + clientId );
 104  0
             object.put( "rowClass", "jspagedlooprow_" + clientId );
 105  0
             object.put( "addLinkClass", "jspagedloop_addlink_" + clientId );
 106  0
             object.put( "addBlockClass", "jspagedloop_addblock_" + clientId );
 107  0
             object.put( "name", clientId );
 108  0
             renderSupport.addScript( "JSPagerConfigs.%s = %s;", clientId, object );
 109  0
             renderSupport.addScript( "eqShowPage( %s, JSPagerConfigs.%s );", pagedLoop.getCurrentPage(), clientId );
 110  0
             renderSupport.addScript( "checkAddLinks( JSPagerConfigs.%s );", clientId );
 111  
             // logger.info( String.format( "Config Object. %s = %s ", clientId, object ) );
 112  
         }
 113  0
     }
 114  
 }