55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
/** @odoo-module */
|
|
|
|
import { registry } from "@web/core/registry";
|
|
import { useService } from "@web/core/utils/hooks";
|
|
import { standardFieldProps } from "@web/views/fields/standard_field_props";
|
|
import { _t } from "@web/core/l10n/translation";
|
|
import { KsImageDialog } from "./ks_image_dialog";
|
|
import { KS_ICON } from "../dashboard/ks_constant";
|
|
const { useState, Component} = owl;
|
|
|
|
class KsImage extends Component {
|
|
|
|
static template = "ks_dashboard_ninja.ksImage";
|
|
static props = {
|
|
...standardFieldProps
|
|
}
|
|
|
|
setup() {
|
|
this.dialog = useService('dialog');
|
|
this.fieldName = this.props.name;
|
|
this.value = this.props.record.data[this.fieldName];
|
|
|
|
this.state = useState({
|
|
icon: this.value ?? KS_ICON[0],
|
|
});
|
|
this.ks_icon = KS_ICON;
|
|
}
|
|
|
|
onClickSelectIcon() {
|
|
this.dialog.add(KsImageDialog, {
|
|
title: _t('Select Icon'),
|
|
body: _t('Icon'),
|
|
icons: KS_ICON,
|
|
cancel: () => {},
|
|
confirm: (icon) => this.onClickIcon(icon),
|
|
});
|
|
}
|
|
|
|
onClickIcon(icon) {
|
|
this.state.icon = icon;
|
|
this.props.record.update({[this.fieldName]: icon});
|
|
}
|
|
|
|
onClickClear() {
|
|
this.state.icon = false;
|
|
}
|
|
|
|
}
|
|
|
|
const ksImageField = {
|
|
component: KsImage,
|
|
supportedTypes: ["char"],
|
|
}
|
|
registry.category("fields").add('ks_image_widget', ksImageField);
|