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

Progress bar options #3687

Draft
wants to merge 1 commit into
base: master-mysterious-egg
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Component, onWillDestroy } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { defaultOptionComponents } from "../components/defaultComponents";

export class ProgressBarOption extends Component {
static template = "html_builder.ProgressBarOption";
static components = { ...defaultOptionComponents };
static props = {};

setup() {
registry
.category("clean-for-save-options")
.add("cleanForSaveProgressBarOption", this.cleanForSave.bind(this));
onWillDestroy(() => {
registry.category("clean-for-save-options").remove("cleanForSaveProgressBarOption");
});
}
cleanForSave() {
const editingEl = this.env.getEditingElement();
const progressBar = editingEl.querySelector(".progress-bar");
const progressLabel = editingEl.querySelector(".s_progress_bar_text");

if (!progressBar.classList.contains("progress-bar-striped")) {
progressBar.classList.remove("progress-bar-animated");
}

if (progressLabel && progressLabel.classList.contains("d-none")) {
progressLabel.remove();
}
}
}

registry.category("sidebar-element-option").add("ProgressBarOption", {
OptionComponent: ProgressBarOption,
selector: ".s_progress_bar",
});

registry.category("website-builder-actions").add("display", {
apply: ({ editingElement, param }) => {
// retro-compatibility
if (editingElement.classList.contains("progress")) {
editingElement.classList.remove("progress");
const progressBarEl = editingElement.querySelector(".progress-bar");
if (progressBarEl) {
const wrapperEl = document.createElement("div");
wrapperEl.classList.add("progress");
progressBarEl.parentNode.insertBefore(wrapperEl, progressBarEl);
wrapperEl.appendChild(progressBarEl);
editingElement.querySelectorAll(".progress-bar span").foreach((spanEl) => {
spanEl.classList.add("s_progress_bar_text");
});
}
}

const progress = editingElement.querySelector(".progress");
const progressValue = progress.getAttribute("aria-valuenow");
let progressLabel = editingElement.querySelector(".s_progress_bar_text");

if (!progressLabel && param !== "none") {
progressLabel = document.createElement("span");
progressLabel.classList.add("s_progress_bar_text", "small");
progressLabel.textContent = progressValue + "%";
}

if (param === "inline") {
editingElement.querySelector(".progress-bar").appendChild(progressLabel);
} else if (["below", "after"].includes(param)) {
progress.insertAdjacentElement("afterend", progressLabel);
}

// Temporary hide the label. It's effectively removed in cleanForSave
// if the option is confirmed
progressLabel.classList.toggle("d-none", param === "none");
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="html_builder.ProgressBarOption">
<WeRow label.translate="Label">
<WeSelect>
<WeSelectItem action="'display'" actionParam="'inline'" classAction="'s_progress_bar_label_inline'">Display Inside</WeSelectItem>
<WeSelectItem action="'display'" actionParam="'below'" classAction="'s_progress_bar_label_below'">Display Below</WeSelectItem>
<WeSelectItem action="'display'" actionParam="'after'" classAction="'s_progress_bar_label_after'">Display After</WeSelectItem>
<WeSelectItem action="'display'" actionParam="'none'" classAction="'s_progress_bar_label_hidden'">Hide</WeSelectItem>
</WeSelect>
</WeRow>
</t>

</templates>
5 changes: 5 additions & 0 deletions addons/html_builder/static/src/builder/snippets_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ export class SnippetsMenu extends Component {
for (const actionButtonEl of actionButtonEls) {
actionButtonEl.disabled = true;
}
// Do the cleanForSave of the options
const saveOptions = registry.category("clean-for-save-options").getAll();
for (const saveOption of saveOptions) {
saveOption();
}
// Save the pending images and the dirty elements
const saveProms = [...this.editor.editable.querySelectorAll(".o_dirty")].map(
async (dirtyEl) => {
Expand Down