1
|
|
|
import {Datatable} from './datatable' |
2
|
|
|
|
3
|
|
|
export class EntityField { |
4
|
|
|
constructor() { |
5
|
|
|
this.initEntityFields() |
6
|
|
|
this.initListener() |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Initalize datatable for all entity fields |
11
|
|
|
*/ |
12
|
|
|
initEntityFields() { |
13
|
|
|
if ($('table[data-filter-type="related-list"]').length == 0) { |
|
|
|
|
14
|
|
|
return |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
$('table[data-filter-type="related-list"]').each((index, el) => { |
18
|
|
|
// Click callback |
19
|
|
|
let rowClickCallback = (event, datatable, recordId, recordLabel) => { |
20
|
|
|
this.selectRelatedModule(datatable, recordId, recordLabel) |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
let datatable = new Datatable() |
24
|
|
|
datatable.init(el, rowClickCallback) |
25
|
|
|
datatable.makeQuery() |
26
|
|
|
}) |
27
|
|
|
|
28
|
|
|
$('.delete-related-record').on('click', (event) => { |
29
|
|
|
const modal = $(event.currentTarget).parents('.modal:first'); |
30
|
|
|
const fieldName = modal.attr('data-field') |
31
|
|
|
|
32
|
|
|
$(`[name='${fieldName}']`).val('') |
33
|
|
|
$(`#${fieldName}_display`).val('') |
34
|
|
|
$(`#${fieldName}_display`).parent().find('label').removeClass('active') |
35
|
|
|
|
36
|
|
|
$(modal).modal('close') |
37
|
|
|
}) |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
selectRelatedModule(datatable, recordId, recordLabel) { |
41
|
|
|
const modal = $(datatable.table).parents('.modal:first'); |
42
|
|
|
const fieldName = modal.attr('data-field') |
43
|
|
|
|
44
|
|
|
$(`[name='${fieldName}']`).val(recordId).trigger('keyup') |
45
|
|
|
$(`#${fieldName}_display`).val(recordLabel) |
46
|
|
|
$(`#${fieldName}_display`).parent().find('label').addClass('active') |
47
|
|
|
|
48
|
|
|
$(modal).modal('close') |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
initListener() { |
52
|
|
|
$('a.entity-modal').on('click', function() { |
53
|
|
|
let tableId = $(this).attr('data-table') |
54
|
|
|
let event = new CustomEvent('uccello.list.refresh', { detail: tableId }) |
|
|
|
|
55
|
|
|
dispatchEvent(event) |
56
|
|
|
}) |
57
|
|
|
} |
58
|
|
|
} |