View Javadoc
1   /**
2    * This file Copyright (c) 2003-2014 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.module.admininterface.lists;
35  
36  import info.magnolia.cms.gui.control.ContextMenu;
37  import info.magnolia.cms.gui.control.ContextMenuItem;
38  import info.magnolia.cms.gui.control.FunctionBar;
39  import info.magnolia.cms.gui.control.FunctionBarItem;
40  import info.magnolia.cms.gui.controlx.list.ListColumn;
41  import info.magnolia.cms.gui.controlx.list.ListControl;
42  import info.magnolia.cms.gui.controlx.list.ListModel;
43  import info.magnolia.cms.gui.controlx.search.RepositorySearchListModel;
44  import info.magnolia.cms.gui.controlx.search.SearchConfig;
45  import info.magnolia.cms.gui.controlx.search.SimpleSearchUtil;
46  import info.magnolia.cms.gui.query.SearchQuery;
47  import info.magnolia.cms.i18n.Messages;
48  import info.magnolia.cms.i18n.MessagesManager;
49  import info.magnolia.context.MgnlContext;
50  import info.magnolia.repository.RepositoryConstants;
51  
52  import javax.servlet.http.HttpServletRequest;
53  import javax.servlet.http.HttpServletResponse;
54  
55  public class WebsiteSearchList extends AbstractSimpleSearchList {
56  
57      protected Messages msgs = MessagesManager.getMessages();
58  
59      public WebsiteSearchList(String name, HttpServletRequest request, HttpServletResponse response) {
60          super(name, request, response);
61      }
62  
63      @Override
64      public ListModel getModel() {
65          return new RepositorySearchListModel(RepositoryConstants.WEBSITE);
66      }
67  
68      @Override
69      public void configureList(ListControl list) {
70          list.setRenderer(new AdminListControlRenderer() {
71  
72              @Override
73              public String onDblClick(ListControl list, Integer index) {
74                  return "mgnl.admininterface.WebsiteSearchList.show();";
75              }
76  
77              @Override
78              public String onSelect(ListControl list, Integer index) {
79                  String js = "mgnl.admininterface.WebsiteSearchList.selected = '" + list.getIteratorValue("path") + "';";
80                  js += super.onSelect(list, index);
81                  return js;
82              }
83          });
84  
85          // show the icon by the name
86          list.addColumn(new ListColumn() {
87  
88              {
89                  setName("name");
90                  setColumnName("name");
91                  setLabel("Name");
92                  setWidth("200");
93              }
94  
95              @Override
96              public String render() {
97                  return "<span style=\"vertical-align: middle\"><img  src=\""
98                      + MgnlContext.getContextPath()
99                      + "/.resources/icons/16/document_plain_earth.gif\"/></span>"
100                     + this.getValue();
101             }
102 
103         });
104 
105         list.addColumn(new ListColumn("mgnl:authorid", "User", "200", true));
106         list.addColumn(new ListColumn("title", "Title", "200", true));
107 
108         list.addSortableField("name");
109         list.addSortableField("title");
110 
111         list.addGroupableField("mgnl:authorid");
112     }
113 
114     @Override
115     protected void configureContextMenu(ContextMenu menu) {
116         ContextMenuItem open = new ContextMenuItem("open");
117         open.setLabel(msgs.get("tree.web.menu.open")); //$NON-NLS-1$
118         open.setIcon(request.getContextPath() + "/.resources/icons/16/document_plain_earth.gif"); //$NON-NLS-1$
119         open.setOnclick("mgnl.admininterface.WebsiteSearchList.show();"); //$NON-NLS-1$
120         open.addJavascriptCondition("{test: function(){return mgnl.admininterface.WebsiteSearchList.selected != null}}");
121 
122         ContextMenuItem navigate = new ContextMenuItem("navigate");
123         navigate.setLabel(msgs.get("tree.menu.navigate")); //$NON-NLS-1$
124         navigate.setIcon(request.getContextPath() + "/.resources/icons/16/compass.gif"); //$NON-NLS-1$
125         navigate.setOnclick("mgnl.admininterface.WebsiteSearchList.navigate();"); //$NON-NLS-1$
126         navigate.addJavascriptCondition("{test: function(){return mgnl.admininterface.WebsiteSearchList.selected != null}}");
127 
128         menu.addMenuItem(open);
129         menu.addMenuItem(null);
130         menu.addMenuItem(navigate);
131     }
132 
133     @Override
134     protected void configureFunctionBar(FunctionBar bar) {
135         super.configureFunctionBar(bar);
136         bar.setOnSearchFunction("mgnl.admininterface.WebsiteSearchList.search");
137 
138         ContextMenu menu = this.getContextMenu();
139 
140         bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("open")));
141         bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("navigate")));
142 
143     }
144 
145     /**
146      * Here we create a all over query
147      */
148     @Override
149     public SearchQuery getQuery() {
150         return SimpleSearchUtil.getSimpleSearchQuery(this.getSearchStr());
151 
152     }
153 
154     /**
155      * Not used in this context
156      */
157     @Override
158     public SearchConfig getSearchConfig() {
159         return null;
160     }
161 
162 }