<u:FileUploader name="uploadFile" change="onChangeImage" id="fileUploader" class="hiddenControls" fileType="jpg,png,jpeg" sendXHR="true"></u:FileUploader>
<mvc:View controllerName="com.sap.image-preview-with-file-uploader.controller.App" xmlns:mvc="sap.ui.core.mvc" displayBlock="true"
xmlns:u="sap.ui.unified" xmlns="sap.m">
<Label labelFor="fileUploader-fu" id="fileUploader-label" class="hiddenControls"></Label>
<GenericTile class="imagePreview" scope="Display" press="onEditImage" id="image"></GenericTile>
<VBox>
<items>
<u:FileUploader name="uploadFile" change="onChangeImage" id="fileUploader" fileType="jpg,png,jpeg" sendXHR="true"></u:FileUploader>
<Label labelFor="fileUploader-fu" id="fileUploader-label"></Label>
<GenericTile class="imagePreview" scope="Display" press="onEditImage" id="image"></GenericTile>
</items>
</VBox>
onEditImage: function (oEvent) {
this.getView().byId("fileUploader-label").getDomRef().click();
}
onChangeImage: function (oEvent) {
if (oEvent.getSource().oFileUpload.files.length > 0) {
var file = oEvent.getSource().oFileUpload.files[0];
var path = URL.createObjectURL(file);
this.getView().byId("image").setBackgroundImage(path);
}
}
.hiddenControls {
height: 0px;
overflow: hidden;
}
<GenericTile class="imagePreview" press="onEditImage" id="image" scope="Actions" subheader="No Image Selected">
<tileContent>
<TileContent id="iconContent">
<content>
<sap.ui.core:Icon xmlns:sap.ui.core="sap.ui.core" src="sap-icon://add" size="2em" id="actionIcon" class="actionIcon"/>
</content>
</TileContent>
</tileContent>
</GenericTile>
onChangeImage: function (oEvent) {
if (oEvent.getSource().oFileUpload.files.length > 0) {
var file = oEvent.getSource().oFileUpload.files[0];
var path = URL.createObjectURL(file);
this.getView().byId("image").setBackgroundImage(path);
this.getView().byId("image").setSubheader("");
this.getView().byId("actionIcon").setSrc("sap-icon://edit");
}
}
onEditImage: function (oEvent) {
if (oEvent.getParameter("action") === "Press") {
this.getView().byId("fileUploader-label").getDomRef().click();
} else if (oEvent.getParameter("action") === "Remove") {
this.getView().byId("actionIcon").setSrc("sap-icon://add");
this.getView().byId("image").setSubheader("No Image Selected");
this.getView().byId("image").setBackgroundImage("");
}
},
.imagePreview {
text-align: center;
color: #0854a0;
}
.actionIcon {
opacity: 0;
}
.imagePreview:hover .actionIcon {
opacity: 1;
transition: all 0.1s ease-in;
z-index: 9999;
transform: scale(1.2);
}
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns:u="sap.ui.unified" xmlns="sap.m"
controllerName="com.sap.image-preview-with-file-uploader.controller.App" displayBlock="true">
<Shell id="shell">
<App id="app">
<pages>
<Page id="page" title="{i18n>title}">
<content>
<VBox>
<items>
<u:FileUploader name="uploadFile" change="onChangeImage" id="fileUploader" class="hiddenControls" fileType="jpg,png,jpeg" sendXHR="true"/>
<Label labelFor="fileUploader-fu" id="fileUploader-label" class="hiddenControls"/>
<GenericTile class="imagePreview" press="onEditImage" id="image" scope="Actions" subheader="No Image Selected">
<tileContent>
<TileContent id="iconContent">
<content>
<sap.ui.core:Icon xmlns:sap.ui.core="sap.ui.core" src="sap-icon://add" size="2em" id="actionIcon" class="actionIcon"/>
</content>
</TileContent>
</tileContent>
</GenericTile>
</items>
</VBox>
</content>
</Page>
</pages>
</App>
</Shell>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("com.sap.image-preview-with-file-uploader.controller.App", {
onInit: function () {
},
/*
* function called
* when tile clicked
*/
onEditImage: function (oEvent) {
if (oEvent.getParameter("action") === "Press") {
this.getView().byId("fileUploader-label").getDomRef().click();
} else if (oEvent.getParameter("action") === "Remove") {
this.getView().byId("actionIcon").setSrc("sap-icon://add");
this.getView().byId("image").setSubheader("No Image Selected");
this.getView().byId("image").setBackgroundImage("");
}
},
onChangeImage: function (oEvent) {
if (oEvent.getSource().oFileUpload.files.length > 0) {
var file = oEvent.getSource().oFileUpload.files[0];
var path = URL.createObjectURL(file);
this.getView().byId("image").setBackgroundImage(path);
this.getView().byId("image").setSubheader("");
this.getView().byId("actionIcon").setSrc("sap-icon://edit");
}
}
});
});
.hiddenControls {
height: 0px;
overflow: hidden;
}
.imagePreview {
text-align: center;
color: #0854a0;
}
.actionIcon {
opacity: 0;
}
.imagePreview:hover .actionIcon {
opacity: 1;
transition: all 0.1s ease-in;
z-index: 9999;
transform: scale(1.2);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
10 | |
9 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 | |
4 |