Commit d6d09e1e authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Implement accept attribute on file inputs

Change-Id: Id9052e79785ed1a53f5654970a46c7002df350de
parent 88b9c681
// -*- mode: java; c-basic-offset: 2; -*- // -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2016-2017 MIT, All rights reserved // Copyright 2016-2020 MIT, All rights reserved
// Released under the Apache License, Version 2.0 // Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
...@@ -27,6 +27,7 @@ import com.google.gwt.user.client.Window; ...@@ -27,6 +27,7 @@ import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.VerticalPanel;
import java.util.Collections;
import static com.google.appinventor.client.Ode.MESSAGES; import static com.google.appinventor.client.Ode.MESSAGES;
...@@ -91,7 +92,8 @@ public class YoungAndroidGeoJSONPropertyEditor extends AdditionalChoicePropertyE ...@@ -91,7 +92,8 @@ public class YoungAndroidGeoJSONPropertyEditor extends AdditionalChoicePropertyE
closeAdditionalChoiceDialog(true); closeAdditionalChoiceDialog(true);
} }
}; };
FileUploadWizard uploader = new FileUploadWizard(assetsFolder, callback); FileUploadWizard uploader = new FileUploadWizard(assetsFolder,
Collections.singleton(".geojson"), callback);
uploader.show(); uploader.show();
} }
}); });
......
// -*- mode: java; c-basic-offset: 2; -*- // -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved // Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2015 MIT, All rights reserved // Copyright 2011-2020 MIT, All rights reserved
// Released under the Apache License, Version 2.0 // Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
...@@ -230,6 +230,7 @@ public class ComponentImportWizard extends Wizard { ...@@ -230,6 +230,7 @@ public class ComponentImportWizard extends Wizard {
private FileUpload createFileUpload() { private FileUpload createFileUpload() {
FileUpload upload = new FileUpload(); FileUpload upload = new FileUpload();
upload.setName(ServerLayout.UPLOAD_COMPONENT_ARCHIVE_FORM_ELEMENT); upload.setName(ServerLayout.UPLOAD_COMPONENT_ARCHIVE_FORM_ELEMENT);
upload.getElement().setAttribute("accept", COMPONENT_ARCHIVE_EXTENSION);
return upload; return upload;
} }
......
// -*- mode: java; c-basic-offset: 2; -*- // -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved // Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2015 MIT, All rights reserved // Copyright 2011-2020 MIT, All rights reserved
// Released under the Apache License, Version 2.0 // Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
...@@ -30,6 +30,7 @@ public class ComponentUploadWizard extends Wizard { ...@@ -30,6 +30,7 @@ public class ComponentUploadWizard extends Wizard {
super(MESSAGES.componentUploadWizardCaption(), true, false); super(MESSAGES.componentUploadWizardCaption(), true, false);
final FileUpload uploadWiget = new FileUpload(); final FileUpload uploadWiget = new FileUpload();
uploadWiget.getElement().setAttribute("accept", COMPONENT_ARCHIVE_EXTENSION);
uploadWiget.setName(ServerLayout.UPLOAD_COMPONENT_ARCHIVE_FORM_ELEMENT); uploadWiget.setName(ServerLayout.UPLOAD_COMPONENT_ARCHIVE_FORM_ELEMENT);
VerticalPanel panel = new VerticalPanel(); VerticalPanel panel = new VerticalPanel();
......
// -*- mode: java; c-basic-offset: 2; -*- // -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved // Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved // Copyright 2011-2020 MIT, All rights reserved
// Released under the Apache License, Version 2.0 // Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
...@@ -8,8 +8,6 @@ package com.google.appinventor.client.wizards; ...@@ -8,8 +8,6 @@ package com.google.appinventor.client.wizards;
import static com.google.appinventor.client.Ode.MESSAGES; import static com.google.appinventor.client.Ode.MESSAGES;
import java.io.File;
import com.google.appinventor.client.ErrorReporter; import com.google.appinventor.client.ErrorReporter;
import com.google.appinventor.client.Ode; import com.google.appinventor.client.Ode;
import com.google.appinventor.client.OdeAsyncCallback; import com.google.appinventor.client.OdeAsyncCallback;
...@@ -24,25 +22,17 @@ import com.google.appinventor.shared.rpc.project.ProjectNode; ...@@ -24,25 +22,17 @@ import com.google.appinventor.shared.rpc.project.ProjectNode;
import com.google.appinventor.shared.rpc.project.youngandroid.YoungAndroidAssetNode; import com.google.appinventor.shared.rpc.project.youngandroid.YoungAndroidAssetNode;
import com.google.appinventor.shared.rpc.project.youngandroid.YoungAndroidAssetsFolder; import com.google.appinventor.shared.rpc.project.youngandroid.YoungAndroidAssetsFolder;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FileUpload; import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.DialogBox; import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener; import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment; import java.util.Collection;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
/** /**
...@@ -53,7 +43,7 @@ public class FileUploadWizard extends Wizard { ...@@ -53,7 +43,7 @@ public class FileUploadWizard extends Wizard {
/** /**
* Interface for callback to execute after a file is uploaded. * Interface for callback to execute after a file is uploaded.
*/ */
public static interface FileUploadedCallback { public interface FileUploadedCallback {
/** /**
* Will be invoked after a file is uploaded. * Will be invoked after a file is uploaded.
* *
...@@ -78,12 +68,27 @@ public class FileUploadWizard extends Wizard { ...@@ -78,12 +68,27 @@ public class FileUploadWizard extends Wizard {
* @param folderNode the upload destination folder * @param folderNode the upload destination folder
* @param fileUploadedCallback callback to be executed after upload * @param fileUploadedCallback callback to be executed after upload
*/ */
public FileUploadWizard(FolderNode folderNode, FileUploadedCallback fileUploadedCallback) {
this(folderNode, null, fileUploadedCallback);
}
/**
* Creates a new file upload wizard.
*
* @param folderNode the upload destination folder
* @param acceptableTypes a collection of acceptable types, or null.
* @param fileUploadedCallback callback to be executed after upload
*/
public FileUploadWizard(final FolderNode folderNode, public FileUploadWizard(final FolderNode folderNode,
final Collection<String> acceptableTypes,
final FileUploadedCallback fileUploadedCallback) { final FileUploadedCallback fileUploadedCallback) {
super(MESSAGES.fileUploadWizardCaption(), true, false); super(MESSAGES.fileUploadWizardCaption(), true, false);
// Initialize UI // Initialize UI
final FileUpload upload = new FileUpload(); final FileUpload upload = new FileUpload();
if (acceptableTypes != null) {
upload.getElement().setAttribute("accept", String.join(",", acceptableTypes));
}
upload.setName(ServerLayout.UPLOAD_FILE_FORM_ELEMENT); upload.setName(ServerLayout.UPLOAD_FILE_FORM_ELEMENT);
setStylePrimaryName("ode-DialogBox"); setStylePrimaryName("ode-DialogBox");
VerticalPanel panel = new VerticalPanel(); VerticalPanel panel = new VerticalPanel();
...@@ -100,11 +105,11 @@ public class FileUploadWizard extends Wizard { ...@@ -100,11 +105,11 @@ public class FileUploadWizard extends Wizard {
final String filename = makeValidFilename(uploadFilename); final String filename = makeValidFilename(uploadFilename);
if(!TextValidators.isValidCharFilename(filename)){ if(!TextValidators.isValidCharFilename(filename)){
createErrorDialog(MESSAGES.malformedFilenameTitle(), MESSAGES.malformedFilename(), createErrorDialog(MESSAGES.malformedFilenameTitle(), MESSAGES.malformedFilename(),
Error.NOFILESELECETED, folderNode, fileUploadedCallback); Error.NOFILESELECETED, folderNode, acceptableTypes, fileUploadedCallback);
return; return;
} else if (!TextValidators.isValidLengthFilename(filename)){ } else if (!TextValidators.isValidLengthFilename(filename)){
createErrorDialog(MESSAGES.filenameBadSizeTitle(), MESSAGES.filenameBadSize(), createErrorDialog(MESSAGES.filenameBadSizeTitle(), MESSAGES.filenameBadSize(),
Error.FILENAMEBADSIZE, folderNode, fileUploadedCallback); Error.FILENAMEBADSIZE, folderNode, acceptableTypes, fileUploadedCallback);
return; return;
} }
int nameLength = uploadFilename.length(); int nameLength = uploadFilename.length();
...@@ -112,7 +117,7 @@ public class FileUploadWizard extends Wizard { ...@@ -112,7 +117,7 @@ public class FileUploadWizard extends Wizard {
if (".aia".equals(fileEnd.toLowerCase())) { if (".aia".equals(fileEnd.toLowerCase())) {
createErrorDialog(MESSAGES.aiaMediaAssetTitle(), MESSAGES.aiaMediaAsset(), createErrorDialog(MESSAGES.aiaMediaAssetTitle(), MESSAGES.aiaMediaAsset(),
Error.AIAMEDIAASSET, folderNode, fileUploadedCallback); Error.AIAMEDIAASSET, folderNode, acceptableTypes, fileUploadedCallback);
return; return;
} }
String fn = conflictingExistingFile(folderNode, filename); String fn = conflictingExistingFile(folderNode, filename);
...@@ -172,7 +177,7 @@ public class FileUploadWizard extends Wizard { ...@@ -172,7 +177,7 @@ public class FileUploadWizard extends Wizard {
}); });
} else { } else {
createErrorDialog(MESSAGES.noFileSelectedTitle(), MESSAGES.noFileSelected(), createErrorDialog(MESSAGES.noFileSelectedTitle(), MESSAGES.noFileSelected(),
Error.NOFILESELECETED, folderNode, fileUploadedCallback); Error.NOFILESELECETED, folderNode, acceptableTypes, fileUploadedCallback);
} }
} }
}); });
...@@ -244,7 +249,8 @@ public class FileUploadWizard extends Wizard { ...@@ -244,7 +249,8 @@ public class FileUploadWizard extends Wizard {
} }
private void createErrorDialog(String title, String body, Error e, private void createErrorDialog(String title, String body, Error e,
final FolderNode folderNode, final FileUploadedCallback fileUploadedCallback) { final FolderNode folderNode, final Collection<String> acceptableTypes,
final FileUploadedCallback fileUploadedCallback) {
final DialogBox dialogBox = new DialogBox(false,true); final DialogBox dialogBox = new DialogBox(false,true);
HTML message; HTML message;
dialogBox.setStylePrimaryName("ode-DialogBox"); dialogBox.setStylePrimaryName("ode-DialogBox");
...@@ -259,7 +265,7 @@ public class FileUploadWizard extends Wizard { ...@@ -259,7 +265,7 @@ public class FileUploadWizard extends Wizard {
ok.addClickListener(new ClickListener() { ok.addClickListener(new ClickListener() {
public void onClick(Widget sender) { public void onClick(Widget sender) {
dialogBox.hide(); dialogBox.hide();
new FileUploadWizard(folderNode, fileUploadedCallback).show(); new FileUploadWizard(folderNode, acceptableTypes, fileUploadedCallback).show();
} }
}); });
holder.add(ok); holder.add(ok);
......
// -*- mode: java; c-basic-offset: 2; -*- // -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved // Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved // Copyright 2011-2020 MIT, All rights reserved
// Released under the Apache License, Version 2.0 // Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
...@@ -37,6 +37,7 @@ public class KeystoreUploadWizard extends Wizard { ...@@ -37,6 +37,7 @@ public class KeystoreUploadWizard extends Wizard {
// Initialize UI // Initialize UI
final FileUpload upload = new FileUpload(); final FileUpload upload = new FileUpload();
upload.setName(ServerLayout.UPLOAD_USERFILE_FORM_ELEMENT); upload.setName(ServerLayout.UPLOAD_USERFILE_FORM_ELEMENT);
upload.getElement().setAttribute("accept", KEYSTORE_EXTENSION);
setStylePrimaryName("ode-DialogBox"); setStylePrimaryName("ode-DialogBox");
VerticalPanel panel = new VerticalPanel(); VerticalPanel panel = new VerticalPanel();
panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
......
// -*- mode: java; c-basic-offset: 2; -*- // -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved // Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved // Copyright 2011-2020 MIT, All rights reserved
// Released under the Apache License, Version 2.0 // Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
...@@ -39,6 +39,7 @@ public class ProjectUploadWizard extends Wizard { ...@@ -39,6 +39,7 @@ public class ProjectUploadWizard extends Wizard {
// Initialize UI // Initialize UI
final FileUpload upload = new FileUpload(); final FileUpload upload = new FileUpload();
upload.setName(ServerLayout.UPLOAD_PROJECT_ARCHIVE_FORM_ELEMENT); upload.setName(ServerLayout.UPLOAD_PROJECT_ARCHIVE_FORM_ELEMENT);
upload.getElement().setAttribute("accept", PROJECT_ARCHIVE_EXTENSION);
setStylePrimaryName("ode-DialogBox"); setStylePrimaryName("ode-DialogBox");
VerticalPanel panel = new VerticalPanel(); VerticalPanel panel = new VerticalPanel();
panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment