View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.web.globalmanagement;
35  
36  import fr.paris.lutece.portal.service.admin.AdminUserService;
37  import fr.paris.lutece.portal.service.globalmanagement.RichTextEditorService;
38  import fr.paris.lutece.portal.service.i18n.I18nService;
39  import fr.paris.lutece.portal.service.template.AppTemplateService;
40  import fr.paris.lutece.portal.service.util.AppPathService;
41  import fr.paris.lutece.util.html.HtmlTemplate;
42  
43  import java.util.HashMap;
44  import java.util.Map;
45  
46  import javax.servlet.http.HttpServletRequest;
47  
48  
49  /**
50   * The Class EditorChoiceLutecePanelJspBean.
51   */
52  public class EditorChoiceLutecePanelJspBean extends AbstractGMLutecePanel
53  {
54      /**
55       * Generated servial UID
56       */
57      private static final long serialVersionUID = -3558930087612105420L;
58      private static final String LABEL_TITLE_EDITOR_CHOICE = "portal.globalmanagement.editorChoice.labelEditorChoice";
59      private static final String PARAM_EDITOR_BACK_OFFICE = "editor_back_office";
60      private static final String PARAM_EDITOR_FRONT_OFFICE = "editor_front_office";
61      private static final String MARK_LIST_EDITORS_BACK_OFFICE = "listEditorsBackOffice";
62      private static final String MARK_LIST_EDITORS_FRONT_OFFICE = "listEditorsFrontOffice";
63      private static final String MARK_CURRENT_EDITOR_BACK_OFFICE = "current_editor_back_office";
64      private static final String MARK_CURRENT_EDITOR_FRONT_OFFICE = "current_editor_front_office";
65      private static final String TEMPLATE_EDITOR_CHOICE_PANEL = "admin/globalmanagement/panel/editor_choice_panel.html";
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      public String getPanelContent(  )
72      {
73          Map<String, Object> model = new HashMap<String, Object>(  );
74          model.put( MARK_LIST_EDITORS_BACK_OFFICE,
75              RichTextEditorService.getListEditorsForBackOffice( AdminUserService.getLocale( getRequest(  ) ) ) );
76          model.put( MARK_CURRENT_EDITOR_BACK_OFFICE, RichTextEditorService.getBackOfficeDefaultEditor(  ) );
77  
78          model.put( MARK_LIST_EDITORS_FRONT_OFFICE,
79              RichTextEditorService.getListEditorsForFrontOffice( AdminUserService.getLocale( getRequest(  ) ) ) );
80          model.put( MARK_CURRENT_EDITOR_FRONT_OFFICE, RichTextEditorService.getFrontOfficeDefaultEditor(  ) );
81  
82          HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_EDITOR_CHOICE_PANEL, getLocale(  ), model );
83  
84          return template.getHtml(  );
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      public String getPanelKey(  )
92      {
93          return LABEL_TITLE_EDITOR_CHOICE;
94      }
95  
96      /**
97       * Returns the panel's order. This panel is a first panel.
98       * @return 1
99       */
100     @Override
101     public int getPanelOrder(  )
102     {
103         return 1;
104     }
105 
106     /**
107      * {@inheritDoc}
108      */
109     @Override
110     public String getPanelTitle(  )
111     {
112         return I18nService.getLocalizedString( LABEL_TITLE_EDITOR_CHOICE, AdminUserService.getLocale( getRequest(  ) ) );
113     }
114 
115     /**
116      * Do update back office editor.
117      *
118      * @param request the request
119      * @return the string
120      */
121     public String doUpdateBackOfficeEditor( HttpServletRequest request )
122     {
123         String strEditorName = request.getParameter( PARAM_EDITOR_BACK_OFFICE );
124         RichTextEditorService.updateBackOfficeDefaultEditor( strEditorName );
125 
126         return AppPathService.getBaseUrl( request ) + GlobalManagementJspBean.JSP_URL_GLOBAL_MANAGEMENT;
127     }
128 
129     /**
130      * Do update front office editor.
131      *
132      * @param request the request
133      * @return the string
134      */
135     public String doUpdateFrontOfficeEditor( HttpServletRequest request )
136     {
137         String strEditorName = request.getParameter( PARAM_EDITOR_FRONT_OFFICE );
138         RichTextEditorService.updateFrontOfficeDefaultEditor( strEditorName );
139 
140         return AppPathService.getBaseUrl( request ) + GlobalManagementJspBean.JSP_URL_GLOBAL_MANAGEMENT;
141     }
142 }