| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.core.document.ui.client.widgets.documenttool; |
| 17 | |
|
| 18 | |
import java.util.List; |
| 19 | |
import java.util.Map; |
| 20 | |
|
| 21 | |
import org.kuali.student.common.assembly.data.ConstraintMetadata; |
| 22 | |
import org.kuali.student.common.assembly.data.Metadata; |
| 23 | |
import org.kuali.student.common.assembly.data.QueryPath; |
| 24 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
| 25 | |
import org.kuali.student.common.ui.client.configurable.mvc.DelayedToolView; |
| 26 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
| 27 | |
import org.kuali.student.common.ui.client.configurable.mvc.HasReferenceId; |
| 28 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
| 29 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding; |
| 30 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityConfiguration; |
| 31 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityFieldConfiguration; |
| 32 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityFieldWidgetInitializer; |
| 33 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.SwapCompositeCondition; |
| 34 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.SwapCompositeConditionFieldConfig; |
| 35 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.InfoMessage; |
| 36 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.MultiplicitySection; |
| 37 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; |
| 38 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView; |
| 39 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; |
| 40 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.WarnContainer; |
| 41 | |
import org.kuali.student.common.ui.client.dto.FileStatus; |
| 42 | |
import org.kuali.student.common.ui.client.dto.UploadStatus; |
| 43 | |
import org.kuali.student.common.ui.client.dto.FileStatus.FileTransferStatus; |
| 44 | |
import org.kuali.student.common.ui.client.dto.UploadStatus.UploadTransferStatus; |
| 45 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
| 46 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
| 47 | |
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
| 48 | |
import org.kuali.student.common.ui.client.theme.Theme; |
| 49 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
| 50 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
| 51 | |
import org.kuali.student.common.ui.client.widgets.KSTextArea; |
| 52 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
| 53 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.OkGroup; |
| 54 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.OkEnum; |
| 55 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; |
| 56 | |
import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel; |
| 57 | |
import org.kuali.student.core.document.dto.DocumentTypeInfo; |
| 58 | |
import org.kuali.student.core.document.dto.RefDocRelationInfo; |
| 59 | |
import org.kuali.student.core.document.ui.client.service.DocumentRpcService; |
| 60 | |
import org.kuali.student.core.document.ui.client.service.DocumentRpcServiceAsync; |
| 61 | |
import org.kuali.student.core.document.ui.client.service.UploadStatusRpcService; |
| 62 | |
import org.kuali.student.core.document.ui.client.service.UploadStatusRpcServiceAsync; |
| 63 | |
|
| 64 | |
import com.google.gwt.core.client.GWT; |
| 65 | |
import com.google.gwt.i18n.client.NumberFormat; |
| 66 | |
import com.google.gwt.user.client.Timer; |
| 67 | |
import com.google.gwt.user.client.ui.Composite; |
| 68 | |
import com.google.gwt.user.client.ui.FileUpload; |
| 69 | |
import com.google.gwt.user.client.ui.FlexTable; |
| 70 | |
import com.google.gwt.user.client.ui.FormPanel; |
| 71 | |
import com.google.gwt.user.client.ui.HTML; |
| 72 | |
import com.google.gwt.user.client.ui.Image; |
| 73 | |
import com.google.gwt.user.client.ui.Widget; |
| 74 | |
import com.google.gwt.widgetideas.client.ProgressBar; |
| 75 | |
import com.google.gwt.widgetideas.client.ProgressBar.TextFormatter; |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | 0 | public class DocumentTool extends DelayedToolView implements HasReferenceId{ |
| 81 | |
private String referenceId; |
| 82 | |
private String referenceTypeKey; |
| 83 | |
private String referenceType; |
| 84 | |
private String referenceState; |
| 85 | |
private String refObjectTypeKey; |
| 86 | 0 | private final String refDocRelationTypeKey = "kuali.org.DocRelation.allObjectTypes"; |
| 87 | |
|
| 88 | |
private static final int POLL_INTERVAL = 2000; |
| 89 | |
|
| 90 | 0 | private DocumentRpcServiceAsync documentServiceAsync = GWT.create(DocumentRpcService.class); |
| 91 | 0 | private VerticalFlowPanel layout = new VerticalFlowPanel(); |
| 92 | 0 | private VerticalFlowPanel documentList = new VerticalFlowPanel(); |
| 93 | 0 | private VerticalFlowPanel uploadList = new VerticalFlowPanel(); |
| 94 | |
|
| 95 | 0 | private KSLabel loadingDocuments = new KSLabel("Loading Documents..."); |
| 96 | 0 | private FormPanel form = new FormPanel(); |
| 97 | 0 | private Callback<String> deleteCallback = new Callback<String>(){ |
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public void exec(String result) { |
| 101 | 0 | refreshDocuments(); |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
}; |
| 105 | |
|
| 106 | 0 | private KSLightBox progressWindow = new KSLightBox(); |
| 107 | 0 | private VerticalFlowPanel progressPanel = new VerticalFlowPanel(); |
| 108 | 0 | private KSLabel progressLabel = new KSLabel(); |
| 109 | 0 | private ProgressBar progressBar = new ProgressBar(); |
| 110 | 0 | private FlexTable fileProgressTable = new FlexTable(); |
| 111 | 0 | private InfoMessage saveWarning = new InfoMessage("The document must be saved before Document files can be uploaded.", true); |
| 112 | |
private Composite showAllLink; |
| 113 | |
|
| 114 | |
private DataModelDefinition modelDefinition; |
| 115 | |
|
| 116 | 0 | private OkGroup progressButtons = new OkGroup(new Callback<OkEnum>(){ |
| 117 | |
@Override |
| 118 | |
public void exec(OkEnum result) { |
| 119 | 0 | if(result == OkEnum.Ok){ |
| 120 | 0 | progressWindow.hide(); |
| 121 | |
} |
| 122 | 0 | } |
| 123 | |
}); |
| 124 | 0 | private UploadStatusRpcServiceAsync uploadStatusRpc = GWT.create(UploadStatusRpcService.class); |
| 125 | |
|
| 126 | 0 | private OkGroup buttonPanel = new OkGroup(new Callback<OkEnum>(){ |
| 127 | |
|
| 128 | |
@Override |
| 129 | |
public void exec(OkEnum result) { |
| 130 | 0 | if(result == OkEnum.Ok){ |
| 131 | 0 | progressButtons.getButton(OkEnum.Ok).setEnabled(false); |
| 132 | 0 | progressLabel.setText("Starting upload..."); |
| 133 | |
|
| 134 | 0 | progressBar.setProgress(0); |
| 135 | 0 | progressBar.setMaxProgress(0); |
| 136 | 0 | fileProgressTable.clear(); |
| 137 | 0 | progressWindow.show(); |
| 138 | 0 | uploadStatusRpc.getUploadId(new KSAsyncCallback<String>(){ |
| 139 | |
|
| 140 | |
@Override |
| 141 | |
public void handleFailure(Throwable caught) { |
| 142 | 0 | progressLabel.setText("Could not contact server."); |
| 143 | 0 | progressButtons.getButton(OkEnum.Ok).setEnabled(true); |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
@Override |
| 147 | |
public void onSuccess(final String result) { |
| 148 | 0 | form.setAction(GWT.getModuleBaseURL()+"rpcservices/DocumentUpload?uploadId=" + result + "&referenceId=" + referenceId +"&refObjectTypeKey=" + refObjectTypeKey + "&refDocRelationTypeKey=" + refDocRelationTypeKey); |
| 149 | 0 | form.submit(); |
| 150 | |
|
| 151 | 0 | progressLabel.setText("Uploading..."); |
| 152 | 0 | Timer progressTimer = new Timer(){ |
| 153 | 0 | private boolean maxSet = false; |
| 154 | |
@Override |
| 155 | |
public void run() { |
| 156 | 0 | uploadStatusRpc.getUploadStatus(result, new KSAsyncCallback<UploadStatus>(){ |
| 157 | |
|
| 158 | |
@Override |
| 159 | |
public void handleFailure(Throwable caught) { |
| 160 | 0 | progressLabel.setText("Unable to query upload status."); |
| 161 | 0 | progressButtons.getButton(OkEnum.Ok).setEnabled(true); |
| 162 | 0 | refreshDocuments(); |
| 163 | 0 | cancel(); |
| 164 | 0 | } |
| 165 | |
|
| 166 | 0 | private int currentFile = 0; |
| 167 | |
|
| 168 | |
@Override |
| 169 | |
public void onSuccess(UploadStatus result) { |
| 170 | 0 | if(!maxSet && result.getTotalSize() != null && result.getTotalSize() != 0){ |
| 171 | 0 | progressBar.setMaxProgress(((double)result.getTotalSize())/1024); |
| 172 | 0 | maxSet = true; |
| 173 | |
} |
| 174 | |
|
| 175 | |
|
| 176 | 0 | fileProgressTable.clear(); |
| 177 | 0 | currentFile = 0; |
| 178 | 0 | for(FileStatus fs: result.getFileStatusList()){ |
| 179 | 0 | addFileProgress(fs); |
| 180 | 0 | currentFile++; |
| 181 | |
} |
| 182 | |
|
| 183 | 0 | if(result.getProgress() != null){ |
| 184 | 0 | progressBar.setProgress(((double)result.getProgress())/1024); |
| 185 | |
} |
| 186 | |
|
| 187 | 0 | if(result.getStatus() == UploadTransferStatus.UPLOAD_FINISHED){ |
| 188 | 0 | progressLabel.setText("Processing..."); |
| 189 | 0 | progressBar.setProgress(progressBar.getMaxProgress()); |
| 190 | |
} |
| 191 | 0 | else if(result.getStatus() == UploadTransferStatus.COMMIT_FINISHED){ |
| 192 | 0 | progressLabel.setText("File upload successful!"); |
| 193 | 0 | progressBar.setProgress(progressBar.getMaxProgress()); |
| 194 | 0 | progressButtons.getButton(OkEnum.Ok).setEnabled(true); |
| 195 | 0 | resetUploadFormPanel(); |
| 196 | |
|
| 197 | 0 | cancel(); |
| 198 | 0 | refreshDocuments(); |
| 199 | |
|
| 200 | |
} |
| 201 | 0 | else if(result.getStatus() == UploadTransferStatus.ERROR){ |
| 202 | 0 | progressLabel.setText("Error uploading!"); |
| 203 | 0 | progressButtons.getButton(OkEnum.Ok).setEnabled(true); |
| 204 | 0 | refreshDocuments(); |
| 205 | 0 | cancel(); |
| 206 | |
} |
| 207 | |
|
| 208 | 0 | } |
| 209 | |
|
| 210 | 0 | NumberFormat nf = NumberFormat.getFormat("#.##"); |
| 211 | |
|
| 212 | |
private void addFileProgress(FileStatus fs) { |
| 213 | |
|
| 214 | |
HTML fileNameLabel; |
| 215 | |
|
| 216 | 0 | if(fs.getStatus() == FileTransferStatus.COMMIT_FINISHED){ |
| 217 | 0 | fileNameLabel = new HTML("<a href=\"" + GWT.getModuleBaseURL()+"rpcservices/DocumentUpload?docId=" + fs.getDocId() + "\"><b>" + fs.getFileName() + "</b></a>"); |
| 218 | |
} |
| 219 | |
else{ |
| 220 | 0 | fileNameLabel = new HTML("<b>" + fs.getFileName() + "</b>"); |
| 221 | |
} |
| 222 | |
|
| 223 | 0 | fileProgressTable.setWidget(currentFile, 0, fileNameLabel); |
| 224 | |
|
| 225 | |
|
| 226 | 0 | Long curProgress = (fs.getProgress())/1024; |
| 227 | 0 | String curProgressString = ""; |
| 228 | 0 | if(curProgress < 1024){ |
| 229 | 0 | curProgressString = nf.format(curProgress) + "kb"; |
| 230 | |
} |
| 231 | |
else{ |
| 232 | 0 | curProgressString = nf.format(curProgress/1024) + "mb"; |
| 233 | |
} |
| 234 | 0 | fileProgressTable.setWidget(currentFile, 1, new KSLabel(curProgressString)); |
| 235 | |
|
| 236 | |
|
| 237 | 0 | String statusString = ""; |
| 238 | 0 | switch(fs.getStatus()){ |
| 239 | |
case ERROR: |
| 240 | 0 | statusString = "Error!"; |
| 241 | 0 | break; |
| 242 | |
case COMMIT_FINISHED: |
| 243 | 0 | statusString = "Finished"; |
| 244 | 0 | break; |
| 245 | |
case FILE_ERROR: |
| 246 | |
|
| 247 | 0 | break; |
| 248 | |
case IN_PROGRESS: |
| 249 | 0 | statusString = "Uploading..."; |
| 250 | 0 | break; |
| 251 | |
case UPLOAD_FINISHED: |
| 252 | 0 | statusString = "Processing..."; |
| 253 | |
break; |
| 254 | |
} |
| 255 | 0 | fileProgressTable.setWidget(currentFile, 2, new KSLabel(statusString)); |
| 256 | |
|
| 257 | 0 | } |
| 258 | |
|
| 259 | |
|
| 260 | |
}); |
| 261 | 0 | } |
| 262 | |
}; |
| 263 | 0 | progressTimer.scheduleRepeating(POLL_INTERVAL); |
| 264 | 0 | } |
| 265 | |
}); |
| 266 | |
} |
| 267 | 0 | } |
| 268 | |
}); |
| 269 | |
|
| 270 | |
public DocumentTool(String refObjectTypeKey, Enum<?> viewEnum, String viewName) { |
| 271 | 0 | super(viewEnum, viewName); |
| 272 | 0 | this.refObjectTypeKey = refObjectTypeKey; |
| 273 | 0 | } |
| 274 | |
|
| 275 | |
protected void isAuthorizedUploadDocuments() { |
| 276 | 0 | documentServiceAsync.isAuthorizedUploadDocuments(referenceId, referenceTypeKey, new KSAsyncCallback<Boolean>() { |
| 277 | |
|
| 278 | |
@Override |
| 279 | |
public void handleFailure(Throwable caught) { |
| 280 | 0 | GWT.log("Error checking permission for adding comments: ", caught); |
| 281 | 0 | throw new RuntimeException("Error checking Permissions: ", caught); |
| 282 | |
} |
| 283 | |
|
| 284 | |
@Override |
| 285 | |
public void onSuccess(Boolean result) { |
| 286 | 0 | GWT.log("User is " + ((result) ? "" : "not ") + "authorized to add comment.", null); |
| 287 | 0 | if(referenceId != null && !(referenceId.isEmpty())){ |
| 288 | |
|
| 289 | 0 | processUi(result); |
| 290 | |
} |
| 291 | |
else{ |
| 292 | 0 | saveWarning.setVisible(true); |
| 293 | 0 | buttonPanel.setVisible(false); |
| 294 | 0 | documentList.setVisible(false); |
| 295 | |
|
| 296 | |
} |
| 297 | 0 | } |
| 298 | |
|
| 299 | |
}); |
| 300 | 0 | } |
| 301 | |
|
| 302 | |
protected void processUi(Boolean result){ |
| 303 | 0 | saveWarning.setVisible(false); |
| 304 | 0 | buttonPanel.setVisible(result); |
| 305 | 0 | documentList.setVisible(true); |
| 306 | 0 | refreshDocuments(); |
| 307 | 0 | } |
| 308 | |
|
| 309 | |
private Metadata getMetaData(String fieldKey) { |
| 310 | 0 | return modelDefinition.getMetadata(QueryPath.concat(fieldKey)); |
| 311 | |
} |
| 312 | |
|
| 313 | |
protected String getLabel(String labelKey) { |
| 314 | |
|
| 315 | |
|
| 316 | 0 | return labelKey; |
| 317 | |
} |
| 318 | |
|
| 319 | |
private MultiplicityConfiguration setupMultiplicityConfig( MultiplicityConfiguration.MultiplicityType multiplicityType |
| 320 | |
, MultiplicityConfiguration.StyleType styleType |
| 321 | |
, String path, String addItemlabelMessageKey |
| 322 | |
, String itemLabelMessageKey |
| 323 | |
, Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition |
| 324 | |
, List<String> deletionParentKeys){ |
| 325 | 0 | QueryPath parentPath = QueryPath.concat(path); |
| 326 | 0 | MultiplicityConfiguration config = new MultiplicityConfiguration(multiplicityType, styleType, getMetaData(parentPath.toString())); |
| 327 | 0 | FieldDescriptor parentFd = buildMuliplicityParentFieldDescriptor(path, null, null); |
| 328 | |
|
| 329 | 0 | MultiplicityFieldConfiguration fc = buildMultiplicityFD("fieldKey", "", parentPath.toString()); |
| 330 | 0 | MultiplicityFieldWidgetInitializer fieldWidgetInitializer = new MultiplicityFieldWidgetInitializer() { |
| 331 | |
|
| 332 | |
@Override |
| 333 | |
public ModelWidgetBinding getModelWidgetBindingInstance() { |
| 334 | |
|
| 335 | 0 | return new ModelWidgetBinding<DocumentForm>() { |
| 336 | |
|
| 337 | |
public void setModelValue(DocumentForm widget, DataModel model, String path) { |
| 338 | |
|
| 339 | 0 | } |
| 340 | |
public void setWidgetValue(DocumentForm widget, DataModel model, String path){ |
| 341 | |
|
| 342 | |
|
| 343 | 0 | } |
| 344 | |
}; |
| 345 | |
} |
| 346 | |
|
| 347 | |
@Override |
| 348 | |
public Widget getNewWidget() { |
| 349 | |
|
| 350 | 0 | return new DocumentForm(); |
| 351 | |
} |
| 352 | |
}; |
| 353 | |
|
| 354 | 0 | ConstraintMetadata min1 = new ConstraintMetadata(); |
| 355 | 0 | Metadata metadata = new Metadata(); |
| 356 | |
|
| 357 | 0 | config.setAddItemLabel(getLabel(addItemlabelMessageKey)); |
| 358 | 0 | config.setItemLabel(getLabel(itemLabelMessageKey)); |
| 359 | 0 | config.setUpdateable(true); |
| 360 | 0 | config.setParent(parentFd); |
| 361 | |
|
| 362 | 0 | fc.setFieldWidgetInitializer(fieldWidgetInitializer); |
| 363 | |
|
| 364 | |
|
| 365 | 0 | min1.setMinOccurs(1); |
| 366 | 0 | metadata.getConstraints().add(min1); |
| 367 | |
|
| 368 | 0 | config.setMetaData(metadata); |
| 369 | 0 | config.addFieldConfiguration(fc); |
| 370 | 0 | config.nextLine(); |
| 371 | |
|
| 372 | 0 | return config; |
| 373 | |
} |
| 374 | |
|
| 375 | |
private FieldDescriptor buildMuliplicityParentFieldDescriptor(String fieldKey, String messageKey, String parentPath) { |
| 376 | 0 | QueryPath path = QueryPath.concat(parentPath, fieldKey); |
| 377 | 0 | Metadata meta = modelDefinition.getMetadata(path); |
| 378 | 0 | FieldDescriptor fd = new FieldDescriptor(path.toString(), generateMessageInfo(messageKey), meta); |
| 379 | 0 | return fd; |
| 380 | |
} |
| 381 | |
|
| 382 | |
private MultiplicityFieldConfiguration buildMultiplicityFD( |
| 383 | |
String fieldKey, String labelKey, String parentPath) { |
| 384 | |
|
| 385 | 0 | QueryPath fieldPath = QueryPath.concat(parentPath, QueryPath.getWildCard(), fieldKey); |
| 386 | 0 | Metadata meta = modelDefinition.getMetadata(fieldPath); |
| 387 | |
|
| 388 | 0 | MultiplicityFieldConfiguration fd = new MultiplicityFieldConfiguration( |
| 389 | |
fieldPath.toString(), generateMessageInfo(labelKey), meta, null); |
| 390 | |
|
| 391 | |
|
| 392 | 0 | return fd; |
| 393 | |
|
| 394 | |
} |
| 395 | |
|
| 396 | |
protected MessageKeyInfo generateMessageInfo(String labelKey) { |
| 397 | 0 | return new MessageKeyInfo("groupName", "type", "state", labelKey); |
| 398 | |
} |
| 399 | |
|
| 400 | |
private Widget createUploadForm() { |
| 401 | 0 | final VerticalSectionView verticalSectionView= new VerticalSectionView(this.getViewEnum(), this.getName(), this.getController().getDefaultModelId()); |
| 402 | 0 | MultiplicitySection ms= new MultiplicitySection(setupMultiplicityConfig( MultiplicityConfiguration.MultiplicityType.GROUP |
| 403 | |
, MultiplicityConfiguration.StyleType.TOP_LEVEL_GROUP |
| 404 | |
, "path", "Include More Files", "File", null, null)); |
| 405 | |
|
| 406 | 0 | verticalSectionView.addSection(ms); |
| 407 | |
|
| 408 | |
try { |
| 409 | |
|
| 410 | 0 | documentServiceAsync.getDocumentTypes(new KSAsyncCallback<List<DocumentTypeInfo>>(){ |
| 411 | |
|
| 412 | |
@Override |
| 413 | |
public void onSuccess(List<DocumentTypeInfo> supportedDocumentTypeInfoResults){ |
| 414 | |
String acceptableDocumentTypesString; |
| 415 | 0 | String maxFileSizeString= "10000000"; |
| 416 | 0 | int maxFileSizeInt= Integer.parseInt(maxFileSizeString)/1048576; |
| 417 | |
|
| 418 | 0 | if(supportedDocumentTypeInfoResults.isEmpty()){ |
| 419 | |
|
| 420 | 0 | acceptableDocumentTypesString= "Sorry, no documents supported for upload now!"; |
| 421 | |
|
| 422 | |
}else{ |
| 423 | |
|
| 424 | 0 | acceptableDocumentTypesString= "." + supportedDocumentTypeInfoResults.get(0).getName(); |
| 425 | 0 | for(int i= 1; i < supportedDocumentTypeInfoResults.size(); i++){ |
| 426 | |
|
| 427 | 0 | acceptableDocumentTypesString+= ", ." + supportedDocumentTypeInfoResults.get(i).getName(); |
| 428 | |
} |
| 429 | |
} |
| 430 | |
|
| 431 | 0 | if(verticalSectionView instanceof SectionView){ |
| 432 | |
|
| 433 | 0 | ((SectionView) verticalSectionView).setInstructions( "Multiple supporting documents associated with this course can be uploaded.<br>" |
| 434 | |
+ " <b>Acceptable file types:</b> " + "<i>" + acceptableDocumentTypesString + "</i><br>" |
| 435 | |
+ " <b>Max file size:</b> " + "<i>~" + maxFileSizeInt + "MB </i>"); |
| 436 | |
} |
| 437 | 0 | } |
| 438 | |
}); |
| 439 | |
|
| 440 | 0 | } catch (Exception e) { |
| 441 | |
|
| 442 | 0 | throw new RuntimeException(e); |
| 443 | 0 | } |
| 444 | |
|
| 445 | 0 | verticalSectionView.getLayout().setWidth("700"); |
| 446 | |
|
| 447 | 0 | return verticalSectionView; |
| 448 | |
} |
| 449 | |
|
| 450 | |
@Override |
| 451 | |
protected Widget createWidget() { |
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | 0 | layout.add(saveWarning); |
| 460 | 0 | saveWarning.setVisible(false); |
| 461 | 0 | buttonPanel.setButtonText(OkEnum.Ok, "Upload"); |
| 462 | 0 | buttonPanel.getButton(OkEnum.Ok).setStyleName(ButtonStyle.SECONDARY.getStyle()); |
| 463 | |
|
| 464 | 0 | uploadList.add(createUploadForm()); |
| 465 | 0 | form.setWidget(uploadList); |
| 466 | 0 | form.setMethod(FormPanel.METHOD_POST); |
| 467 | 0 | form.setEncoding(FormPanel.ENCODING_MULTIPART); |
| 468 | |
|
| 469 | 0 | buttonPanel.setContent(form); |
| 470 | 0 | if (showAllLink != null) { |
| 471 | 0 | layout.add(showAllLink); |
| 472 | |
} |
| 473 | 0 | layout.add(buttonPanel); |
| 474 | 0 | layout.add(documentList); |
| 475 | 0 | documentList.setVisible(false); |
| 476 | 0 | buttonPanel.setVisible(false); |
| 477 | |
|
| 478 | 0 | SectionTitle sectionTitle = SectionTitle.generateH2Title("Upload Status"); |
| 479 | 0 | progressWindow.setNonCaptionHeader(sectionTitle); |
| 480 | 0 | progressPanel.add(progressLabel); |
| 481 | 0 | progressPanel.add(progressBar); |
| 482 | 0 | progressPanel.add(fileProgressTable); |
| 483 | 0 | progressBar.setWidth("400px"); |
| 484 | 0 | progressBar.setTextFormatter(new TextFormatter() { |
| 485 | |
|
| 486 | |
@Override |
| 487 | |
protected String getText(ProgressBar bar, double curProgress) { |
| 488 | |
String result; |
| 489 | 0 | NumberFormat nf = NumberFormat.getFormat("#.##"); |
| 490 | 0 | if (curProgress == bar.getMaxProgress()) { |
| 491 | 0 | result = "Total Uploaded: " + nf.format(curProgress) + "kb"; |
| 492 | 0 | } else if (curProgress == 0 || bar.getMaxProgress() == 0) { |
| 493 | 0 | result = ""; |
| 494 | |
} else { |
| 495 | |
String curProgressString; |
| 496 | |
String maxProgressString; |
| 497 | |
|
| 498 | 0 | if (curProgress < 1024) { |
| 499 | 0 | curProgressString = nf.format(curProgress) + "kb"; |
| 500 | |
} else { |
| 501 | 0 | curProgressString = nf.format(curProgress / 1024) + "mb"; |
| 502 | |
} |
| 503 | |
|
| 504 | 0 | if (bar.getMaxProgress() < 1024) { |
| 505 | 0 | maxProgressString = nf.format(bar.getMaxProgress()) + "kb"; |
| 506 | |
} else { |
| 507 | 0 | maxProgressString = nf.format((bar.getMaxProgress()) / 1024) + "mb"; |
| 508 | |
} |
| 509 | 0 | result = curProgressString + " out of " + maxProgressString; |
| 510 | |
} |
| 511 | 0 | return result; |
| 512 | |
} |
| 513 | |
}); |
| 514 | 0 | progressBar.setHeight("30px"); |
| 515 | 0 | progressPanel.add(progressButtons); |
| 516 | 0 | progressPanel.setWidth("500px"); |
| 517 | 0 | progressWindow.setWidget(progressPanel); |
| 518 | 0 | progressWindow.setSize(520, 270); |
| 519 | |
|
| 520 | 0 | return layout; |
| 521 | |
} |
| 522 | |
|
| 523 | |
private void resetUploadFormPanel() { |
| 524 | 0 | uploadList.clear(); |
| 525 | 0 | uploadList.add(createUploadForm()); |
| 526 | 0 | } |
| 527 | |
|
| 528 | |
private static class DocumentForm extends Composite{ |
| 529 | 0 | private KSLabel file = new KSLabel("* File Location"); |
| 530 | 0 | private KSLabel description = new KSLabel("Description"); |
| 531 | 0 | private FileUpload upload = new FileUpload(); |
| 532 | 0 | private KSTextArea documentDescription = new KSTextArea(); |
| 533 | 0 | private FlexTable tableLayout = new FlexTable(); |
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | 0 | public DocumentForm(){ |
| 539 | 0 | tableLayout.setWidget(0, 0, file); |
| 540 | 0 | tableLayout.setWidget(0, 1, upload); |
| 541 | 0 | upload.setName("uploadFile"); |
| 542 | 0 | tableLayout.setWidget(1, 0, description); |
| 543 | 0 | tableLayout.setWidget(1, 1, documentDescription); |
| 544 | 0 | documentDescription.setName("documentDescription"); |
| 545 | 0 | this.initWidget(tableLayout); |
| 546 | 0 | } |
| 547 | |
} |
| 548 | |
|
| 549 | |
public String getReferenceId() { |
| 550 | 0 | return referenceId; |
| 551 | |
} |
| 552 | |
|
| 553 | |
public void setReferenceId(String referenceId) { |
| 554 | 0 | this.referenceId = referenceId; |
| 555 | 0 | } |
| 556 | |
|
| 557 | |
public String getReferenceTypeKey() { |
| 558 | 0 | return referenceTypeKey; |
| 559 | |
} |
| 560 | |
|
| 561 | |
public void setReferenceTypeKey(String referenceTypeKey) { |
| 562 | 0 | this.referenceTypeKey = referenceTypeKey; |
| 563 | 0 | } |
| 564 | |
|
| 565 | |
public String getReferenceType() { |
| 566 | 0 | return referenceType; |
| 567 | |
} |
| 568 | |
|
| 569 | |
public void setReferenceType(String referenceType) { |
| 570 | 0 | this.referenceType = referenceType; |
| 571 | 0 | } |
| 572 | |
|
| 573 | |
public String getReferenceState() { |
| 574 | 0 | return referenceState; |
| 575 | |
} |
| 576 | |
|
| 577 | |
public void setReferenceState(String referenceState) { |
| 578 | 0 | this.referenceState = referenceState; |
| 579 | 0 | } |
| 580 | |
|
| 581 | |
@Override |
| 582 | |
public void setVisible(boolean visible) { |
| 583 | 0 | super.setVisible(visible); |
| 584 | 0 | if (showAllLink == null){ |
| 585 | 0 | isAuthorizedUploadDocuments(); |
| 586 | |
} |
| 587 | 0 | } |
| 588 | |
|
| 589 | |
private void refreshDocuments(){ |
| 590 | 0 | documentList.clear(); |
| 591 | 0 | if(referenceId != null && !(referenceId.isEmpty())){ |
| 592 | 0 | documentList.add(loadingDocuments); |
| 593 | |
try { |
| 594 | 0 | documentServiceAsync.getRefDocIdsForRef(refObjectTypeKey, referenceId, new KSAsyncCallback<List<RefDocRelationInfo>>(){ |
| 595 | |
|
| 596 | |
@Override |
| 597 | |
public void handleFailure(Throwable caught) { |
| 598 | 0 | GWT.log("getRefDocIdsForRef failed", caught); |
| 599 | 0 | documentList.remove(loadingDocuments); |
| 600 | |
|
| 601 | 0 | } |
| 602 | |
|
| 603 | |
@Override |
| 604 | |
public void onSuccess(List<RefDocRelationInfo> result) { |
| 605 | 0 | documentList.clear(); |
| 606 | 0 | if(result != null && !(result.isEmpty())){ |
| 607 | 0 | documentList.add(new DocumentList(refObjectTypeKey, result, deleteCallback)); |
| 608 | |
} |
| 609 | 0 | documentList.remove(loadingDocuments); |
| 610 | 0 | } |
| 611 | |
}); |
| 612 | 0 | } catch (Exception e) { |
| 613 | 0 | GWT.log("getRefDocIdsForRef failed", e); |
| 614 | 0 | } |
| 615 | |
} |
| 616 | 0 | } |
| 617 | |
|
| 618 | |
@Override |
| 619 | |
public Image getImage() { |
| 620 | 0 | return Theme.INSTANCE.getCommonImages().getDocumentIcon(); |
| 621 | |
} |
| 622 | |
|
| 623 | |
public DataModelDefinition getModelDefinition() { |
| 624 | 0 | return modelDefinition; |
| 625 | |
} |
| 626 | |
|
| 627 | |
public void setModelDefinition(DataModelDefinition modelDefinition) { |
| 628 | 0 | this.modelDefinition = modelDefinition; |
| 629 | 0 | } |
| 630 | |
|
| 631 | |
public void setShowAllLink(Composite showAllLink) { |
| 632 | 0 | this.showAllLink = showAllLink; |
| 633 | 0 | } |
| 634 | |
|
| 635 | |
public void showShowAllLink(boolean show) { |
| 636 | 0 | this.showAllLink.setVisible(show); |
| 637 | 0 | if (show) { |
| 638 | 0 | saveWarning.setVisible(false); |
| 639 | 0 | buttonPanel.setVisible(false); |
| 640 | 0 | documentList.setVisible(false); |
| 641 | |
} else { |
| 642 | 0 | isAuthorizedUploadDocuments(); |
| 643 | |
} |
| 644 | 0 | } |
| 645 | |
|
| 646 | |
@Override |
| 647 | |
public void showExport(boolean show) { |
| 648 | |
|
| 649 | |
|
| 650 | 0 | } |
| 651 | |
|
| 652 | |
} |