Coverage Report - org.kuali.rice.krad.uif.container.PageGroup
 
Classes in this File Line Coverage Branch Coverage Complexity
PageGroup
0%
0/42
0%
0/30
6
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.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.krad.uif.container;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.config.property.ConfigurationService;
 20  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 21  
 import org.kuali.rice.krad.uif.component.Component;
 22  
 import org.kuali.rice.krad.uif.view.View;
 23  
 import org.kuali.rice.krad.uif.widget.Growls;
 24  
 import org.kuali.rice.krad.util.ErrorMessage;
 25  
 import org.kuali.rice.krad.util.GlobalVariables;
 26  
 import org.kuali.rice.krad.util.MessageMap;
 27  
 import org.springframework.util.AutoPopulatingList;
 28  
 
 29  
 import java.text.MessageFormat;
 30  
 import java.util.List;
 31  
 
 32  
 /**
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  */
 35  0
 public class PageGroup extends Group {
 36  
     private static final long serialVersionUID = 7571981300587270274L;
 37  
 
 38  
     private boolean autoFocus;
 39  
 
 40  
     /**
 41  
      * Perform finalize here adds to its document ready script the
 42  
      * setupValidator js function for setting up the validator for this view.
 43  
      *
 44  
      * @see org.kuali.rice.krad.uif.container.ContainerBase#performFinalize(org.kuali.rice.krad.uif.view.View,
 45  
      *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
 46  
      */
 47  
     @Override
 48  
     public void performFinalize(View view, Object model, Component parent) {
 49  0
         super.performFinalize(view, model, parent);
 50  
 
 51  0
         String prefixScript = "";
 52  0
         if (this.getOnDocumentReadyScript() != null) {
 53  0
             prefixScript = this.getOnDocumentReadyScript();
 54  
         }
 55  
 
 56  
         // growls are setup here because they are relevant to the current page, but their
 57  
         // settings are global to the view
 58  0
         String growlScript = "";
 59  0
         if (view.isGrowlMessagingEnabled()) {
 60  0
             Growls gw = view.getGrowls();
 61  
 
 62  
             //Setup defaults
 63  0
             if (!gw.getComponentOptions().isEmpty()) {
 64  0
                 growlScript = "setGrowlDefaults(" + gw.getComponentOptionsJSString() + ");";
 65  
             }
 66  
 
 67  0
             ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
 68  0
             MessageMap messageMap = GlobalVariables.getMessageMap();
 69  0
             if (messageMap.hasErrors()) {
 70  0
                 String message = configService.getPropertyValueAsString("growl.hasErrors");
 71  0
                 if (StringUtils.isNotBlank(message)) {
 72  0
                     growlScript =
 73  
                             growlScript + "showGrowl('" + message + "', '" + configService.getPropertyValueAsString(
 74  
                                     "general.error") + "', 'errorGrowl');";
 75  
                 }
 76  
             }
 77  
 
 78  0
             if (messageMap.hasWarnings()) {
 79  0
                 String message = configService.getPropertyValueAsString("growl.hasWarnings");
 80  0
                 if (StringUtils.isNotBlank(message)) {
 81  0
                     growlScript =
 82  
                             growlScript + "showGrowl('" + message + "', '" + configService.getPropertyValueAsString(
 83  
                                     "general.warning") + "', 'warningGrowl');";
 84  
                 }
 85  
             }
 86  
 
 87  0
             if (messageMap.hasInfo()) {
 88  0
                 List<String> properties = messageMap.getPropertiesWithInfo();
 89  0
                 String message = "";
 90  0
                 for (String property : properties) {
 91  0
                     List<AutoPopulatingList<ErrorMessage>> lists = messageMap.getInfoMessagesForProperty(property,
 92  
                             true);
 93  0
                     for (List<ErrorMessage> errorList : lists) {
 94  0
                         if (errorList != null) {
 95  0
                             for (ErrorMessage e : errorList) {
 96  0
                                 if (StringUtils.isBlank(message)) {
 97  0
                                     message = configService.getPropertyValueAsString(e.getErrorKey());
 98  
                                 } else {
 99  0
                                     message = message + "<br/>" + configService.getPropertyValueAsString(
 100  
                                             e.getErrorKey());
 101  
                                 }
 102  0
                                 if (e.getMessageParameters() != null) {
 103  0
                                     message = message.replace("'", "''");
 104  0
                                     message = MessageFormat.format(message, (Object[]) e.getMessageParameters());
 105  
                                 }
 106  
                             }
 107  
                         }
 108  
                     }
 109  0
                 }
 110  
 
 111  0
                 if (StringUtils.isNotBlank(message)) {
 112  0
                     growlScript =
 113  
                             growlScript + "showGrowl('" + message + "', '" + configService.getPropertyValueAsString(
 114  
                                     "general.info") + "', 'infoGrowl');";
 115  
                 }
 116  
             }
 117  
         }
 118  
 
 119  0
         this.setOnDocumentReadyScript(prefixScript + "\nsetupValidator();" + growlScript);
 120  0
     }
 121  
 
 122  
     /**
 123  
      * When this is true, the first field of the kualiForm will be focused by
 124  
      * default, unless the parameter focusId is set on the form (by an
 125  
      * actionField), then that field will be focused instead. When this setting
 126  
      * if false, no field will be focused.
 127  
      *
 128  
      * @return the autoFocus
 129  
      */
 130  
     public boolean isAutoFocus() {
 131  0
         return this.autoFocus;
 132  
     }
 133  
 
 134  
     /**
 135  
      * @param autoFocus the autoFocus to set
 136  
      */
 137  
     public void setAutoFocus(boolean autoFocus) {
 138  0
         this.autoFocus = autoFocus;
 139  0
     }
 140  
 
 141  
 }