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