View Javadoc
1   /**
2    * Copyright 2005-2016 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.element;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.uif.UifConstants;
21  import org.kuali.rice.krad.uif.container.CollectionGroup;
22  import org.kuali.rice.krad.uif.util.LifecycleElement;
23  import org.kuali.rice.krad.uif.util.UrlInfo;
24  import org.kuali.rice.krad.web.form.UifFormBase;
25  
26  /**
27   * A content element that will display the collection configured with a file upload button.
28   *
29   * <p>This is used to list objects that represent files.
30   * The file will be uploaded to the methodToCall specified and the response is expected to be the refreshed collection.
31   * </p>
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  @BeanTag(name = "multiFileUploadCollection", parent = "Uif-MultiFileUploadCollection")
36  public class MultiFileUploadCollection extends ContentElementBase {
37      private static final long serialVersionUID = 6324034860109503990L;
38  
39      private CollectionGroup collection;
40  
41      private String methodToCall;
42      private UrlInfo url;
43  
44      private String addFilesButtonText;
45  
46      private String acceptFileTypes;
47      private Integer maxFileSize;
48      private Integer minFileSize;
49  
50      private String propertyPath;
51  
52      /**
53       * This finalize method adds template options to the templateOptions property based on settings in the
54       * parameters of this class
55       *
56       * {@inheritDoc}
57       */
58      @Override
59      public void performFinalize(Object model, LifecycleElement parent) {
60          super.performFinalize(model, parent);
61  
62          UifFormBase form = (UifFormBase) model;
63  
64          // Set plugin convenience setters into templateOptions to be consumed by the plugin
65          if (url == null && methodToCall != null) {
66              getTemplateOptions().put(UifConstants.MultiFileUploadOptions.URL,
67                      "?methodToCall=" + methodToCall + "&formKey=" + form.getFormKey() + "&viewId=" + form.getViewId()
68                              + "&bindingPath=" + collection.getBindingInfo().getBindingPath()
69                              + "&updateComponentId=" + collection.getId() );
70          } else if (url != null) {
71              getTemplateOptions().put(UifConstants.MultiFileUploadOptions.URL, url.getHref());
72          }
73  
74          if (acceptFileTypes != null) {
75              getTemplateOptions().put(UifConstants.MultiFileUploadOptions.ACCEPT_FILE_TYPES, acceptFileTypes);
76          }
77  
78          if (maxFileSize != null) {
79              getTemplateOptions().put(UifConstants.MultiFileUploadOptions.MAX_SIZE, maxFileSize.toString());
80          }
81  
82          if (minFileSize != null) {
83              getTemplateOptions().put(UifConstants.MultiFileUploadOptions.MIN_SIZE, minFileSize.toString());
84          }
85  
86          this.propertyPath = collection.getBindingInfo().getBindingPath();
87  
88          // Make collection inherit readOnly
89          this.collection.setReadOnly(this.getReadOnly());
90      }
91  
92      /**
93       * The collection which holds the files uploaded
94       *
95       * @return the collection
96       */
97      @BeanTagAttribute
98      public CollectionGroup getCollection() {
99          return collection;
100     }
101 
102     /**
103      * @see MultiFileUploadCollection#getCollection()
104      */
105     public void setCollection(CollectionGroup collection) {
106         this.collection = collection;
107     }
108 
109     /**
110      * The methodToCall for uploading files, this methodToCall must return the refreshed collection
111      *
112      * @return the methodToCall for file uploads
113      */
114     @BeanTagAttribute
115     public String getMethodToCall() {
116         return methodToCall;
117     }
118 
119     /**
120      * @see MultiFileUploadCollection#getMethodToCall()
121      */
122     public void setMethodToCall(String methodToCall) {
123         this.methodToCall = methodToCall;
124     }
125 
126     /**
127      * The url override for file uploads, this will be used instead of the methodToCall, if set, as the url to post
128      * the file upload to
129      *
130      * @return the file upload url configuration override
131      */
132     @BeanTagAttribute
133     public UrlInfo getUrl() {
134         return url;
135     }
136 
137     /**
138      * @see MultiFileUploadCollection#getUrl()
139      */
140     public void setUrl(UrlInfo url) {
141         this.url = url;
142     }
143 
144     /**
145      * The text to be used on the add files button
146      *
147      * @return the text of the add files button
148      */
149     @BeanTagAttribute
150     public String getAddFilesButtonText() {
151         return addFilesButtonText;
152     }
153 
154     /**
155      * @see MultiFileUploadCollection#getAddFilesButtonText()
156      */
157     public void setAddFilesButtonText(String addFilesButtonText) {
158         this.addFilesButtonText = addFilesButtonText;
159     }
160 
161     /**
162      * A regex used to allow or disallow a certain file types for this file upload component
163      *
164      * @return the regex for file upload verification
165      */
166     @BeanTagAttribute
167     public String getAcceptFileTypes() {
168         return acceptFileTypes;
169     }
170 
171     /**
172      * @see MultiFileUploadCollection#getAcceptFileTypes()
173      */
174     public void setAcceptFileTypes(String acceptFileTypes) {
175         this.acceptFileTypes = acceptFileTypes;
176     }
177 
178     /**
179      * The maximum file size to allow (in bytes) for a file upload
180      *
181      * @return maximum file size in bytes
182      */
183     @BeanTagAttribute
184     public Integer getMaxFileSize() {
185         return maxFileSize;
186     }
187 
188     /**
189      * @see MultiFileUploadCollection#getMaxFileSize()
190      */
191     public void setMaxFileSize(Integer maxFileSize) {
192         this.maxFileSize = maxFileSize;
193     }
194 
195     /**
196      * The minimum file size needed (in bytes) for a file to be uploaded
197      *
198      * @return minimum file size in bytes
199      */
200     @BeanTagAttribute
201     public Integer getMinFileSize() {
202         return minFileSize;
203     }
204 
205     /**
206      * @see MultiFileUploadCollection#getMinFileSize()
207      */
208     public void setMinFileSize(Integer minFileSize) {
209         this.minFileSize = minFileSize;
210     }
211 
212     /**
213      * The property path used for this component, which is the binding path of collection
214      *
215      * @return the property path
216      */
217     public String getPropertyPath() {
218         return propertyPath;
219     }
220 }