-
Notifications
You must be signed in to change notification settings - Fork 104
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
1 parent
2cefa55
commit c5e90eb
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
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
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
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,77 @@ | ||
/** @odoo-module */ | ||
import {registry} from "@web/core/registry"; | ||
import {Many2OneField, many2OneField} from "@web/views/fields/many2one/many2one_field"; | ||
import {onWillUpdateProps} from "@odoo/owl"; | ||
|
||
export class PlmMany2oneWidget extends Many2OneField { | ||
|
||
static template = "plm.PlmMany2oneWidget"; | ||
static props = { | ||
...Many2OneField.props, | ||
options: {type: Object, optional: true}, | ||
}; | ||
static defaultProps = { | ||
...Many2OneField.defaultProps, | ||
options: false, | ||
}; | ||
|
||
async setup() { | ||
super.setup(); | ||
console.log("..........1"); | ||
this.imageData = false; | ||
this.relatedField = false; | ||
this.imageToolTipData = false; | ||
onWillUpdateProps(async (nextProps) => { | ||
this.imageData = false; | ||
this.imageToolTipData = false; | ||
let fieldName = nextProps.name; | ||
if (nextProps && nextProps.record && nextProps.record.data && nextProps.record.data[fieldName] && nextProps.record.data[fieldName].length != 0) { | ||
let imageData = await this.env.model.orm.call(this.relation, "search_read", [], { | ||
domain: [["id", "=", nextProps.record.data[fieldName][0]]], | ||
fields: [nextProps.options.image_field], | ||
}); | ||
if (imageData && imageData.length != 0 && imageData[0][nextProps.options.image_field]) { | ||
this.imageData = "data:image/png;base64, " + imageData[0][nextProps.options.image_field]; | ||
this.imageToolTipData = JSON.stringify({"url": this.imageData}); | ||
this.render(); | ||
} | ||
} | ||
}); | ||
if (this.props && this.props.record && this.props.record.data && this.props.record.data[this.props.name] && this.props.record.data[this.props.name].length != 0) { | ||
|
||
|
||
let imageData = await this.env.model.orm.call(this.relation, "search_read", [], { | ||
domain: [["id", "=", this.props.record.data[this.props.name][0]]], | ||
fields: [this.props.options.image_field], | ||
}); | ||
this.relatedField = await this.env.model.orm.call(this.relation, "search_read", [], { | ||
domain: [["id", "=", this.props.record.data[this.props.name][0]]], | ||
fields: [this.props.options.linked_field], | ||
}); | ||
if (imageData && imageData.length != 0 && imageData[0][this.props.options.image_field]) { | ||
this.imageData = "data:image/png;base64, " + imageData[0][this.props.options.image_field]; | ||
this.imageToolTipData = JSON.stringify({"url": this.imageData}); | ||
this.render(); | ||
} | ||
} | ||
} | ||
|
||
onImageClicked() { | ||
|
||
let selectedProductId = this.props.record.data.product_id[0]; | ||
let relatedFieldName = this.props.options.linked_field; | ||
let model = this.props.record.model.root.model.config.fields[this.props.name].relation; | ||
let action_open_linked_field = this.props.record.model.orm.call(model, "action_open_linked_field", [selectedProductId, relatedFieldName]); | ||
return this.action.doAction(action_open_linked_field); | ||
} | ||
} | ||
|
||
const plmMany2oneField = { | ||
...many2OneField, | ||
component: PlmMany2oneWidget, | ||
extractProps: ({attrs, context, decorations, options, string}, dynamicInfo) => ({ | ||
...many2OneField.extractProps({attrs, context, decorations, options, string}, dynamicInfo), | ||
options: options, | ||
}), | ||
}; | ||
registry.category("fields").add("plm_many2one_image", plmMany2oneField); |
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="plm.PlmMany2oneWidget" t-inherit="web.Many2OneField" t-inherit-mode="primary"> | ||
<xpath expr="//div[hasclass('o_field_many2one_selection')]/Many2XAutocomplete" position="before"> | ||
<span t-if="imageData"> | ||
<img data-tooltip-template="web.ImageZoomTooltip" | ||
t-att-data-tooltip-info="imageToolTipData" | ||
style="width:30px;height:30px" t-att-src="imageData" | ||
t-on-click="onImageClicked" | ||
/> | ||
</span> | ||
</xpath> | ||
</t> | ||
</templates> |