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.cms.gui.control;
35  
36  import info.magnolia.freemarker.FreemarkerUtil;
37  
38  import java.util.HashMap;
39  import java.util.Map;
40  
41  
42  /**
43   * The bar containing function buttons and the search field.
44   * @author higi
45   */
46  public class FunctionBar extends ContextMenu {
47  
48      /**
49       * Name to reference this object in js
50       */
51      private String javascriptName;
52  
53      /**
54       * True if the search field is showed
55       */
56      private boolean searchable = false;
57  
58      /**
59       * Javascript called if Enter is pressed in the field
60       */
61      private String onSearchFunction = "function(val){alert(val)}";
62  
63      /**
64       * String already present in the search field
65       */
66      private String searchStr = "";
67  
68      /**
69       * @param menuName the name of this menu (used in js)
70       */
71      public FunctionBar(String menuName) {
72          super(menuName);
73          this.javascriptName = "mgnlFunctionBar";
74      }
75  
76      /**
77       * Render the html code using the freemarker template
78       */
79      @Override
80      public String getHtml() {
81          Map params = new HashMap();
82          params.put("functionBar", this);
83          return FreemarkerUtil.process("info/magnolia/cms/gui/control/FunctionBar.ftl", params);
84      }
85  
86      /**
87       * Render the javascript code to initialize it
88       */
89      @Override
90      public String getJavascript() {
91          Map params = new HashMap();
92          params.put("functionBar", this);
93          return FreemarkerUtil.process("info/magnolia/cms/gui/control/FunctionBarJavascript.ftl", params);
94      }
95  
96      /**
97       * @return true if the functionBar has one or more functionBarItems
98       */
99      public boolean hasMenuItems() {
100         return !this.getMenuItems().isEmpty();
101     }
102 
103     @Override
104     public void addMenuItem(ContextMenuItem item) {
105         if(item != null && !(item instanceof FunctionBarItem)){
106             item = new FunctionBarItem(item);
107         }
108         super.addMenuItem(item);
109     }
110     /**
111      * @return Returns the javascriptName.
112      */
113     public String getJavascriptName() {
114         return javascriptName;
115     }
116 
117     /**
118      * @param javascriptName The javascriptName to set.
119      */
120     public void setJavascriptName(String javascriptName) {
121         this.javascriptName = javascriptName;
122     }
123 
124     /**
125      * @return Returns the searchable.
126      */
127     public boolean isSearchable() {
128         return this.searchable;
129     }
130 
131     /**
132      * @param searchable The searchable to set.
133      */
134     public void setSearchable(boolean searchable) {
135         this.searchable = searchable;
136     }
137 
138     /**
139      * @return Returns the onSearchFunction.
140      */
141     public String getOnSearchFunction() {
142         return this.onSearchFunction;
143     }
144 
145     /**
146      * @param onSearch The onSearch function to set.
147      */
148     public void setOnSearchFunction(String onSearch) {
149         this.onSearchFunction = onSearch;
150     }
151 
152     /**
153      * @return Returns the searchStr.
154      */
155     public String getSearchStr() {
156         return this.searchStr;
157     }
158 
159     /**
160      * @param searchStr The searchStr to set.
161      */
162     public void setSearchStr(String searchStr) {
163         this.searchStr = searchStr;
164     }
165 }