Umožněn upload souborů k požadavkům na služební cesty a k vyúčtování služební cesty.
closes #131Verze_2.0
							parent
							
								
									c6ebf8959b
								
							
						
					
					
						commit
						ecd3cf426b
					
				@ -0,0 +1,72 @@
 | 
				
			|||||||
 | 
					package info.bukova.isspst.ui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import info.bukova.isspst.data.DataModel;
 | 
				
			||||||
 | 
					import info.bukova.isspst.data.FileMetainfo;
 | 
				
			||||||
 | 
					import info.bukova.isspst.storage.DocumentFileStorage;
 | 
				
			||||||
 | 
					import info.bukova.isspst.storage.EntityWithAttachment;
 | 
				
			||||||
 | 
					import org.zkoss.bind.annotation.BindingParam;
 | 
				
			||||||
 | 
					import org.zkoss.bind.annotation.Command;
 | 
				
			||||||
 | 
					import org.zkoss.bind.annotation.ContextParam;
 | 
				
			||||||
 | 
					import org.zkoss.bind.annotation.ContextType;
 | 
				
			||||||
 | 
					import org.zkoss.bind.annotation.Init;
 | 
				
			||||||
 | 
					import org.zkoss.bind.annotation.NotifyChange;
 | 
				
			||||||
 | 
					import org.zkoss.zk.ui.event.UploadEvent;
 | 
				
			||||||
 | 
					import org.zkoss.zk.ui.select.annotation.WireVariable;
 | 
				
			||||||
 | 
					import org.zkoss.zul.Filedownload;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @author Pepa Rokos
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class FormWithUpload<T extends DataModel> extends FormViewModel<T> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private List<FileMetainfo> attachments;
 | 
				
			||||||
 | 
						private List<FileMetainfo> forDelete;
 | 
				
			||||||
 | 
						@WireVariable
 | 
				
			||||||
 | 
						private DocumentFileStorage documentStorage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Init(superclass = true)
 | 
				
			||||||
 | 
						public void initFormWithUpload() {
 | 
				
			||||||
 | 
							if (getDataBean() instanceof EntityWithAttachment) {
 | 
				
			||||||
 | 
								attachments = ((EntityWithAttachment)getDataBean()).getAttachedFiles();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							forDelete = new ArrayList<FileMetainfo>(); // kolekce příloh na smazání v případě uložení záznamu
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Command
 | 
				
			||||||
 | 
						@NotifyChange("attachments")
 | 
				
			||||||
 | 
						public void uploadAttachment(@ContextParam(ContextType.TRIGGER_EVENT) UploadEvent upEvent) {
 | 
				
			||||||
 | 
							FileMetainfo metaInfo = documentStorage.saveAndCreateInfo(upEvent.getMedia().getByteData(),
 | 
				
			||||||
 | 
									upEvent.getMedia().getName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							((EntityWithAttachment)getDataBean()).addAttachment(metaInfo);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Command
 | 
				
			||||||
 | 
						@NotifyChange("attachments")
 | 
				
			||||||
 | 
						public void deleteAttachment(@BindingParam("attachment") FileMetainfo metaInfo) {
 | 
				
			||||||
 | 
							((EntityWithAttachment)getDataBean()).removeAttachment(metaInfo);
 | 
				
			||||||
 | 
							forDelete.add(metaInfo); // smazat až v případě uložení záznamu
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Command
 | 
				
			||||||
 | 
						public void downloadAttachment(@BindingParam("attachment") FileMetainfo metaInfo) {
 | 
				
			||||||
 | 
							Filedownload.save(documentStorage.fileData(metaInfo), metaInfo.getContentType(), metaInfo.getFileName());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public List<FileMetainfo> getAttachments() {
 | 
				
			||||||
 | 
							return attachments;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						protected void doSave() {
 | 
				
			||||||
 | 
							for (FileMetainfo info : forDelete) {
 | 
				
			||||||
 | 
								documentStorage.removeFile(info);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							super.doSave();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					<?page title="${labels.TravelOrdersFormTitle}" contentType="text/html;charset=UTF-8"?>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<zk xmlns="http://www.zkoss.org/2005/zul"
 | 
				
			||||||
 | 
						xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
				
			||||||
 | 
						xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
 | 
				
			||||||
 | 
						<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<vbox>
 | 
				
			||||||
 | 
							<button image="/img/upload-016.png"
 | 
				
			||||||
 | 
									label="Připojit soubor"
 | 
				
			||||||
 | 
									upload="true"
 | 
				
			||||||
 | 
									onUpload="@command('uploadAttachment')"
 | 
				
			||||||
 | 
									sclass="nicebutton" />
 | 
				
			||||||
 | 
							<grid model="@load(vm.attachments)" height="180px">
 | 
				
			||||||
 | 
								<columns>
 | 
				
			||||||
 | 
									<column label="Soubor" width="220px"/>
 | 
				
			||||||
 | 
									<column label="Popis" hflex="max"/>
 | 
				
			||||||
 | 
									<column width="200px"/>
 | 
				
			||||||
 | 
								</columns>
 | 
				
			||||||
 | 
								<rows>
 | 
				
			||||||
 | 
									<template name="model">
 | 
				
			||||||
 | 
										<row>
 | 
				
			||||||
 | 
											<a href="@load('/api/dl/'.concat(each.pathInFilesystem).concat('/').concat(each.fileName))"
 | 
				
			||||||
 | 
											   label="@load(each.fileName)"
 | 
				
			||||||
 | 
											   target="blank"/>
 | 
				
			||||||
 | 
											<textbox value="@bind(each.description)" sclass="grid-textbox-max"/>
 | 
				
			||||||
 | 
											<hbox>
 | 
				
			||||||
 | 
												<button image="/img/delete-016.png" label="Odebrat" onClick="@command('deleteAttachment', attachment=each)" sclass="nicebutton"/>
 | 
				
			||||||
 | 
												<button image="/img/download-016.png" label="Stáhnout" onClick="@command('downloadAttachment', attachment=each)" sclass="nicebutton"/>
 | 
				
			||||||
 | 
											</hbox>
 | 
				
			||||||
 | 
										</row>
 | 
				
			||||||
 | 
									</template>
 | 
				
			||||||
 | 
								</rows>
 | 
				
			||||||
 | 
							</grid>
 | 
				
			||||||
 | 
						</vbox>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</zk>
 | 
				
			||||||
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 789 B  | 
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 734 B  | 
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 197 B  | 
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 650 B  | 
					Loading…
					
					
				
		Reference in New Issue