View Javadoc

1   /**
2    * This file Copyright (c) 2003-2011 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.beans.config.ContentRepository;
37  import info.magnolia.cms.gui.control.ContextMenu;
38  import info.magnolia.cms.gui.control.ContextMenuItem;
39  import info.magnolia.cms.gui.control.FunctionBar;
40  import info.magnolia.cms.gui.control.FunctionBarItem;
41  import info.magnolia.cms.gui.controlx.list.ListColumn;
42  import info.magnolia.cms.gui.controlx.list.ListControl;
43  import info.magnolia.cms.gui.controlx.list.ListModel;
44  import info.magnolia.cms.gui.controlx.search.RepositorySearchListModel;
45  import info.magnolia.cms.gui.controlx.search.SearchConfig;
46  import info.magnolia.cms.gui.controlx.search.SimpleSearchUtil;
47  import info.magnolia.cms.gui.query.SearchQuery;
48  import info.magnolia.cms.i18n.Messages;
49  import info.magnolia.cms.i18n.MessagesManager;
50  import info.magnolia.context.MgnlContext;
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      public ListModel getModel() {
64          return new RepositorySearchListModel(ContentRepository.WEBSITE);
65      }
66  
67      public void configureList(ListControl list) {
68          list.setRenderer(new AdminListControlRenderer() {
69  
70              public String onDblClick(ListControl list, Integer index) {
71                  return "mgnl.admininterface.WebsiteSearchList.show();";
72              }
73  
74              public String onSelect(ListControl list, Integer index) {
75                  String js = "mgnl.admininterface.WebsiteSearchList.selected = '" + list.getIteratorValue("path") + "';";
76                  js += super.onSelect(list, index);
77                  return js;
78              }
79          });
80  
81          // show the icon by the name
82          list.addColumn(new ListColumn() {
83  
84              {
85                  setName("name");
86                  setColumnName("name");
87                  setLabel("Name");
88                  setWidth("200");
89              }
90  
91              public String render() {
92                  return "<span style=\"vertical-align: middle\"><img  src=\""
93                      + MgnlContext.getContextPath()
94                      + "/.resources/icons/16/document_plain_earth.gif\"/></span>"
95                      + this.getValue();
96              }
97  
98          });
99  
100         list.addColumn(new ListColumn("mgnl:authorid", "User", "200", true));
101         list.addColumn(new ListColumn("title", "Title", "200", true));
102 
103         list.addSortableField("name");
104         list.addSortableField("title");
105 
106         list.addGroupableField("mgnl:authorid");
107     }
108 
109     protected void configureContextMenu(ContextMenu menu) {
110         ContextMenuItem open = new ContextMenuItem("open");
111         open.setLabel(msgs.get("tree.web.menu.open")); //$NON-NLS-1$
112         open.setIcon(request.getContextPath() + "/.resources/icons/16/document_plain_earth.gif"); //$NON-NLS-1$
113         open.setOnclick("mgnl.admininterface.WebsiteSearchList.show();"); //$NON-NLS-1$
114         open.addJavascriptCondition("{test: function(){return mgnl.admininterface.WebsiteSearchList.selected != null}}");
115 
116         ContextMenuItem navigate = new ContextMenuItem("navigate");
117         navigate.setLabel(msgs.get("tree.menu.navigate")); //$NON-NLS-1$
118         navigate.setIcon(request.getContextPath() + "/.resources/icons/16/compass.gif"); //$NON-NLS-1$
119         navigate.setOnclick("mgnl.admininterface.WebsiteSearchList.navigate();"); //$NON-NLS-1$
120         navigate.addJavascriptCondition("{test: function(){return mgnl.admininterface.WebsiteSearchList.selected != null}}");
121 
122         menu.addMenuItem(open);
123         menu.addMenuItem(null);
124         menu.addMenuItem(navigate);
125     }
126 
127     protected void configureFunctionBar(FunctionBar bar) {
128         super.configureFunctionBar(bar);
129         bar.setOnSearchFunction("mgnl.admininterface.WebsiteSearchList.search");
130 
131         ContextMenu menu = this.getContextMenu();
132 
133         bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("open")));
134         bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("navigate")));
135 
136     }
137 
138     /**
139      * Here we create a all over query
140      */
141     public SearchQuery getQuery() {
142         return SimpleSearchUtil.getSimpleSearchQuery(this.getSearchStr());
143 
144     }
145 
146     /**
147      * Not used in this context
148      */
149     public SearchConfig getSearchConfig() {
150         return null;
151     }
152 
153 }