Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1545 Lượt xem

Dear All,

I have tried so many methods to override this function using patch (without prototype) and old JS methods but unable override it.
Original function path : addons/web/static/src/views/calendar/colors.js
Original Function : 

export function getColor(key) {
if (!key) {
return false;
}
if (colorMap.has(key)) {
return colorMap.get(key);
}

// check if the key is a css color
if (typeof key === "string" && key.match(CSS_COLOR_REGEX)) {
colorMap.set(key, key);
} else if (typeof key === "number") {
colorMap.set(key, ((key - 1) % 55) + 1);
} else {
colorMap.set(key, (((colorMap.size + 1) * 5) % 24) + 1);
}

return colorMap.get(key);
}

Can someone please help me to override this function?



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

You can create a new function to replace an existing one and use it wherever the old function was used. For example, if you want to modify the getColor function inside the openPopover function, you can patch the openPopover function with your new changes


openPopover(target, record) {

    const color = getColor(record.colorIndex);

    this.popover.open(

        target,

        this.getPopoverProps(record),

        `o_cw_popover o_calendar_color_${typeof color === "number" ? color : 0}`

    );

}



You can create your own version of the getColor function and then update the openPopover function to use it. This way, your new function will work wherever the old one was used


Hope it helps.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 24
1196
0
thg 11 23
1589
1
thg 8 23
4542
0
thg 4 22
4206
0
thg 5 21
19