4 changed files with 62 additions and 54 deletions
@ -1,76 +1,77 @@ |
|||||
/** @odoo-module **/ |
/** @odoo-module **/ |
||||
|
|
||||
import { patch } from "@web/core/utils/patch"; |
import { patch } from "@web/core/utils/patch"; |
||||
import { ListRenderer } from "@web/views/list/list_renderer"; |
import { ListRenderer } from "@web/views/list/list_renderer"; |
||||
import { ListController } from '@web/views/list/list_controller'; |
import { ListController } from '@web/views/list/list_controller'; |
||||
|
|
||||
//For ORM Call
|
//For ORM Call
|
||||
import { useService } from "@web/core/utils/hooks"; |
import { useService } from "@web/core/utils/hooks"; |
||||
|
const { useRef, onPatched, onMounted, useState,onWillUpdateProps } = owl; |
||||
|
|
||||
const { useRef, onPatched, onMounted, useState } = owl; |
|
||||
|
|
||||
//Patching
|
//Patching
|
||||
patch(ListRenderer.prototype, 'list-color-patch', { |
patch(ListRenderer.prototype, 'list-color-patch', { |
||||
setup() { |
setup() { |
||||
|
if (this.constructor.name == 'SectionAndNoteListRenderer') { |
||||
|
// Call method for removing color picking field from one2many
|
||||
|
onMounted(() => { |
||||
|
this.__owl__.bdom.el.children[0].children[1].childNodes.forEach((item) => { |
||||
|
if (item.nodeName != "#text"){ |
||||
|
if(!item.attributes.length == 0){ |
||||
|
var list_one2many = item.children[1]; |
||||
|
list_one2many.remove(); |
||||
|
} |
||||
|
} |
||||
|
}) |
||||
|
}) |
||||
|
} |
||||
this._super.apply(); |
this._super.apply(); |
||||
this.orm = useService("orm"); |
this.orm = useService("orm"); |
||||
// PATH OF CORRESPONDING MODEL
|
onMounted(this.color); |
||||
// var current_model = this.props.list.model.env.searchModel.resModel
|
if (this.constructor.name == 'SectionAndNoteListRenderer') { |
||||
onMounted(this.color) |
// Call method for removing color picking field from one2many
|
||||
|
onPatched(()=>{ |
||||
|
this.__owl__.bdom.el.children[0].children[1].childNodes.forEach((item) => { |
||||
|
if (item.nodeName != "#text"){ |
||||
|
if(!item.attributes.length == 0){ |
||||
|
var list_one2many = item.children[1]; |
||||
|
list_one2many.remove(); |
||||
|
} |
||||
|
} |
||||
|
}) |
||||
|
}); |
||||
|
} |
||||
|
onPatched(()=>{ |
||||
|
this.color() |
||||
|
}); |
||||
}, |
}, |
||||
|
|
||||
|
|
||||
color_pick(ev,record){ |
color_pick(ev,record){ |
||||
var color = ev.target.value |
var color = ev.target.value |
||||
var res_id = record.resId |
var res_id = record.resId |
||||
var res_model = record.resModel |
var res_model = record.resModel |
||||
|
|
||||
//ORM Call
|
//ORM Call
|
||||
|
|
||||
this.orm.call("color.picker","get_color_picker_model_and_id",[],{ |
this.orm.call("color.picker","get_color_picker_model_and_id",[],{ |
||||
record_id: res_id, |
record_id: res_id, |
||||
model_name: res_model, |
model_name: res_model, |
||||
record_color: color, |
record_color: color, |
||||
}).then(function(data){ |
}).then(function(data){ |
||||
|
|
||||
|
|
||||
}) |
}) |
||||
|
|
||||
|
|
||||
ev.target.parentNode.parentNode.style.backgroundColor = color |
ev.target.parentNode.parentNode.style.backgroundColor = color |
||||
}, |
}, |
||||
|
|
||||
|
|
||||
//Call from onMounted
|
//Call from onMounted
|
||||
color(){ |
color(){ |
||||
var current_model = this.props.list.model.env.searchModel.resModel |
var current_model = this.props.list.model.env.searchModel.resModel |
||||
var tr_list = $('.o_data_row') |
var tr_list = $('.o_data_row') |
||||
var current_tr; |
var current_tr; |
||||
|
var self = this; |
||||
|
|
||||
this.orm.call("color.picker","search_read",[],{ |
this.orm.call("color.picker","search_read",[],{ |
||||
domain: [ |
domain: [ |
||||
['res_model', '=',current_model], |
['res_model', '=',current_model], |
||||
|
|
||||
], |
], |
||||
|
|
||||
}).then(function(data){ |
}).then(function(data){ |
||||
for(var i=0;i<tr_list.length;i++){ |
Array.prototype.forEach.call(tr_list, function(tr) { |
||||
current_tr = tr_list[i].children[1].dataset.id |
data.forEach((item) => { |
||||
|
if (tr.firstChild.nextElementSibling.dataset.id == item.record_id) { |
||||
for(var j=0;j<data.length;j++){ |
tr.style.backgroundColor = item.color |
||||
if(current_tr == data[j].record_id){ |
|
||||
tr_list[i].style.backgroundColor = data[j].color |
|
||||
|
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
} |
} |
||||
|
}); |
||||
|
}); |
||||
}) |
}) |
||||
|
|
||||
}, |
}, |
||||
|
|
||||
}) |
}) |
@ -1,20 +1,26 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||
<templates id="template" xml:space="preserve"> |
<templates id="template" xml:space="preserve"> |
||||
<!-- Add the header on th--> |
<!-- Add the header on th--> |
||||
<t t-name="ListHeadTemplate" t-inherit="web.ListRenderer" t-inherit-mode="extension" owl="1"> |
<t t-name="ListHeadTemplate" t-inherit="web.ListRenderer" |
||||
|
t-inherit-mode="extension" owl="1"> |
||||
<xpath expr="//th[hasclass('o_list_record_selector')]" position="after"> |
<xpath expr="//th[hasclass('o_list_record_selector')]" position="after"> |
||||
<th> |
<th> |
||||
<td>Color</td> |
<td class="color_picker_td">Color</td> |
||||
</th> |
</th> |
||||
</xpath> |
</xpath> |
||||
</t> |
</t> |
||||
<!-- Add the color field on tree --> |
<!-- Add the color field on tree --> |
||||
<t t-name="ListColorTemplate" t-inherit="web.ListRenderer.RecordRow" t-inherit-mode="extension" owl="1"> |
<t t-name="ListColorTemplate" t-inherit="web.ListRenderer.RecordRow" |
||||
|
t-inherit-mode="extension" owl="1"> |
||||
<xpath expr="//td[hasclass('o_list_record_selector')]" position="after"> |
<xpath expr="//td[hasclass('o_list_record_selector')]" position="after"> |
||||
<td class="not_display" t-att-data-id="record.resId" style="display:none"> |
<td class="not_display" t-att-data-id="record.resId" |
||||
|
style="display:none"> |
||||
</td> |
</td> |
||||
<td class="color_picker_checkbox"> |
<td class="color_picker_checkbox"> |
||||
<input type="color" value="#e7d8d5" class="row_color_pick" name="row_color_value" style="width:20px;border: 1px;height: 20px;" t-on-change="(ev) => this.color_pick(ev, record)"/> |
<input type="color" value="#e7d8d5" class="row_color_pick" |
||||
|
name="row_color_value" |
||||
|
style="width:20px;border: 1px;height: 20px;" |
||||
|
t-on-change="(ev) => this.color_pick(ev, record)"/> |
||||
</td> |
</td> |
||||
</xpath> |
</xpath> |
||||
</t> |
</t> |
||||
|
Loading…
Reference in new issue