001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.uif.widget;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
020 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
021 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
022 import org.kuali.rice.krad.uif.UifConstants;
023 import org.kuali.rice.krad.uif.component.Component;
024 import org.kuali.rice.krad.uif.container.Group;
025 import org.kuali.rice.krad.uif.view.View;
026
027 /**
028 * Allows client-side reordering of the group contents
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032 @BeanTag(name = "reorderer", parent = "Uif-Reorderer")
033 public class Reorderer extends WidgetBase {
034 private static final long serialVersionUID = 6142957061046219120L;
035
036 private String movableStyleClass;
037
038 public Reorderer() {
039 super();
040 }
041
042 /**
043 * The following initialization is performed:
044 *
045 * <ul>
046 * <li>Adds the movable style class to each group item</li>
047 * <li>Prepares the movable widget option based on the movable style class</li>
048 * </ul>
049 */
050 @Override
051 public void performFinalize(View view, Object model, Component component) {
052 super.performFinalize(view, model, component);
053
054 if (!(component instanceof Group)) {
055 throw new RiceIllegalArgumentException("Parent component for Reorderer widget must be a group.");
056 }
057
058 if (StringUtils.isNotBlank(movableStyleClass)) {
059 for (Component item : ((Group) component).getItems()) {
060 item.addStyleClass(movableStyleClass);
061 }
062
063 // add the default movable class to the selectors option if not already configured
064 if (!getTemplateOptions().containsKey(UifConstants.ReordererOptionKeys.SELECTORS)) {
065 String selectorsOption =
066 "{" + UifConstants.ReordererOptionKeys.MOVABLES + " : 'span." + movableStyleClass + "' }";
067 getTemplateOptions().put(UifConstants.ReordererOptionKeys.SELECTORS, selectorsOption);
068 }
069 }
070 }
071
072 /**
073 * Returns the style class for the item spans that will identify a movable element
074 *
075 * <p>
076 * Given style class will be used to build a jQuery selector that is then passed to the
077 * reorderer widget through the options
078 * </p>
079 *
080 * @return String style class
081 */
082 @BeanTagAttribute(name="movableStyleClass")
083 public String getMovableStyleClass() {
084 return movableStyleClass;
085 }
086
087 /**
088 * Setter for the style class that identifies movable elements (spans)
089 *
090 * @param movableStyleClass
091 */
092 public void setMovableStyleClass(String movableStyleClass) {
093 this.movableStyleClass = movableStyleClass;
094 }
095 }