Skip to content

Commit

Permalink
#23603 : Creating new branch based on master.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcastro-dotcms committed Mar 3, 2023
1 parent 99d0455 commit c77114a
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@
aceAreaParser(parser);
}
/**
* Adds the on-blur event to the "File Name" field so that it automatically fills the "Title", if required.
*/
function addAutoFillTitleEvent() {
dojo.byId("fileName").addEventListener("blur", (event) => {
const titleField = dojo.byId("title");
if (titleField && !titleField.value) {
titleField.value = dojo.byId("fileName").value;
}
});
}
let tempFileId = "new";
/**
Expand All @@ -93,20 +105,20 @@
if(!changed) {
return;
}
let text = aceEditor.getValue();
const text = aceEditor.getValue();
if (contentletInode.value == '') {
let fileName = dojo.byId("fileName").value;
const fileName = dojo.byId("fileName").value;
if (fileName) {
let fileExtension = fileName.split('.').pop();
const fileExtension = fileName.split('.').pop();
if (fileExtension) {
loadAce(fileExtension);
}
let data = JSON.stringify({
const data = JSON.stringify({
"fileName": fileName,
"fileContent": text
});
let xhr = new XMLHttpRequest();
const xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
Expand All @@ -115,9 +127,9 @@
});
xhr.onload = function() {
let jsonData = JSON.parse(xhr.response);
const jsonData = JSON.parse(xhr.response);
tempFileId = jsonData.tempFiles[0].id;
let elements = document.getElementsByName("<%= field.getFieldContentlet() %>");
const elements = document.getElementsByName("<%= field.getFieldContentlet() %>");
for (let i = 0; i < elements.length; i++) {
if (elements[i].tagName.toLowerCase() == "input") {
elements[i].value = tempFileId;
Expand Down Expand Up @@ -156,5 +168,8 @@
<input type="hidden" id="<%=field.getVelocityVarName()%>_hidden_field" value="<%=contents %>">

<script>
loadAce("<%= fileExtension %>")
loadAce("<%= fileExtension %>");
document.addEventListener("DOMContentLoaded", function(event) {
addAutoFillTitleEvent();
});
</script>

0 comments on commit c77114a

Please sign in to comment.