1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
odoo.define('hr.StandaloneM2OAvatarEmployee', function (require) {
'use strict';
const StandaloneFieldManagerMixin = require('web.StandaloneFieldManagerMixin');
const Widget = require('web.Widget');
const { Many2OneAvatarEmployee } = require('hr.Many2OneAvatarEmployee');
const StandaloneM2OAvatarEmployee = Widget.extend(StandaloneFieldManagerMixin, {
className: 'o_standalone_avatar_employee',
/**
* @override
*/
init(parent, value) {
this._super(...arguments);
StandaloneFieldManagerMixin.init.call(this);
this.value = value;
},
/**
* @override
*/
willStart() {
return Promise.all([this._super(...arguments), this._makeAvatarWidget()]);
},
/**
* @override
*/
start() {
this.avatarWidget.$el.appendTo(this.$el);
return this._super(...arguments);
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* Create a record, and initialize and start the avatar widget.
*
* @private
* @returns {Promise}
*/
async _makeAvatarWidget() {
const modelName = 'hr.employee';
const fieldName = 'employee_id';
const recordId = await this.model.makeRecord(modelName, [{
name: fieldName,
relation: modelName,
type: 'many2one',
value: this.value,
}]);
const state = this.model.get(recordId);
this.avatarWidget = new Many2OneAvatarEmployee(this, fieldName, state);
this._registerWidget(recordId, fieldName, this.avatarWidget);
return this.avatarWidget.appendTo(document.createDocumentFragment());
},
});
return StandaloneM2OAvatarEmployee;
});
|