-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
175 lines (166 loc) · 4.84 KB
/
index.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
* @file GridList.js
* @brief grid list component for mofron
*/
const mf = require('mofron');
const Menu = require('mofron-comp-menu');
const Click = require('mofron-event-click');
const Grid = require('mofron-layout-grid');
const Hrzcnt = require('mofron-layout-hrzcenter');
mf.comp.GridList = class extends mf.Component {
constructor (po) {
try {
super();
this.name('GridList');
this.prmOpt(po);
} catch (e) {
console.error(e.stack);
throw e;
}
}
initDomConts (prm) {
try {
super.initDomConts();
this.addLayout(this.grid());
} catch (e) {
console.error(e.stack);
throw e;
}
}
rate (prm) {
try {
if (undefined === prm) {
/* getter */
if (undefined === this.m_rate) {
this.rate(90);
}
return this.m_rate;
}
/* setter */
if ('number' !== typeof prm) {
throw new Error('invalid parameter');
}
this.m_rate = prm;
} catch (e) {
console.error(e.stack);
throw e;
}
}
addChild(chd, idx) {
try {
let clk = (p1, p2) => {
try {
let chd = p2.child();
for (let cidx in chd) {
if (p1.getId() === chd[cidx].child()[0].getId()) {
p2.execSelect(parseInt(cidx));
}
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
chd.execOption({ event : [ new Click(new mf.Param(clk, this)) ] });
let wrap = new mf.Component({
child : [ chd ],
layout : (0 !== this.rate()) ? [ new Hrzcnt(this.rate()) ] : undefined
});
super.addChild(wrap, idx);
} catch (e) {
console.error(e.stack);
throw e;
}
}
selectIndex (idx) {
try {
if (undefined === idx) {
/* getter */
return (undefined === this.m_selidx) ? null : this.m_selidx;
}
/* setter */
if (('number' !== typeof idx) || (undefined === this.child()[idx])) {
throw new Error('invalid parameter : ' + idx);
}
this.child()[idx].eventTgt().getRawDom.click();
} catch (e) {
console.error(e.stack);
throw e;
}
}
selectEvent (evt, prm) {
try {
if (undefined === evt) {
/* getter */
return (undefined === this.m_selevt) ? [] : this.m_selevt;
}
/* setter */
if ('function' !== (typeof evt)) {
throw new Error('invalid parameter');
}
if (undefined === this.m_selevt) {
this.m_selevt = [];
}
this.m_selevt.push([evt, prm]);
} catch (e) {
console.error(e.stack);
throw e;
}
}
execSelect (idx) {
try {
if (('number' !== typeof idx) || (undefined === this.child()[idx])) {
throw new Error('invalid parameter : ' + idx);
}
this.m_selidx = idx;
let evt = this.selectEvent();
for (let eidx in evt) {
evt[eidx][0](idx, evt[eidx][1], this);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
column (prm) {
try {
if (undefined === prm) {
/* getter */
return this.grid().rate().length();
}
/* setter */
if (('number' !== typeof prm) || (0 === prm) || (100 < prm)) {
throw new Error('invalid parameter');
}
let rate = [];
for (let idx=0; idx < prm ;idx++) {
rate.push(100/prm);
}
this.grid().rate(rate);
} catch (e) {
console.error(e.stack);
throw e;
}
}
grid (prm) {
try {
if (undefined === prm) {
/* getter */
if (undefined === this.m_grid) {
this.grid(new Grid());
}
return this.m_grid;
}
/* setter */
if (true !== mf.func.isInclude(prm, 'Grid')) {
throw new Error('invalid parameter');
}
this.m_grid = prm;
} catch (e) {
console.error(e.stack);
throw e;
}
}
}
module.exports = mf.comp.GridList;
/* end of file */