Commit a473e66b authored by Anastasios Kalogeropoulos's avatar Anastasios Kalogeropoulos
Browse files

delete image if empty in step2 done

parent acd4a83e
......@@ -540,38 +540,69 @@ public class IdeaInputBean implements Serializable {
ThemeDisplay themeDisplay = (ThemeDisplay) FacesContext.getCurrentInstance().getExternalContext()
.getRequestMap().get(WebKeys.THEME_DISPLAY);
IdeasLocalService ideasLocalService = ideasLocalServiceTracker.getService();
File tmpFile = null;
if (this.dataUrl1 != null && !this.dataUrl1.equals("")) {
try {
tmpFile = convertDataUrlToFile(this.dataUrl1);
} catch (IOException e1) {
return;
if(this.dataUrl1.equals("-1")) {
this.titleImgUrl1 = "/";
//delete picture from idea
long pictureId = ideasLocalService.getPictureIdByIdeasRefAndPosition(currentIdeasId, 0);
if(pictureId != 0) {
logger.info("Picture " + Long.toString(pictureId) + " from idea " + currentIdeasId + " deleted");
ideasLocalService.deletePictureById(pictureId);
}
IdeasLocalService ideasLocalService = ideasLocalServiceTracker.getService();
FileEntry createdEntry = null;
if (tmpFile != null && dataUrl1 != null) {
} else {
if (this.dataUrl1 != null && !this.dataUrl1.equals("")) {
try {
createdEntry = saveFile(tmpFile, this.IDEAS_PICTURE_FOLDER, this.IDEAS_PICTURE_QUALIFIER);
} catch (PortalException | IOException e) {
logger.error("Could not upload a picture", e);
tmpFile = convertDataUrlToFile(this.dataUrl1);
} catch (IOException e1) {
return;
}
FileEntry createdEntry = null;
if (tmpFile != null && dataUrl1 != null) {
try {
createdEntry = saveFile(tmpFile, this.IDEAS_PICTURE_FOLDER, this.IDEAS_PICTURE_QUALIFIER);
} catch (PortalException | IOException e) {
logger.error("Could not upload a picture", e);
}
String titleImgRef = getFullyQualifiedUrlForFileEntry(themeDisplay, createdEntry);
titleImgUrl1 = titleImgRef;
long picPrimaryKey = createdEntry.getPrimaryKey();
ideasLocalService.addPictureToExistingIdea(currentIdeasId, picPrimaryKey, titleImgRef,0);
logger.info("Added Picture to Idea with primary key " + currentIdeasId);
}
String titleImgRef = getFullyQualifiedUrlForFileEntry(themeDisplay, createdEntry);
titleImgUrl1 = titleImgRef;
long picPrimaryKey = createdEntry.getPrimaryKey();
ideasLocalService.addPictureToExistingIdea(currentIdeasId, picPrimaryKey, titleImgRef,0);
logger.info("Added Picture to Idea with primary key " + currentIdeasId);
}
}
if(this.dataUrl2 != null && !this.dataUrl2.equals("")){
this.titleImgUrl2 = addAdditionalPicture(this.dataUrl2,themeDisplay,1);
if(this.dataUrl2.equals("-1")) {
this.titleImgUrl2 = "/";
//delete picture from idea
long pictureId = ideasLocalService.getPictureIdByIdeasRefAndPosition(currentIdeasId, 1);
if(pictureId != 0) {
logger.info("Picture " + Long.toString(pictureId) + " from idea " + currentIdeasId + " deleted");
ideasLocalService.deletePictureById(pictureId);
}
}else {
if(this.dataUrl2 != null && !this.dataUrl2.equals("")){
this.titleImgUrl2 = addAdditionalPicture(this.dataUrl2,themeDisplay,1);
}
}
if(this.dataUrl3 != null && !this.dataUrl3.equals("")){
this.titleImgUrl3 = addAdditionalPicture(this.dataUrl3,themeDisplay,2);
if(this.dataUrl3.equals("-1")) {
this.titleImgUrl3 = "/";
//delete picture from idea
long pictureId = ideasLocalService.getPictureIdByIdeasRefAndPosition(currentIdeasId, 2);
if(pictureId != 0) {
logger.info("Picture " + Long.toString(pictureId) + " from idea " + currentIdeasId + " deleted");
ideasLocalService.deletePictureById(pictureId);
}
} else {
if(this.dataUrl3 != null && !this.dataUrl3.equals("")){
this.titleImgUrl3 = addAdditionalPicture(this.dataUrl3,themeDisplay,2);
}
}
RequestContext.getCurrentInstance().update("_JSFIdeaBoard_WAR_JSFIdeaBoard_:mainBodyOverview");
......@@ -1368,7 +1399,7 @@ public class IdeaInputBean implements Serializable {
}
if(this.titleImgUrl1.equals("/") && this.titleImgUrl2.equals("/") && this.titleImgUrl3.equals("/")){
return false;
}
}
return true;
}
......
......@@ -110,7 +110,15 @@ function handleTabChange(index) {
});
}
function isCanvasBlank(canvasElement) {
var blank = document.createElement('canvas');
blank.width = canvasElement.width;
blank.height = canvasElement.height;
return canvasElement.toDataURL() == blank.toDataURL();
}
function handleDragStart(e) {
[].forEach.call(images, function (img) {
img.classList.remove('img_dragging');
......@@ -241,7 +249,11 @@ function handleTabChange(index) {
if (!fabric.Canvas.supports('toDataURL')) {
alert('This browser doesn\'t provide means to serialize canvas to an image');
} else {
document.getElementById("_JSFIdeaBoard_WAR_JSFIdeaBoard_:ideaInputStepTwoFormFooter:imgData1").value = canvas1.toDataURL('png');
if(isCanvasBlank(canvas1)) {
document.getElementById("_JSFIdeaBoard_WAR_JSFIdeaBoard_:ideaInputStepTwoFormFooter:imgData1").value = "-1";
} else {
document.getElementById("_JSFIdeaBoard_WAR_JSFIdeaBoard_:ideaInputStepTwoFormFooter:imgData1").value = canvas1.toDataURL('png');
}
}
};
......@@ -253,7 +265,11 @@ function handleTabChange(index) {
if (!fabric.Canvas.supports('toDataURL')) {
alert('This browser doesn\'t provide means to serialize canvas to an image');
} else {
document.getElementById("_JSFIdeaBoard_WAR_JSFIdeaBoard_:ideaInputStepTwoFormFooter:imgData2").value = canvas2.toDataURL('png');
if(isCanvasBlank(canvas2)) {
document.getElementById("_JSFIdeaBoard_WAR_JSFIdeaBoard_:ideaInputStepTwoFormFooter:imgData2").value = "-1";
} else {
document.getElementById("_JSFIdeaBoard_WAR_JSFIdeaBoard_:ideaInputStepTwoFormFooter:imgData2").value = canvas2.toDataURL('png');
}
}
};
......@@ -265,7 +281,11 @@ function handleTabChange(index) {
if (!fabric.Canvas.supports('toDataURL')) {
alert('This browser doesn\'t provide means to serialize canvas to an image');
} else {
document.getElementById("_JSFIdeaBoard_WAR_JSFIdeaBoard_:ideaInputStepTwoFormFooter:imgData3").value = canvas3.toDataURL('png');
if(isCanvasBlank(canvas3)) {
document.getElementById("_JSFIdeaBoard_WAR_JSFIdeaBoard_:ideaInputStepTwoFormFooter:imgData3").value = "-1";
} else {
document.getElementById("_JSFIdeaBoard_WAR_JSFIdeaBoard_:ideaInputStepTwoFormFooter:imgData3").value = canvas3.toDataURL('png');
}
}
};
......
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