Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(old-edit-content): Update Binary Field on save #29540

Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@
customEvent.initCustomEvent('ng-event', false, false, customEventDetail);
document.dispatchEvent(customEvent);

setBinaryFieldInputs()

}

function refreshPermissionsTab(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
Object inodeObj =(Object) request.getAttribute("inode");
String inode = inodeObj != null ? inodeObj.toString() : "";

String contentletIdentifierGlobal = contentlet.getIdentifier();
zJaaal marked this conversation as resolved.
Show resolved Hide resolved

String counter = (String) request.getAttribute("counter");

boolean fullScreenField = Try.of(()->(boolean)request.getAttribute("DOT_FULL_SCREEN_FIELD")).getOrElse(false);
Expand Down Expand Up @@ -216,7 +218,7 @@
String jsonField = "{}";
String contentletObj = "{}";
Boolean showVideoThumbnail = Config.getBooleanProperty("SHOW_VIDEO_THUMBNAIL", true);

// If it can be parsed as a JSON, then it means that the value is already a Block Editor's value
if (value != null) {
try {
Expand Down Expand Up @@ -287,7 +289,7 @@
field.value = !detail ? null : JSON.stringify(detail);;
});

//
//
blockEditor.contentlet = contentlet;
blockEditor.field = fieldData;

Expand Down Expand Up @@ -730,16 +732,16 @@
helperText=fv.getValue();
}
}

%>


<div id="confirmReplaceNameDialog-<%=field.getVelocityVarName()%>" dojoType="dijit.Dialog" >
<div dojoType="dijit.layout.ContentPane" style="text-align:center;height:auto;" class="box" hasShadow="true" id="confirmReplaceNameDialog-<%=field.getVelocityVarName()%>CP">
<p style="margin:0;max-width:600px;word-wrap: break-word">
<%= LanguageUtil.get(pageContext, "Do-you-want-to-replace-the-existing-asset-name") %>
"<span id="confirmReplaceNameDialog-<%=field.getVelocityVarName()%>-oldValue"> </span>"
<%= LanguageUtil.get(pageContext, "with") %>
<%= LanguageUtil.get(pageContext, "Do-you-want-to-replace-the-existing-asset-name") %>
"<span id="confirmReplaceNameDialog-<%=field.getVelocityVarName()%>-oldValue"> </span>"
<%= LanguageUtil.get(pageContext, "with") %>
"<span id="confirmReplaceNameDialog-<%=field.getVelocityVarName()%>-newValue"></span>""
<br>&nbsp;<br>
</p>
Expand Down Expand Up @@ -767,22 +769,27 @@
fileNameField?.setValue(newFileName);
dijit.byId("confirmReplaceNameDialog-<%=field.getVelocityVarName()%>").hide();
}

function closeConfirmReplaceName(){
dijit.byId("confirmReplaceNameDialog-<%=field.getVelocityVarName()%>").hide();
}
</script>
<script>
// Create a new scope so that variables defined here can have the same name without being overwritten.
(function autoexecute() {
function setBinaryFieldInputs() {
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
const binaryFieldContainer = document.getElementById("container-binary-field-<%=field.getVelocityVarName()%>");

/**
* Note: This is a temporary solution.
* This is a workaround to get the contentlet from the API
* because there is no way to get the same contentlet the AP retreive from the dwr call.
*/
fetch('/api/v1/content/<%=inode%>', {

const identifier = "<%=contentletIdentifierGlobal%>";



fetch(`/api/v1/content/${identifier}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -830,12 +837,12 @@
if(contentBaseType === 4){ // FileAsset
let titleField = dijit.byId("title");
let fileNameField = dijit.byId("fileName");
window.newFileName = fileName; //To use in confirmReplaceName function
window.newFileName = fileName; //To use in confirmReplaceName function

if(!fileNameField.value){
titleField?.setValue(fileName);
}

if(fileNameField.value && fileName && fileNameField.value !== fileName) {
document.getElementById("confirmReplaceNameDialog-<%=field.getVelocityVarName()%>-oldValue").innerHTML = fileNameField.value;
document.getElementById("confirmReplaceNameDialog-<%=field.getVelocityVarName()%>-newValue").innerHTML = fileName;
Expand Down Expand Up @@ -869,7 +876,9 @@
.catch(() => {
binaryFieldContainer.innerHTMl = '<div class="callOutBox">Error loading the binary field</div>';
})
})();
};

setBinaryFieldInputs();
</script>
<%}else{%>

Expand Down