| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| LightBox |
|
| 5.5;5.5 |
| 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 | 0 | super(); |
| 32 | 0 | } |
| 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 | * @return String of widget options formatted as JS Map | |
| 42 | */ | |
| 43 | @Override | |
| 44 | public String getComponentOptionsJSString() { | |
| 45 | 0 | if (getComponentOptions() == null) { |
| 46 | 0 | setComponentOptions(new HashMap<String, String>()); |
| 47 | } | |
| 48 | 0 | StringBuffer sb = new StringBuffer(); |
| 49 | ||
| 50 | 0 | sb.append("{"); |
| 51 | ||
| 52 | 0 | for (String optionKey : getComponentOptions().keySet()) { |
| 53 | 0 | String optionValue = getComponentOptions().get(optionKey); |
| 54 | ||
| 55 | 0 | if (sb.length() > 1) { |
| 56 | 0 | sb.append(","); |
| 57 | } | |
| 58 | ||
| 59 | 0 | sb.append(optionKey); |
| 60 | 0 | sb.append(":"); |
| 61 | ||
| 62 | //If an option value starts with { or [, it would be a nested value and it should not use quotes around it | |
| 63 | // If value is a function script do not use quotes | |
| 64 | 0 | if (StringUtils.startsWith(optionValue, "{") || StringUtils.startsWith(optionValue, "[") |
| 65 | || (StringUtils.startsWith(optionValue, "function") && StringUtils.endsWith(optionValue, "}")) | |
| 66 | || optionValue.equals("true") || optionValue.equals("false")){ | |
| 67 | 0 | sb.append(optionValue); |
| 68 | }else{ | |
| 69 | 0 | sb.append("\"" + optionValue + "\""); |
| 70 | } | |
| 71 | 0 | } |
| 72 | ||
| 73 | 0 | sb.append("}"); |
| 74 | 0 | return sb.toString(); |
| 75 | } | |
| 76 | ||
| 77 | } |