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.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 public String getHtml() { 80 Map params = new HashMap(); 81 params.put("functionBar", this); 82 return FreemarkerUtil.process("info/magnolia/cms/gui/control/FunctionBar.ftl", params); 83 } 84 85 /** 86 * Render the javascript code to initialize it 87 */ 88 public String getJavascript() { 89 Map params = new HashMap(); 90 params.put("functionBar", this); 91 return FreemarkerUtil.process("info/magnolia/cms/gui/control/FunctionBarJavascript.ftl", params); 92 } 93 94 /** 95 * @return true if the functionBar has one or more functionBarItems 96 */ 97 public boolean hasMenuItems() { 98 return !this.getMenuItems().isEmpty(); 99 } 100 101 public void addMenuItem(ContextMenuItem item) { 102 if(item != null && !(item instanceof FunctionBarItem)){ 103 item = new FunctionBarItem(item); 104 } 105 super.addMenuItem(item); 106 } 107 /** 108 * @return Returns the javascriptName. 109 */ 110 public String getJavascriptName() { 111 return javascriptName; 112 } 113 114 /** 115 * @param javascriptName The javascriptName to set. 116 */ 117 public void setJavascriptName(String javascriptName) { 118 this.javascriptName = javascriptName; 119 } 120 121 /** 122 * @return Returns the searchable. 123 */ 124 public boolean isSearchable() { 125 return this.searchable; 126 } 127 128 /** 129 * @param searchable The searchable to set. 130 */ 131 public void setSearchable(boolean searchable) { 132 this.searchable = searchable; 133 } 134 135 /** 136 * @return Returns the onSearchFunction. 137 */ 138 public String getOnSearchFunction() { 139 return this.onSearchFunction; 140 } 141 142 /** 143 * @param onSearch The onSearch function to set. 144 */ 145 public void setOnSearchFunction(String onSearch) { 146 this.onSearchFunction = onSearch; 147 } 148 149 /** 150 * @return Returns the searchStr. 151 */ 152 public String getSearchStr() { 153 return this.searchStr; 154 } 155 156 /** 157 * @param searchStr The searchStr to set. 158 */ 159 public void setSearchStr(String searchStr) { 160 this.searchStr = searchStr; 161 } 162 }