View Javadoc
1   package fr.paris.lutece.plugins.atelieraba.web;
2   
3   import java.util.List;
4   import java.util.Map;
5   
6   import javax.servlet.http.HttpServletRequest;
7   
8   import fr.paris.lutece.plugins.atelieraba.business.Cours;
9   import fr.paris.lutece.plugins.atelieraba.business.CoursCounter;
10  import fr.paris.lutece.plugins.atelieraba.business.CoursHome;
11  import fr.paris.lutece.portal.service.util.AppPropertiesService;
12  import fr.paris.lutece.portal.util.mvc.admin.MVCAdminJspBean;
13  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
14  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
15  import fr.paris.lutece.portal.web.util.LocalizedPaginator;
16  import fr.paris.lutece.util.html.Paginator;
17  import fr.paris.lutece.util.url.UrlItem;
18  
19  /**
20   * This class provides the user interface to manage Cours features ( manage )
21   */
22  @Controller( controllerJsp = "ConsultationCours.jsp", controllerPath = "jsp/admin/plugins/atelieraba/", right = "ATELIERABA_COURS_MANAGEMENT" )
23  public class ConsultationCoursJspBean extends MVCAdminJspBean
24  {
25  
26      /**
27       *
28       */
29      private static final long     serialVersionUID                       = -8531478776523064005L;
30      // Views
31      private static final String   VIEW_MANAGE_COURS                      = "consultationCours";
32      // Templates
33      private static final String   TEMPLATE_CONSULTATION_COURS            = "/admin/plugins/atelieraba/consultation_cours.html";
34  
35      private static final String   JSP_CONSULTATION_COURS                 = "jsp/admin/plugins/atelieraba/ConsultationCours.jsp";
36  
37      // Properties for page titles
38      private static final String   PROPERTY_PAGE_TITLE_MANAGE_COURS       = "atelieraba.consultation_cours.pageTitle";
39      private static final String   PROPERTY_DEFAULT_LIST_INSCRIT_PER_PAGE = "dacicmusiquedanse.listInscrits.itemsPerPage";
40  
41      protected static final String MARK_PAGINATOR                         = "paginator";
42      protected static final String MARK_NB_ITEMS_PER_PAGE                 = "nb_items_per_page";
43  
44      protected static final String PARAMETER_PAGE_INDEX                   = "page_index";
45  
46      protected int                 _nItemsPerPage;
47      protected int                 _nDefaultItemsPerPage;
48      protected String              _strCurrentPageIndex;
49  
50      /**
51       * Build the Manage View
52       *
53       * @param request
54       *            The HTTP request
55       * @return The page
56       */
57      @View( value = VIEW_MANAGE_COURS, defaultView = true )
58      public String getManageCours( HttpServletRequest request )
59      {
60  
61          Map<String, Object> model = getModel( );
62  
63          UrlItem url = new UrlItem( JSP_CONSULTATION_COURS );
64          String strUrl = url.getUrl( );
65  
66          List<Cours> coursList = CoursHome.getCourssList( );
67          Map<Integer, CoursCounter> coursCounterMap = CoursHome.getCoursCounter( );
68  
69          for ( Cours c : coursList )
70          {
71              c.setCoursCounter( coursCounterMap.get( c.getId( ) ) );
72          }
73  
74          model.put( "cours_list", coursList );
75  
76          // PAGINATOR
77          _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_INSCRIT_PER_PAGE, 50 );
78          _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
79          _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
80  
81          @SuppressWarnings( { "rawtypes", "unchecked" } )
82          LocalizedPaginator paginator = new LocalizedPaginator( coursList, _nItemsPerPage, strUrl, PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale( ) );
83  
84          model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
85          model.put( MARK_PAGINATOR, paginator );
86  
87          return getPage( PROPERTY_PAGE_TITLE_MANAGE_COURS, TEMPLATE_CONSULTATION_COURS, model );
88      }
89  
90  }