1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import {
|
7 | rowUtilFunObj
|
8 | } from './row-util';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | const getValue = function(fieldName) {
|
18 | return rowUtilFunObj._getField(this, fieldName)['value']
|
19 | }
|
20 |
|
21 |
|
22 | const getChildValue = function(fieldName) {
|
23 | var nameArr = fieldName.split('.');
|
24 | var _name = nameArr[0];
|
25 | for (var i = 0, count = nameArr.length; i < count; i++) {
|
26 | var _value = this.getValue(_name);
|
27 |
|
28 | if (i == count - 1) {
|
29 | if (_value instanceof u.DataTable) {
|
30 | return _value.rows.peek();
|
31 | } else {
|
32 | return _value;
|
33 | }
|
34 | } else {
|
35 | if (_value instanceof u.DataTable) {
|
36 | _value = _value.getCurrentRow();
|
37 | if (!_value)
|
38 | return '';
|
39 | else
|
40 | return _value.getChildValue(fieldName.replace(_name + '.', ''))
|
41 | } else {
|
42 | _name = _name + '.' + nameArr[i + 1];
|
43 | }
|
44 |
|
45 | }
|
46 | }
|
47 | return '';
|
48 | };
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | const getData = function() {
|
59 | var data = ko.toJS(this.data)
|
60 | var meta = this.parent.getMeta()
|
61 | for (var key in meta) {
|
62 | if (meta[key] && meta[key].type) {
|
63 | if (meta[key].type == 'date' || meta[key].type == 'datetime') {
|
64 | if (key.indexOf('.') > 0) {
|
65 | var keys = key.split('.');
|
66 | var _keyValue = data;
|
67 | for (var i = 0, count = keys.length; i < count; i++) {
|
68 | _keyValue = _keyValue[keys[i]];
|
69 | }
|
70 | _keyValue.value = rowUtilFunObj._dateToUTCString(_keyValue.value);
|
71 |
|
72 | } else {
|
73 | data[key].value = rowUtilFunObj._dateToUTCString(data[key].value)
|
74 | }
|
75 | } else if (meta[key].type == 'child') {
|
76 | var chiddt = this.getValue(key),
|
77 | rs = chiddt.rows(),
|
78 | cds = [];
|
79 | for (var i = 0; i < rs.length; i++) {
|
80 | cds.push(rs[i].getData());
|
81 | }
|
82 | data[key].value = JSON.stringify(cds);
|
83 | }
|
84 | }
|
85 | }
|
86 | return {
|
87 | 'id': this.rowId,
|
88 | 'status': this.status,
|
89 | data: data
|
90 | }
|
91 | }
|
92 |
|
93 |
|
94 | const getEmptyData = function() {
|
95 | return {
|
96 | 'id': this.rowId,
|
97 | 'status': this.status,
|
98 | data: {}
|
99 | }
|
100 | };
|
101 |
|
102 | export const rowGetDataFunObj = {
|
103 | getValue: getValue,
|
104 | getChildValue: getChildValue,
|
105 | getData: getData,
|
106 | getEmptyData: getEmptyData
|
107 | }
|