-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
274 lines (257 loc) · 7.06 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/**
* @file mofron-comp-radio/index.js
* @brief radio button component for mofron
* @feature text size is automatically changed when the height is changed.
* @license MIT
*/
const FormItem = require('mofron-comp-formitem');
const Text = require("mofron-comp-text");
const onCommon = require("mofron-event-oncommon");
const Common = require("mofron-event-common");
const Click = require("mofron-event-click");
const ConfArg = mofron.class.ConfArg;
const comutl = mofron.util.common;
module.exports = class extends FormItem {
/**
* initialize radio component
*
* @param (mixed) short-form parameter
* key-value: component config
* @short text
* @type private
*/
constructor (prm) {
try {
super();
this.modname("Radio");
this.shortForm("text");
this.confmng().add('group', { type:'string' });
this.confmng().add('select',{ type:'boolean', init:false });
/* set config */
if (undefined !== prm) {
this.config(prm);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* initialize dom contents
*
* @type private
*/
initDomConts () {
try {
super.initDomConts();
this.horizon(true);
let chk = new mofron.class.Dom({
tag: "input", component: this,
attrs : { type : "radio" }
});
this.child(
new mofron.class.Component({
style: { "display" : "flex" },
childDom: new mofron.class.PullConf({ child: chk }),
child: this.text()
})
);
this.childDom(chk);
/* set change event */
let val_chg = (v1,v2,v3) => {
let chg_evt = v1.changeEvent();
for (let cidx in chg_evt) {
chg_evt[cidx][0](v1, true, chg_evt[cidx][1]);
}
setTimeout(() => {
v1.data('select_buff', true);
},500);
};
this.event(new onCommon(val_chg,"onchange"), { private:true });
} catch (e) {
console.error(e.stack);
throw e;
}
}
afterRender () {
try {
super.afterRender();
if (null !== this.group()) {
this.childDom().attrs({ "name" : this.group() });
let grp_buf = mofron.root[0].data('mofron-comp-radio_group_' + this.group());
if (null === grp_buf) {
mofron.root[0].data('mofron-comp-radio_group_' + this.group(), [this]);
} else {
grp_buf.push(this);
}
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* radio text
*
* @param (mixed) string: radio text contents
* mofron-comp-text: radio text contents
* undefined: call as getter
* @return (mofron-comp-text) radio text contents
* @type prameter
*/
text (prm,cnf) {
try {
if (true === comutl.isinc(prm, "Text")) {
prm.event(
new Click(new ConfArg(
(cp1,cp2,cp3) => {
cp3.childDom().getRawDom().click();
},
this
))
);
prm.config(cnf);
} else if ('string' === typeof prm) {
this.text().text(prm);
this.text().config(cnf);
return;
}
return this.innerComp('text', prm, Text);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* select status
*
* @param (boolean) true: select
* false: unselect
* undefined: call as getter
* @return (boolean) select status
* @type parameter
*/
select (flg) {
try {
this.confmng('select',flg);
let sts = this.childDom().props("checked");
if (undefined === flg) {
return sts;
}
/* setter */
if ("boolean" !== typeof flg) {
throw new Error("invalid parameter");
}
this.childDom().props({ checked : flg });
if (flg !== sts) {
let chg_evt = this.changeEvent();
for (let cidx in chg_evt) {
chg_evt[cidx][0](this, flg, chg_evt[cidx][1]);
}
}
this.data('select_buff', flg);
} catch (e) {
console.error(e.stack);
throw e;
}
}
selectEvent (fnc,prm) {
try {
let sel_evt = (s1,s2,s3) => {
try {
if ((true === s2) && ('function' === typeof fnc)) {
fnc(s1,s2,s3);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
return this.changeEvent(sel_evt,prm);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* select status
*
* @param (boolean) same as 'select'
* @return (boolean) select status
* @type parameter
*/
value (prm) {
try {
return this.select(prm);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* clear select
*
* @type function
*/
clear () {
try {
this.select(false);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* radio button size
*
* @param (string(size)) radio button size (both height and width)
* undefined: call as getter
* @return (mixed) string(size): radio button size
* null: not set
* @type parameter
*/
size (wid,hei) {
try {
if (0 === arguments.length) {
return super.width();
} else if (1 === arguments.length) {
super.size(wid, wid);
} else {
super.size(wid, hei);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* radio button height
*
* @param (string(size)) radio button height
* undefined: call as getter
* @return (mixed) string(size): radio button height
* null: not set
* @type parameter
*/
height (prm) {
try {
let ret = super.height(prm);
if (undefined !== prm) {
this.text().size(prm);
}
return ret;
} catch (e) {
console.error(e.stack);
throw e;
}
}
group (prm) {
try {
return this.confmng('group', prm);
} catch (e) {
console.error(e.stack);
throw e;
}
}
}
/* end of file */