UNPKG

3.24 kBJavaScriptView Raw
1/**
2 * Module : Kero webpack entry row index
3 * Author : liuyk(liuyuekai@yonyou.com)
4 * Date : 2016-08-09 15:24:46
5 */
6
7import {
8 Events
9} from './indexEvents';
10
11
12import {
13 setValue,
14 setChildValue,
15 setChildSimpleDataByRowId,
16 setData,
17 updateRow
18} from './row-data';
19
20import {
21 getValue,
22 getChildValue,
23 getData,
24 getEmptyData
25} from './row-getData';
26
27import {
28 getMeta
29} from './row-getMeta';
30
31import {
32 formatValueFun,
33 getSimpleData
34} from './row-getSimpleData';
35
36import {
37 init
38} from './row-init';
39
40import {
41 setMeta
42} from './row-meta';
43
44import {
45 ref,
46 refMeta,
47 refCombo,
48 refDate,
49 refEnum
50} from './row-ref';
51
52import{
53 toggleSelect,
54 singleSelect,
55 multiSelect
56} from './row-rowSelect';
57
58import {
59 setSimpleData
60} from './row-simpleData';
61
62import {
63 formatValue, //需要最终产出,
64} from './row-util';
65
66
67class Row extends Events{
68 constructor(options){
69 super();
70 var self = this;
71 this.rowId = options['id'] || Row.getRandomRowId()
72 this.status = Row.STATUS.NEW
73 this.parent = options['parent']
74 this.initValue = null
75 this.data = {}
76 this.metaChange = {}//ko.observable(1)
77 this.valueChange = {};
78 this.currentRowChange = ko.observable(1);
79 this.selected = ko.pureComputed({
80 read: function () {
81 var index = this.parent.getRowIndex(this);
82 var selectindices = this.parent.getSelectedIndices();
83 return selectindices.indexOf(index) != -1;
84 },
85 owner: this
86
87 })
88 this.focused = ko.pureComputed({
89 read: function () {
90 var index = this.parent.getRowIndex(this);
91 var focusIndex = this.parent.getFocusIndex()
92 return focusIndex == index;
93 },
94 owner: this
95
96 })
97
98
99
100
101
102 this.init();
103 }
104}
105
106//data
107Row.prototype.setValue= setValue;
108Row.prototype.setChildValue= setChildValue;
109Row.prototype.setChildSimpleDataByRowId= setChildSimpleDataByRowId;
110Row.prototype.setData= setData;
111Row.prototype.updateRow= updateRow;
112
113//getData
114Row.prototype.getValue= getValue;
115Row.prototype.getChildValue= getChildValue;
116Row.prototype.getData= getData;
117Row.prototype.getEmptyData= getEmptyData;
118
119//getMeta
120Row.prototype.getMeta= getMeta;
121
122//getSimpleData
123Row.prototype.formatValueFun= formatValueFun;
124Row.prototype.getSimpleData= getSimpleData;
125
126//init
127Row.prototype.init= init;
128
129//meta
130Row.prototype.setMeta= setMeta;
131
132//ref
133Row.prototype.ref= ref;
134Row.prototype.refMeta= refMeta;
135Row.prototype.refCombo= refCombo;
136Row.prototype.refDate= refDate;
137Row.prototype.refEnum= refEnum;
138
139//rowSelect
140Row.prototype.toggleSelect= toggleSelect;
141Row.prototype.singleSelect= singleSelect;
142Row.prototype.multiSelect= multiSelect;
143
144//simpleData
145Row.prototype.setSimpleData= setSimpleData;
146
147//util
148Row.prototype.formatValue= formatValue;
149
150
151
152Row.STATUS = {
153 NORMAL: 'nrm',
154 UPDATE: 'upd',
155 NEW: 'new',
156 DELETE: 'del',
157 FALSE_DELETE: 'fdel'
158}
159
160/*
161 * 生成随机行id
162 * @private
163 */
164Row.getRandomRowId = function () {
165 var _id = setTimeout(function () {})
166 return _id + '';
167};
168
169
170
171export {
172 Row
173}