-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
addons/html_builder/static/src/builder/options/progress_bar_option.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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("website-builder-actions").add("display", { | ||
isActive: () => { | ||
// Obligé de mettre; peut-être ennuiant | ||
return true; | ||
}, | ||
apply: this.display.bind(this), | ||
}); | ||
registry | ||
.category("clean-for-save-options") | ||
.add("cleanForSaveProgressBarOption", this.cleanForSave.bind(this)); | ||
onWillDestroy(() => { | ||
registry.category("website-builder-actions").remove("display"); | ||
registry.category("clean-for-save-options").remove("cleanForSaveProgressBarOption"); | ||
}); | ||
} | ||
display({ 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"); | ||
} | ||
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", | ||
}); |
15 changes: 15 additions & 0 deletions
15
addons/html_builder/static/src/builder/options/progress_bar_option.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters