1 $group
2 #
3 # params
4 # { props
5 # string key
6 # string elementId
7 # string theme
8 # string language
9 # boolean readOnly
10 class EditorControl
11 ctor
12 param props
13 set this.props = props
14 set this.key = props.key
15 set this.elementId = props.elementId
16 set this.theme = props.theme || 'github'
17 set this.language = props.language || 'js'
18 set this.isSettingValue = false
19 m initialize
20 if this.editor
21 return
22 set this.editor
23 new AceEditor
24 {
25 @ key this.key
26 @ editorElementId this.elementId
27 @ width '100%'
28 @ height '100%'
29 _ this.editor.initialize
30 _ this.editor.setMime
31 @ this.language
32 _ this.editor.setTheme
33 @ this.theme
34 if this.props.readOnly
35 _ this.editor.readOnly
36 @ true
37 _ this.editor.on
38 @ 'change'
39 =>
40 param value
41 if this.isSettingValue == false
42 log 'editvaluechanged', this.key, value
43 emit( editvaluechanged)
44 @ key this.key
45 @ value value
46 @ defer true
47 on( seteditvalue)
48 var key = data.key
49 var value = data.value
50 log 'seteditvalue', key, value
51 if key === this.key
52 set this.isSettingValue = true
53 _ this.value
54 @ value
55 set this.isSettingValue = false
56 log 'EditorControl initialized'
57 m theme
58 param value
59 if typeof value === 'undefined'
60 return this.theme
61 else
62 _ this.editor.setTheme
63 @ value
64 set this.theme = value
65 m language
66 param value
67 if typeof value === 'undefined'
68 return this.language
69 else
70 _ this.editor.setMime
71 @ value
72 set this.language = value
73 m value
74 param value
75 if this.editor
76 if typeof value === 'undefined'
77 return
78 _ this.editor.getValue
79 else
80 _ this.editor.setValue
81 @ value