Coverage Report - org.kuali.rice.kns.uif.widget.DirectInquiry
 
Classes in this File Line Coverage Branch Coverage Complexity
DirectInquiry
0%
0/63
0%
0/18
1.9
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation Licensed under the Educational Community
 3  
  * License, Version 1.0 (the "License"); you may not use this file except in
 4  
  * compliance with the License. You may obtain a copy of the License at
 5  
  * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law
 6  
  * or agreed to in writing, software distributed under the License is
 7  
  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 8  
  * KIND, either express or implied. See the License for the specific language
 9  
  * governing permissions and limitations under the License.
 10  
  */
 11  
 package org.kuali.rice.kns.uif.widget;
 12  
 
 13  
 import java.util.List;
 14  
 import java.util.Map;
 15  
 import java.util.Map.Entry;
 16  
 import java.util.Properties;
 17  
 
 18  
 import org.kuali.rice.kns.uif.UifConstants;
 19  
 import org.kuali.rice.kns.uif.UifParameters;
 20  
 import org.kuali.rice.kns.uif.container.View;
 21  
 import org.kuali.rice.kns.uif.core.BindingInfo;
 22  
 import org.kuali.rice.kns.uif.core.Component;
 23  
 import org.kuali.rice.kns.uif.field.ActionField;
 24  
 import org.kuali.rice.kns.uif.field.AttributeField;
 25  
 import org.kuali.rice.kns.util.UrlFactory;
 26  
 
 27  
 /**
 28  
  * Widget for rendering an Direct Inquiry link icon next to a input field
 29  
  * 
 30  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 31  
  */
 32  
 public class DirectInquiry extends Inquiry {
 33  
     
 34  
     private static final long serialVersionUID = -2490979579285984314L;
 35  
     
 36  
     private ActionField directInquiryActionField;
 37  
     
 38  
     // Binding Info fields used by direct inquiry to access html fields
 39  
     private String bindingPrefix;
 40  
     
 41  
     private boolean bindToMap;
 42  
 
 43  
     public DirectInquiry() {
 44  0
         super();
 45  0
     }
 46  
 
 47  
     /**
 48  
      * @see org.kuali.rice.kns.uif.widget.WidgetBase#performFinalize(org.kuali.rice.kns.uif.container.View,
 49  
      *      java.lang.Object, org.kuali.rice.kns.uif.core.Component)
 50  
      */
 51  
     @Override
 52  
     public void performFinalize(View view, Object model, Component parent) {
 53  0
         super.performFinalize(view, model, parent);
 54  
 
 55  
         // only set inquiry if enabled
 56  0
         if (!isRender() || isReadOnly()) {
 57  0
             return;
 58  
         }
 59  
 
 60  
         // set render to false until we find an inquiry class
 61  0
         setRender(false);
 62  
 
 63  0
         AttributeField field = (AttributeField) parent;
 64  
         
 65  
         // If this is a direct inquiry (not read only) then set the binding prefix
 66  
         // for mapping to the field names used in the script to get values from the form
 67  0
             BindingInfo bindingInfo = field.getBindingInfo();
 68  0
             if (bindingInfo.isBindToForm()) {
 69  0
                     bindingPrefix = bindingInfo.getBindByNamePrefix();
 70  0
             }else if (bindingInfo.isBindToMap()){
 71  0
                     bindToMap = true;
 72  0
                     bindingPrefix = bindingInfo.getBindingObjectPath();
 73  
             }else{
 74  0
                     bindingPrefix = bindingInfo.getBindingObjectPath() + (bindingInfo.getBindByNamePrefix()==null?"":("." + bindingInfo.getBindByNamePrefix()));
 75  
             }
 76  
 
 77  0
             setupLink(view, model, field);
 78  0
     }
 79  
 
 80  
     /**
 81  
      * Builds the inquiry link and onclick script based on the given inquiry class and parameters
 82  
      * 
 83  
      * @param dataObject
 84  
      *            - parent object that contains the data (used to pull inquiry
 85  
      *            parameters)
 86  
      * @param propertyName
 87  
      *            - name of the property the inquiry is set on
 88  
      * @param inquiryObjectClass
 89  
      *            - class of the object the inquiry should point to
 90  
      * @param inquiryParms
 91  
      *            - map of key field mappings for the inquiry
 92  
      */
 93  
         public void buildInquiryLink(Object dataObject, String propertyName,
 94  
                         Class<?> inquiryObjectClass, Map<String, String> inquiryParms) {
 95  0
                 Properties urlParameters = new Properties();
 96  
 
 97  0
                 urlParameters.put(UifParameters.DATA_OBJECT_CLASS_NAME,
 98  
                                 inquiryObjectClass.getName());
 99  0
                 urlParameters.put(UifParameters.METHOD_TO_CALL,
 100  
                                 UifConstants.MethodToCallNames.START);
 101  
 
 102  
                 // Direct inquiry
 103  0
                 String inquiryUrl = UrlFactory.parameterizeUrl(getBaseInquiryUrl(),
 104  
                                 urlParameters);
 105  0
                 StringBuilder paramMapString = new StringBuilder();
 106  
                 // Check if lightbox is set. Get lightbox options.
 107  0
                 String lightBoxOptions = "";
 108  0
                 boolean lightBoxShow = directInquiryActionField.getLightBox() != null;
 109  0
                 if (lightBoxShow) {
 110  0
                         lightBoxOptions = directInquiryActionField.getLightBox()
 111  
                                         .getComponentOptionsJSString();
 112  
                 }
 113  
 
 114  
                 // Build parameter string using the actual names of the fields as on the
 115  
                 // html page
 116  0
                 for (Entry<String, String> inquiryParameter : inquiryParms.entrySet()) {
 117  0
                         if (bindToMap) {
 118  0
                                 paramMapString.append(bindingPrefix);
 119  0
                                 paramMapString.append("['");
 120  0
                                 paramMapString.append(inquiryParameter.getKey());
 121  0
                                 paramMapString.append("']");
 122  
                         } else {
 123  0
                                 paramMapString.append(bindingPrefix);
 124  0
                                 paramMapString.append(".");
 125  0
                                 paramMapString.append(inquiryParameter.getKey());
 126  
                         }
 127  0
                         paramMapString.append(":");
 128  0
                         paramMapString.append(inquiryParameter.getValue());
 129  0
                         paramMapString.append(",");
 130  
                 }
 131  0
                 paramMapString.deleteCharAt(paramMapString.length() - 1);
 132  
 
 133  
                 // Create onlick script to open the inquiry window on the click event
 134  
                 // of the direct inquiry
 135  0
                 StringBuilder onClickScript = new StringBuilder("showDirectInquiry(\"");
 136  0
                 onClickScript.append(inquiryUrl);
 137  0
                 onClickScript.append("\", \"");
 138  0
                 onClickScript.append(paramMapString);
 139  0
                 onClickScript.append("\", ");
 140  0
                 onClickScript.append(lightBoxShow);
 141  0
                 onClickScript.append(", ");
 142  0
                 onClickScript.append(lightBoxOptions);
 143  0
                 onClickScript.append(");");
 144  0
                 directInquiryActionField.setBlockValidateDirty(true);
 145  0
                 directInquiryActionField.setClientSideJs(onClickScript.toString());
 146  
 
 147  0
                 setRender(true);
 148  0
         }
 149  
 
 150  
     /**
 151  
      * @see org.kuali.rice.kns.uif.core.ComponentBase#getNestedComponents()
 152  
      */
 153  
     @Override
 154  
     public List<Component> getNestedComponents() {
 155  0
         List<Component> components = super.getNestedComponents();
 156  
 
 157  0
         components.add(directInquiryActionField);
 158  
 
 159  0
         return components;
 160  
     }        
 161  
         
 162  
         /**
 163  
          * @return the directInquiryActionField
 164  
          */
 165  
         public ActionField getDirectInquiryActionField() {
 166  0
                 return this.directInquiryActionField;
 167  
         }
 168  
 
 169  
         /**
 170  
          * @param directInquiryActionField the directInquiryActionField to set
 171  
          */
 172  
         public void setDirectInquiryActionField(ActionField directInquiryActionField) {
 173  0
                 this.directInquiryActionField = directInquiryActionField;
 174  0
         }
 175  
 
 176  
         /**
 177  
          * @return the bindingPrefix
 178  
          */
 179  
         public String getBindingPrefix() {
 180  0
                 return this.bindingPrefix;
 181  
         }
 182  
 
 183  
         /**
 184  
          * @param bindingPrefix the bindingPrefix to set
 185  
          */
 186  
         public void setBindingPrefix(String bindingPrefix) {
 187  0
                 this.bindingPrefix = bindingPrefix;
 188  0
         }
 189  
 
 190  
         /**
 191  
          * @param bindToMap the bindToMap to set
 192  
          */
 193  
         public void setBindToMap(boolean bindToMap) {
 194  0
                 this.bindToMap = bindToMap;
 195  0
         }
 196  
 
 197  
         /**
 198  
          * @return the bindToMap
 199  
          */
 200  
         public boolean isBindToMap() {
 201  0
                 return bindToMap;
 202  
         }
 203  
 
 204  
 }