View Javadoc
1   /*******************************************************************************
2    * Copyright 2012 Internet2
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   ******************************************************************************/
16  /*
17   * Copyright (C) 2004-2007 University Corporation for Advanced Internet Development, Inc.
18   * Copyright (C) 2004-2007 The University Of Pennsylvania
19   * 
20   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
21   * file except in compliance with the License. You may obtain a copy of the License at
22   * 
23   * http://www.apache.org/licenses/LICENSE-2.0
24   * 
25   * Unless required by applicable law or agreed to in writing, software distributed under
26   * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
27   * KIND, either express or implied. See the License for the specific language governing
28   * permissions and limitations under the License.
29   */
30  package edu.internet2.middleware.grouper.ui.tags;
31  
32  import java.io.IOException;
33  
34  import javax.servlet.jsp.JspException;
35  import javax.servlet.jsp.tagext.SimpleTagSupport;
36  
37  import org.apache.commons.lang.StringUtils;
38  
39  import edu.internet2.middleware.grouper.ui.util.GrouperUiUtils;
40  
41  /**
42   * <pre>
43   * This will generate a combobox
44   * </pre>
45   * @author mchyzer
46   *
47   */
48  public class GrouperComboboxTag extends SimpleTagSupport {
49  
50    /** id and class of elements, and name of combobox.  Make this unique in app */
51    private String id;
52    
53    /** width, int, means pixels */
54    private int width = -1;
55  
56    /** the operation to call when filtering */
57    private String filterOperation;
58  
59    /** the default text which should appear in the combo box when drawn */
60    private String comboDefaultText;
61    
62    /** the default value (will be submitted) which should appear in the combo box when drawn */
63    private String comboDefaultValue;
64    
65    /** send more form element names to the filter operation, comma separated */
66    private String additionalFormElementNames;
67    
68    /**
69     * send more form element names to the filter operation, comma separated
70     * @param additionalFormElementNames1
71     */
72    public void setAdditionalFormElementNames(String additionalFormElementNames1) {
73      this.additionalFormElementNames = additionalFormElementNames1;
74    }
75  
76    /**
77     * the default text which should appear in the combo box when drawn
78     * @param comboDefaultText1
79     */
80    public void setComboDefaultText(String comboDefaultText1) {
81      this.comboDefaultText = comboDefaultText1;
82    }
83  
84    /**
85     * the default value (will be submitted) which should appear in the combo box when drawn
86     * @param comboDefaultValue1
87     */
88    public void setComboDefaultValue(String comboDefaultValue1) {
89      this.comboDefaultValue = comboDefaultValue1;
90    }
91  
92    /**
93     * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
94     */
95    @Override
96    public void doTag() throws JspException, IOException {
97  
98      StringBuilder result = new StringBuilder();
99      
100     //<div id="simpleMembershipUpdatePickGroupDiv" style="width:400px;"></div>
101     //
102     //<script> 
103     //    guiRegisterDhtmlxCombo('simpleMembershipUpdatePickGroupDiv', 
104     //       'simpleMembershipUpdatePickGroup', 400, 
105     //        true, "../app/SimpleMembershipUpdate.filterGroups", 'defaultText', 'defaultValue' );    
106     //</script> 
107     
108     //if it was shorthand, prefix with the full path
109     if (!StringUtils.contains(this.filterOperation, "/")) {
110       this.filterOperation = "../app/" + this.filterOperation;
111     }
112     
113     result.append("<div id=\"").append(this.id + "Div").append("\"");
114     if (this.width != -1) {
115       //TODO this width doesnt work since the width: part isnt there, or px
116       result.append(" style=\"").append(this.width).append("\"");
117     }
118     result.append("></div>\n");
119     result.append("<script type=\"text/javascript\"> \n");
120     result.append("guiRegisterDhtmlxCombo('").append(this.id).append("Div', '")
121        .append(this.id).append("', ")
122       .append(this.width == -1 ? null : this.width).append(", true, \"");
123     result.append(this.filterOperation).append("\", ");
124     if (StringUtils.isBlank(this.comboDefaultText)) {
125       result.append("null");
126     } else {
127       result.append("'").append(GrouperUiUtils.escapeJavascript(this.comboDefaultText, true)).append("'");
128     }
129     result.append(", ");
130     if (StringUtils.isBlank(this.comboDefaultValue)) {
131       result.append("null");
132     } else {
133       result.append("'").append(GrouperUiUtils.escapeJavascript(this.comboDefaultValue, true)).append("'");
134     }
135     result.append(", ");
136     if (StringUtils.isBlank(this.additionalFormElementNames)) {
137       result.append("null");
138     } else {
139       result.append("'").append(GrouperUiUtils.escapeJavascript(this.additionalFormElementNames, true)).append("'");
140     }
141     result.append(");\n");
142     
143     
144     result.append("</script>\n");
145 
146     this.getJspContext().getOut().print(result.toString());
147   }
148   
149   /**
150    * id and class of elements, and name of combobox.  Make this unique in app
151    * @param id1 the id to set
152    */
153   public void setId(String id1) {
154     this.id = id1;
155   }
156   
157   /**
158    * width, int, means pixels
159    * @param width1 the width to set
160    */
161   public void setWidth(int width1) {
162     this.width = width1;
163   }
164   
165   /**
166    * the operation to call when filtering
167    * @param filterOperation1 the filterOperation to set
168    */
169   public void setFilterOperation(String filterOperation1) {
170     this.filterOperation = filterOperation1;
171   }
172 
173 }