001/**
002 * Copyright 2005-2018 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 */
016package org.kuali.rice.krad.uif.element;
017
018import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
019import org.kuali.rice.krad.uif.element.ContentElementBase;
020import org.kuali.rice.krad.uif.util.LifecycleElement;
021
022/**
023 * Pager widgets are used to page a set of information which has multiple pages.
024 *
025 * @author Kuali Rice Team (rice.collab@kuali.org)
026 * @see org.kuali.rice.krad.uif.layout.StackedLayoutManager
027 */
028public abstract class Pager extends ContentElementBase {
029    private static final long serialVersionUID = 4581039429463422458L;
030
031    private String linkScript;
032
033    private int numberOfPages;
034    private int currentPage;
035
036    private String prevText;
037    private String nextText;
038
039    public Pager() {
040        super();
041    }
042
043    /**
044     * performFinalize calculates the pagesStart and pagesEnd properties (using numberOfPages, currentPage, and
045     * maxNumberedLinksShown - these must be set) which determines pages shown by the widget
046     *
047     * @param model the current model
048     * @param parent parent container
049     */
050    @Override
051    public void performFinalize(Object model, LifecycleElement parent) {
052        super.performFinalize(model, parent);
053
054        // if no pages or 1 page, do not render
055        if (numberOfPages == 0 || numberOfPages == 1) {
056            this.setRender(false);
057        }
058
059        this.linkScript = "e.preventDefault();" + this.linkScript;
060    }
061
062    /**
063     * The script to execute when a link is clicked (should probably use the "this" var in most cases, to determine
064     * page number selected - see retrieveStackedPage(linkElement, collectionId) js function)
065     *
066     * @return the script to execute when a link is clicked
067     */
068    @BeanTagAttribute
069    public String getLinkScript() {
070        return linkScript;
071    }
072
073    /**
074     * Set the link js script
075     *
076     * @param linkScript the link js script
077     */
078    public void setLinkScript(String linkScript) {
079        this.linkScript = linkScript;
080    }
081
082    /**
083     * Number of pages TOTAL that make up the component being paged (this must be set by the framework based on some
084     * list size)
085     *
086     * @return the number of pages used in this pager
087     */
088    public int getNumberOfPages() {
089        return numberOfPages;
090    }
091
092    /**
093     * Set the TOTAL number of pages
094     *
095     * @param numberOfPages
096     */
097    public void setNumberOfPages(int numberOfPages) {
098        this.numberOfPages = numberOfPages;
099    }
100
101    /**
102     * The current page being shown by this pager widget (this must be set when the page is changed)
103     *
104     * @return the current page being shown
105     */
106    public int getCurrentPage() {
107        return currentPage;
108    }
109
110    /**
111     * Set the current page
112     *
113     * @param currentPage
114     */
115    public void setCurrentPage(int currentPage) {
116        this.currentPage = currentPage;
117    }
118
119    /**
120     * The text to use on the previous link.
121     *
122     * @return the previous link text
123     */
124    @BeanTagAttribute
125    public String getPrevText() {
126        return prevText;
127    }
128
129    /**
130     * @see Pager#getPrevText()
131     */
132    public void setPrevText(String prevText) {
133        this.prevText = prevText;
134    }
135
136    /**
137     * The text to use on the next link.
138     *
139     * @return the next link text
140     */
141    @BeanTagAttribute
142    public String getNextText() {
143        return nextText;
144    }
145
146    /**
147     * @see Pager#getNextText()
148     */
149    public void setNextText(String nextText) {
150        this.nextText = nextText;
151    }
152}