Skip to content

Commit 5201066

Browse files
refactor confirm button on clear - #4079 (#4082)
* refactor confirm button on clear * confirmation modal added
1 parent c4aad3d commit 5201066

File tree

2 files changed

+63
-55
lines changed

2 files changed

+63
-55
lines changed

index.html

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,9 @@
314314
</div>
315315
</div>
316316

317-
<div
318-
class="clearPop"
319-
id="ClearButton"
320-
tabindex="-1"
321-
>
322-
<span id="ClearContent"></span>
323-
<img
324-
id="clearClose"
325-
class="msgCloseIcon"
326-
src="images/close.svg"
327-
alt="Close"
328-
/>
317+
<div id="clear-modal-container" style="display: none; z-index: 999; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.4); align-items: center; justify-content: center;">
318+
<div id="cleardropdown" style="background-color: white; padding: 24px; border-radius: 8px; width: 400px; box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);">
319+
</div>
329320
</div>
330321

331322
<script>

js/turtles.js

Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -891,58 +891,75 @@ Turtles.TurtlesView = class {
891891
};
892892
};
893893

894-
/**
895-
* Makes clear button by initailising 'CLEARBUTTON' SVG.
896-
* Assigns click listener function to call allClear() method.
897-
*/
894+
const renderClearConfirmation = () => {
895+
const modalContainer = document.getElementById("clear-modal-container");
896+
const clearDropdown = document.getElementById("cleardropdown");
897+
clearDropdown.innerHTML = "";
898+
899+
const title = document.createElement("div");
900+
title.innerHTML = `<h2 style="color: #0066FF; font-size: 24px; text-align: left; margin: 0;">${_("Clear Workspace")}</h2>`;
901+
clearDropdown.appendChild(title);
902+
903+
const confirmationMessage = document.createElement("div");
904+
confirmationMessage.innerHTML = `<div style="color: #666666; font-size: 16px; margin-bottom: 24px; text-align: left;">
905+
${_("Are you sure you want to clear the workspace ?")}
906+
</div>`;
907+
clearDropdown.appendChild(confirmationMessage);
908+
909+
const confirmButton = document.createElement("button");
910+
confirmButton.innerHTML = _("Confirm");
911+
confirmButton.style.cssText = `
912+
background-color: #2196F3;
913+
color: white;
914+
border: none;
915+
border-radius: 4px;
916+
padding: 8px 16px;
917+
font-weight: bold;
918+
cursor: pointer;
919+
margin-right: 16px;
920+
`;
921+
confirmButton.onclick = () => {
922+
this.activity._allClear();
923+
modalContainer.style.display = "none";
924+
};
925+
clearDropdown.appendChild(confirmButton);
926+
927+
const cancelButton = document.createElement("button");
928+
cancelButton.innerHTML = _("Cancel");
929+
cancelButton.style.cssText = `
930+
background-color: #f1f1f1;
931+
color: black;
932+
border: none;
933+
border-radius: 4px;
934+
padding: 8px 16px;
935+
font-weight: bold;
936+
cursor: pointer;
937+
`;
938+
cancelButton.onclick = () => {
939+
modalContainer.style.display = "none";
940+
};
941+
clearDropdown.appendChild(cancelButton);
942+
943+
modalContainer.style.display = "flex";
944+
};
945+
946+
898947
const __makeClearButton = () => {
948+
// Create the Clear button using the existing _makeButton helper
899949
this._clearButton = _makeButton(
900950
CLEARBUTTON,
901951
{
902-
"name":"Clean",
903-
"label":_("Clean")
952+
name: "Clean",
953+
label: _("Clean"),
904954
},
905955
this._w - 5 - 2 * 55,
906956
70 + LEADING + 6
907957
);
908-
909-
this._clearButton.onclick = () => {
910-
const clearBox = document.getElementById("ClearButton");
911-
const clearContent = document.getElementById("ClearContent");
912-
clearContent.innerHTML = _("Confirm");
913-
clearBox.style.visibility="visible";
914-
const auxToolbar = docById("aux-toolbar");
915-
const clearBtnPosition = auxToolbar.style.display === "block" ? "183px" : "125px";
916-
clearBox.style.top = clearBtnPosition;
917-
const func = this.activity._allClear;
918-
clearBox.addEventListener("click", function(event) {
919-
if(event.target.id == "clearClose"){
920-
this.style.visibility = "hidden";
921-
}
922-
else{
923-
func();
924-
clearBox.style.visibility = "hidden";
925-
if (auxToolbar.style.display === "block") {
926-
setTimeout(() => {
927-
docById("Grid").style.top = "136px";
928-
docById("Expand").style.top = "136px";
929-
docById("Collapse").style.top = "136px";
930-
docById("Clean").style.top = "136px";
931-
}, 0);
932-
} else {
933-
docById("Grid").style.top = "76px";
934-
docById("Expand").style.top = "76px";
935-
docById("Collapse").style.top = "76px";
936-
docById("Clean").style.top = "76px";
937-
}
938-
}
939-
});
940-
};
941-
942-
if (doCollapse) {
943-
__collapse();
944-
}
958+
959+
// Assign click listener to the Clear button
960+
this._clearButton.onclick = renderClearConfirmation;
945961
};
962+
946963

947964
/**
948965
* Makes collapse button by initailising 'COLLAPSEBUTTON' SVG.

0 commit comments

Comments
 (0)