Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 9, 2024
1 parent bcf6102 commit e589138
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 144 deletions.
28 changes: 5 additions & 23 deletions solara/lib/core/dashboard/brand/BrandView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {DataSource} from './BrandModel.js';
import '../component/onboard_bottom_sheet/OnboardBottomSheet.js';
import '../component/OnboardBottomSheet.js';
import './AddFieldSheet.js';
import '../component/ConfirmationDialog.js';

class BrandView {
constructor(model) {
Expand Down Expand Up @@ -379,12 +380,12 @@ class BrandView {
const deleteIcon = document.createElement('span');
deleteIcon.className = 'delete-icon';
deleteIcon.textContent = '×';
deleteIcon.onclick = () => this.onDeleteField(sectionItem, container, section);
deleteIcon.onclick = () => this.onDeleteField(sectionItem, container);
inputWrapper.appendChild(deleteIcon);

container.appendChild(inputWrapper);

container.addEventListener('change', () => this.onSectionChanged(sectionItem, container.closest('.section'), section));
container.addEventListener('change', () => this.onSectionChanged(sectionItem, container.closest('.section')));

return container;
}
Expand Down Expand Up @@ -422,26 +423,7 @@ class BrandView {
}

showConfirmationDialog(message, onConfirm) {
const confirmationMessageElement = document.getElementById('confirmationMessage');
const confirmButton = document.getElementById('confirmButton');
const cancelButton = document.getElementById('cancelButton');

confirmationMessageElement.textContent = message;
this.confirmationDialog.style.display = 'block';
this.overlay.style.display = 'block';

confirmButton.onclick = () => {
onConfirm();
this.hideConfirmationDialog();
};

cancelButton.onclick = () => this.hideConfirmationDialog();
this.overlay.onclick = () => this.hideConfirmationDialog();
}

hideConfirmationDialog() {
this.confirmationDialog.style.display = 'none';
this.overlay.style.display = 'none';
this.confirmationDialog.showDialog(message, onConfirm);
}

showApplyChangesButton() {
Expand Down
53 changes: 2 additions & 51 deletions solara/lib/core/dashboard/brand/brand.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,49 +168,7 @@
width: 100%;
}
}
.confirmation-dialog {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 1001;
text-align: center;
}
.confirmation-dialog h3 {
margin-top: 0;
color: var(--primary-color);
}
.confirmation-dialog .buttons {
margin-top: 20px;
}
.confirmation-dialog button {
margin: 0 10px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.confirmation-dialog .confirm {
background-color: var(--delete-color);
color: white;
}
.confirmation-dialog .cancel {
background-color: #ccc;
color: #333;
}
.confirmation-dialog .confirm:hover {
background-color: #c82333;
}
.confirmation-dialog .cancel:hover {
background-color: #bbb;
}


.array-input-container {
display: flex;
Expand Down Expand Up @@ -527,14 +485,7 @@ <h1><span id="brandNametitle"></span></h1>
<button class="close-message" id="closeMessage">Close</button>
</div>

<div class="confirmation-dialog" id="confirmationDialog">
<h3>Confirm Action</h3>
<p id="confirmationMessage"></p>
<div class="buttons">
<button class="confirm" id="confirmButton">Confirm</button>
<button class="cancel" id="cancelButton">Cancel</button>
</div>
</div>
<confirmation-dialog id="confirmationDialog"></confirmation-dialog>

<div class="overlay" id="overlay"></div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions solara/lib/core/dashboard/brands/BrandsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ class BrandsController {

const brandKey = this.view.bottomSheet.dataset.brandKey;
const brandName = this.view.bottomSheet.dataset.brandName;
this.view.showConfirmationDialog(`Are you sure you need to offboard ${brandKey} (${brandName}) and delete all its configurations?`);
document.getElementById('confirmButton').onclick = async () => {
await this.model.offboardBrand(brandKey);
location.reload();
};
this.view.showConfirmationDialog(`Are you sure you need to offboard ${brandKey} (${brandName}) and delete all its configurations?`,
async () => {
await this.model.offboardBrand(brandKey);
location.reload();
});
}

async handleDoctorOption(event) {
Expand Down
18 changes: 4 additions & 14 deletions solara/lib/core/dashboard/brands/BrandsView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '../component/onboard_bottom_sheet/OnboardBottomSheet.js';
import '../component/OnboardBottomSheet.js';
import '../component/ConfirmationDialog.js';

class BrandsView {
constructor() {
Expand Down Expand Up @@ -139,19 +140,8 @@ class BrandsView {
this.overlay.style.display = 'none';
}

showConfirmationDialog(message) {
const confirmationMessageElement = document.getElementById('confirmationMessage');
const cancelButton = document.getElementById('cancelButton');
confirmationMessageElement.textContent = message;
this.confirmationDialog.style.display = 'block';
this.overlay.style.display = 'block';
this.overlay.onclick = () => this.hideConfirmationDialog();
cancelButton.onclick = () => this.hideConfirmationDialog();
}

hideConfirmationDialog() {
this.confirmationDialog.style.display = 'none';
this.overlay.style.display = 'none';
showConfirmationDialog(message, onConfirm) {
this.confirmationDialog.showDialog(message, onConfirm);
}

showMessage(message) {
Expand Down
52 changes: 1 addition & 51 deletions solara/lib/core/dashboard/brands/brands.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,49 +181,6 @@
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
}
.confirmation-dialog {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 1001;
text-align: center;
}
.confirmation-dialog h3 {
margin-top: 0;
color: var(--primary-color);
}
.confirmation-dialog .buttons {
margin-top: 20px;
}
.confirmation-dialog button {
margin: 0 10px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.confirmation-dialog .confirm {
background-color: var(--offboard-color);
color: white;
}
.confirmation-dialog .cancel {
background-color: #ccc;
color: #333;
}
.confirmation-dialog .confirm:hover {
background-color: #c82333;
}
.confirmation-dialog .cancel:hover {
background-color: #bbb;
}
.brands-list-header {
display: flex;
justify-content: space-between;
Expand Down Expand Up @@ -553,14 +510,7 @@ <h2>All Brands</h2>
</ul>
</div>

<div class="confirmation-dialog" id="confirmationDialog">
<h3>Confirm Action</h3>
<p id="confirmationMessage"></p>
<div class="buttons">
<button class="confirm" id="confirmButton">Confirm</button>
<button class="cancel" id="cancelButton">Cancel</button>
</div>
</div>
<confirmation-dialog id="confirmationDialog"></confirmation-dialog>

<onboard-bottom-sheet id="onboardBottomSheet"></onboard-bottom-sheet>

Expand Down
103 changes: 103 additions & 0 deletions solara/lib/core/dashboard/component/ConfirmationDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
class ConfirmationDialog extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'});
this.render();
}

render() {
this.shadowRoot.innerHTML = `
<style>
.confirmation-dialog {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 1001;
text-align: center;
}
.confirmation-dialog h3 {
margin-top: 0;
color: var(--primary-color);
}
.confirmation-dialog .buttons {
margin-top: 20px;
}
.confirmation-dialog button {
margin: 0 10px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.confirmation-dialog .confirm {
background-color: #dc3545;
color: white;
}
.confirmation-dialog .cancel {
background-color: #ccc;
color: #333;
}
.confirmation-dialog .confirm:hover {
background-color: #c82333;
}
.confirmation-dialog .cancel:hover {
background-color: #bbb;
}
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
}
</style>
<div class="overlay" id="overlay"></div>
<div class="confirmation-dialog" id="confirmationDialog">
<h3>Confirm Action</h3>
<p id="confirmationMessage"></p>
<div class="buttons">
<button class="confirm" id="confirmButton">Confirm</button>
<button id="cancelButton">Cancel</button>
</div>
</div>
`;

this.confirmationDialog = this.shadowRoot.getElementById('confirmationDialog');
this.overlay = this.shadowRoot.getElementById('overlay');
this.confirmButton = this.shadowRoot.getElementById('confirmButton');
this.cancelButton = this.shadowRoot.getElementById('cancelButton');
this.confirmationMessageElement = this.shadowRoot.getElementById('confirmationMessage');

this.cancelButton.onclick = () => this.hide();
this.overlay.onclick = () => this.hide();
}

showDialog(message, onConfirm) {
this.confirmationMessageElement.textContent = message;
this.confirmationDialog.style.display = 'block';
this.overlay.style.display = 'block';

this.confirmButton.onclick = () => {
onConfirm();
this.hide();
};
}

hide() {
this.confirmationDialog.style.display = 'none';
this.overlay.style.display = 'none';
}
}

customElements.define('confirmation-dialog', ConfirmationDialog);

0 comments on commit e589138

Please sign in to comment.