Coverage Report - org.kuali.rice.kns.uif.widget.LightBox
 
Classes in this File Line Coverage Branch Coverage Complexity
LightBox
0%
0/18
0%
0/18
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  
      * TODO: move to component base
 42  
          * 
 43  
          * @return String of widget options formatted as JS Map
 44  
          */
 45  
         @Override
 46  
         public String getComponentOptionsJSString() {
 47  0
                 if (getComponentOptions() == null) {
 48  0
                         setComponentOptions(new HashMap<String, String>());
 49  
                 }
 50  0
                 StringBuffer sb = new StringBuffer();
 51  
 
 52  0
                 sb.append("{");
 53  
 
 54  0
                 for (String optionKey : getComponentOptions().keySet()) {
 55  0
                         String optionValue = getComponentOptions().get(optionKey);
 56  
 
 57  0
                         if (sb.length() > 1) {
 58  0
                                 sb.append(",");
 59  
                         }
 60  
 
 61  0
                         sb.append(optionKey);
 62  0
                         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  0
                         if (StringUtils.startsWith(optionValue, "{") || StringUtils.startsWith(optionValue, "[") 
 67  
                                         || (StringUtils.startsWith(optionValue, "function") && StringUtils.endsWith(optionValue, "}"))
 68  
                                         ||  optionValue.equals("true") || optionValue.equals("false")){
 69  0
                                 sb.append(optionValue);
 70  
                         }else{
 71  0
                                 sb.append("\"" + optionValue + "\"");
 72  
                         }
 73  0
                 }
 74  
 
 75  0
                 sb.append("}");
 76  0
                 return sb.toString();
 77  
         }
 78  
         
 79  
 }