Skip to content

Commit

Permalink
disable upload button when user clear upload file
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Sep 23, 2015
1 parent 891b5db commit f2cca68
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public void glossaryFileUploaded(FileUploadEvent event) throws IOException {
glossaryFileUpload.setFileName(uploadedFile.getName());
}

public void glossaryFileCleared() {
glossaryFileUpload = new GlossaryFileUploadHelper();
}

/**
* Helper class to upload glossary files.
*/
Expand Down
14 changes: 11 additions & 3 deletions zanata-war/src/main/java/org/zanata/action/VersionHomeAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ public String sourceExtensionOf(String docPath, String docName) {
public String translationExtensionOf(String docPath, String docName) {
return "."
+ translationFileServiceImpl.getTranslationFileExtension(
projectSlug,
versionSlug, docPath, docName);
projectSlug,
versionSlug, docPath, docName);
}

public boolean hasOriginal(String docPath, String docName) {
Expand Down Expand Up @@ -973,7 +973,7 @@ public boolean needDocumentTypeSelection(String fileName) {

public List<DocumentType> getDocumentTypes(String fileName) {
return Lists.newArrayList(
translationFileServiceImpl.getDocumentTypes(fileName));
translationFileServiceImpl.getDocumentTypes(fileName));
}

public void setDefaultTranslationDocType(String fileName) {
Expand Down Expand Up @@ -1067,12 +1067,20 @@ public void sourceFileUploaded(FileUploadEvent event) throws IOException {

}

public void sourceFileCleared() {
sourceFileUpload = new SourceFileUploadHelper();
}

public void transFileUploaded(FileUploadEvent event) throws IOException {
UploadedFile uploadedFile = event.getUploadedFile();
translationFileUpload.setFileName(uploadedFile.getName());
translationFileUpload.setFileContents(uploadedFile.getInputStream());
}

public void transFileCleared() {
translationFileUpload = new TranslationFileUploadHelper();
}

private class DocumentFilter extends InMemoryListFilter<HDocument> {
private DocumentDAO documentDAO =
ServiceLocator.instance().getInstance(DocumentDAO.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
class="modal" id="glossaryUploadDialog" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
Expand Down Expand Up @@ -106,12 +107,15 @@
<div class="form__item txt--understated" id="message">
<span>#{msgs['jsf.Glossary.supportedFileFormat']}</span>
</div>

<a4j:jsFunction name="clearSelection" action="#{glossaryAction.glossaryFileCleared}"/>
<div class="form__item">
<rich:fileUpload id="upload-file"
fileUploadListener="#{glossaryAction.glossaryFileUploaded}"
onfilesubmit="onGlossaryFileSubmitted()"
addControlLabel="Select file..." clearAllLabel="Clear all" clearLabel="Clear"
uploadLabel="upload" immediateUpload="true" maxFilesQuantity="1"
onclear="clearSelection();enableUploadGlossaryButton(false);"
listHeight="100"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@
<div class="l--pad-top-quarter form__item txt--understated" id="uploadPanelMsg"></div>

<div class="form__item">
<a4j:jsFunction name="clearTransFileUpload" action="#{versionHomeAction.transFileCleared}"/>
<rich:fileUpload id="upload-file"
fileUploadListener="#{versionHomeAction.transFileUploaded}"
onfilesubmit="onTranslationFileSubmitted()"
addControlLabel="Select file..." clearAllLabel="Clear all" clearLabel="Clear"
uploadLabel="upload" immediateUpload="true" maxFilesQuantity="1"
listHeight="100"
onclear="clearTransFileUpload();setUploadTranslationDocButtonEnabled(false);"
/>

</div>
Expand Down
7 changes: 6 additions & 1 deletion zanata-war/src/main/webapp/iteration/view.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
.
show();
checkIfFileSelected();

setUploadSourceButtonEnabled(false);
}

function hideUploadSourcePanel() {
Expand Down Expand Up @@ -454,11 +456,14 @@
<h:outputText id="uploadSourcePanelHeader"/>
</f:facet>
<h:form id="uploadSrcForm" >
<a4j:jsFunction name="clearSourceUpload" action="#{versionHomeAction.sourceFileCleared}"/>

<rich:fileUpload
fileUploadListener="#{versionHomeAction.sourceFileUploaded}"
addControlLabel="Select file..." clearAllLabel="Clear all" clearLabel="Clear"
uploadLabel="upload" immediateUpload="true" maxFilesQuantity="1" listHeight="60"

onclear="clearSourceUpload();setUploadSourceButtonEnabled(false);"
onfilesubmit="setUploadSourceButtonEnabled(true);"
/>
<h:inputHidden id="uploadSourceDocId"
value="#{versionHomeAction.sourceFileUpload.docId}"/>
Expand Down

0 comments on commit f2cca68

Please sign in to comment.