1 /*
2 * Copyright 2007 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
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 package org.kuali.rice.kns.uif.widget;
17
18 import java.util.HashMap;
19
20 import org.apache.commons.lang.StringUtils;
21
22 /**
23 * Used for rendering a lightbox in the UI to display links in dialog popups
24 *
25 * @author Kuali Rice Team (rice.collab@kuali.org)
26 */
27 public class LightBox extends WidgetBase {
28 private static final long serialVersionUID = -4004284762546700975L;
29
30 public LightBox() {
31 super();
32 }
33
34 /**
35 * Overide to cater for passing functions to fancybox without quotes.
36 * If this is not be specific to Fancybox it should be moved to ComponentBase
37 * Builds a string from the underlying <code>Map</code> of component options
38 * that will export that options as a JavaScript Map for use in js and
39 * jQuery plugins.
40 *
41 * TODO: move to component base
42 *
43 * @return String of widget options formatted as JS Map
44 */
45 @Override
46 public String getComponentOptionsJSString() {
47 if (getComponentOptions() == null) {
48 setComponentOptions(new HashMap<String, String>());
49 }
50 StringBuffer sb = new StringBuffer();
51
52 sb.append("{");
53
54 for (String optionKey : getComponentOptions().keySet()) {
55 String optionValue = getComponentOptions().get(optionKey);
56
57 if (sb.length() > 1) {
58 sb.append(",");
59 }
60
61 sb.append(optionKey);
62 sb.append(":");
63
64 //If an option value starts with { or [, it would be a nested value and it should not use quotes around it
65 // If value is a function script do not use quotes
66 if (StringUtils.startsWith(optionValue, "{") || StringUtils.startsWith(optionValue, "[")
67 || (StringUtils.startsWith(optionValue, "function") && StringUtils.endsWith(optionValue, "}"))
68 || optionValue.equals("true") || optionValue.equals("false")){
69 sb.append(optionValue);
70 }else{
71 sb.append("\"" + optionValue + "\"");
72 }
73 }
74
75 sb.append("}");
76 return sb.toString();
77 }
78
79 }