Files
odoo-docs/static/js/misc.js
Lulu Grimalkin (lugr) 912dde6d26 [ADD] Inventory: add stock valuation cheat sheet
An adaptation of the venerable business memento from 8.0 to the new
inventory valuation mechanics of Odoo 19.0 by scavenging and cobbling
together of the scripts `entries.js` and `coa-valuation.js`. The shared
data is kept in a separate file.

Additionally, we remove the old inventory valuation documentation.

Task ID: 5107300

closes odoo/documentation#14906

Signed-off-by: Felicia Kuan (feku) <feku@odoo.com>
2025-10-23 17:06:20 +00:00

114 lines
4.4 KiB
JavaScript

(function () {
document.addEventListener('DOMContentLoaded', function () {
alternatives();
highlight();
checks_handling();
});
function highlight() {
// NOTE: used by valuation cheat_sheet.rst
$('.highlighter-list').each(function () {
var $this = $(this),
$target = $($this.data('target'));
$this.on('mouseout', 'li', function (e) {
$(e.currentTarget).removeClass('secondary');
$target.find('.related').removeClass('related');
}).on('mouseover', 'li', function (e) {
if (!e.currentTarget.contains(e.target)) { return; }
var $li = $(e.currentTarget);
// console.log($li, $li.data('highlight'), $target.find($li.data('highlight')));
$li.addClass('secondary');
$target.find($li.data('highlight')).addClass('related');
});
});
}
/** alternatives display:
* - prepend control for each <dt>
* - radio input with link to following dd
* - label is <dt> content
* - hide all first-level dt and dd (CSS)
* - on change
* - hide all dds
* - show dd corresponding to the selected radio
* - automatically select first control on startup
*/
function alternatives() {
// NOTE: used by valuation cheat_sheet.rst
$('dl.alternatives').each(function (index) {
var $list = $(this),
$contents = $list.children('dd');
var $controls = $('<div class="alternatives-controls">').append(
$list.children('dt').map(function () {
var label = document.createElement('label'),
input = document.createElement('input');
input.setAttribute('type', 'radio');
input.setAttribute('name', 'alternatives-' + index);
var sibling = this;
while ((sibling = sibling.nextSibling) && sibling.nodeType !== 1);
input.content = sibling;
label.appendChild(input);
label.appendChild(document.createTextNode(' '));
// Hack to bold the definition since we have to strip rST formatting
const [headText, tailText] = this.textContent.split(':', 2);
if (tailText) {
const bold = document.createElement('b'),
defined = document.createTextNode(`${headText}:`);
bold.appendChild(defined);
label.appendChild(bold);
}
label.appendChild(document.createTextNode(tailText || headText));
label.normalize();
return label;
}))
.insertBefore($list)
.on('change', 'input', function (e) {
// change event triggers only on newly selected input, not
// on the one being deselected
$contents.css('display', '');
var content = e.target.content;
content && (content.style.display = 'block');
})
.find('input:first').click();
});
$('.alternatives-note').insertAfter($('.alternatives-controls'));
}
function checks_handling() {
// NOTE: used by accounting cheat_sheet.rst
var $section = $('.checks-handling');
if (!$section.length) { return; }
var $ul = $section.find('ul')
.find('li').each(function () {
var txt = this.textContent;
while (this.firstChild) {
this.removeChild(this.firstChild)
}
$('<label style="display: block;">')
.append('<input type="radio" name="checks-handling">')
.append(' ')
.append(txt)
.appendTo(this);
}).end()
.on('change', 'input', update);
update();
function update() {
var $inputs = $ul.find('input');
var idx = 0;
$inputs.each(function (index) {
if (this.checked) {
idx = index;
}
}).eq(idx).prop('checked', true);
$ul.nextAll('div').hide().eq(idx).show();
}
}
})();