-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcept.coffee
192 lines (171 loc) · 5.73 KB
/
concept.coffee
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
conceptBuilder = (json) ->
switch json.dataType
when "DvQuantity"
new DvQuantity(json)
when "DV_CODED_TEXT"
new DvCodedText(json)
when "DV_BOOLEAN"
new DvBoolean(json)
when "DV_TEXT"
new DvText(json)
when "DV_COUNT"
new DvCount(json)
when "DvOrdinal"
new DvOrdinal(json)
when "DV_MULTIMEDIA"
new DvMultiMedia(json)
when "DV_DATE_TIME"
new DvDateTime(json)
when "DV_INTERVAL"
new DvInterval(json)
when "DV_PROPORTION"
new DvProportion(json)
when "DV_URI"
new DvUri(json)
when "DvMultipleElements"
new DvMultipleElements(json)
when "DvCluster"
new DvCluster(json)
else
new DvAny(json)
class Concept
constructor: (json) ->
@name = json.name
@path = json.path.replace(/\./g, "___")
@type = json.dataType
# <input type="text" value="@value" aqbe:path="@path" />
inputBuilder: (placeholder="") ->
$("<input>").attr("type", "text").attr("value", "").attr("aqbe:path", @path).attr("aqbe:type", @type).attr("placeholder", placeholder)
# <input type="text" value="@value" aqbe:path="@path" id="fieldDate" />
calenderBuilder: () ->
@inputBuilder().attr("id", "fieldDate")
# <select aqbe:path="@path"><option value="">Please Select</option></select>
selectBuilder: (path=@path, type=@type, require=false) ->
selecter = $("<select>").attr("aqbe:path", path).attr("aqbe:type", type)
if require
selecter
else
selecter.append("""<option value="">Please Select</option>""")
getHtml: ->
$("<tr>").append($("<td>").text(@name))
class DvQuantity extends Concept
constructor: (json) ->
super json
@path = @path + "/magnitude"
@unitPath = @path.replace("/magnitude", "/units")
@min = if json.min[0]? then json.min else [-999999]
@max = if json.max[0]? then json.max else [999999]
@unit = json.unit
getHtml: ->
input = @inputBuilder("0.0").attr("aqbe:min", @min[0]).attr("aqbe:max", @max[0])
unitSelecter = @selectBuilder(path=@unitPath, type="DvQuantityUnit", require=true)
for k, v in @unit
unitSelecter.append("<option value=\"#{v}\">#{k}</option>")
unitSelecter.change =>
index = unitSelecter.val()
$(input).attr("aqbe:min", @min[index]).attr("aqbe:max", @max[index])
super.append($("<td>").append(input).append(" ").append(unitSelecter).append("<span class=\"error\">"))
class DvCodedText extends Concept
constructor: (json) ->
super json
@codeList = json.codeList
getHtml: ->
select = @selectBuilder()
for code in @codeList
select.append("<option value=\"#{code}\">#{code}</option>")
super.append($("<td>").append(select))
class DvBoolean extends Concept
constructor: (json) ->
super json
getHtml: ->
super.append($("<td>").append(@selectBuilder().append("""<option value="true">true</option>""").append("""<option value="false">false</option>""")))
class DvText extends Concept
constructor: (json) ->
super json
getHtml: ->
super.append($("<td>").append(@inputBuilder("Freetext")))
class DvCount extends Concept
constructor: (json) ->
super json
@min = if json.min? then json.min else -999999
@max = if json.max? then json.max else 999999
getHtml: ->
super.append($("<td>").append(@inputBuilder("0").attr("aqbe:min", @min).attr("aqbe:max", @max)).append("<span class=\"error\">"))
class DvOrdinal extends Concept
constructor: (json) ->
super json
@codeList = json.codeList
getHtml: ->
select = @selectBuilder()
for c in @codeList
select.append("<option value=\"#{c._1}\">#{c._2}</option>")
super.append($("<td>").append(select))
class DvMultiMedia extends Concept
constructor: (json) ->
super json
@codeList = json.codeList
getHtml: ->
select = @selectBuilder()
for c in @codeList
select.append("<option value=\"#{c}\">#{c}</option>")
super.append($("<td>").append(select))
class DvDateTime extends Concept
constructor: (json) ->
super json
getHtml: ->
super.append($("<td>").append(@calenderBuilder("Date Time")).append("""<input type="hidden" value="" aqbe:type="DvDateTimeInteger" aqbe:path=""" + @path + """ />"""))
class DvInterval extends Concept
constructor: (json) ->
super json
@interval = json.interval
getHtml: ->
newTable = $("<table>").attr("class", "adl")
for c in @interval
cc = conceptBuilder(c)
newTable.append(cc.getHtml())
super.append($("<td>").append(newTable))
class DvProportion extends Concept
constructor: (json) ->
super json
@minNum = json.minNum
@maxNum = json.maxNum
@minDen = json.minDen
@maxDen = json.maxDen
getHtml: ->
@min = @minNum
@max = @maxNum
num = @inputBuilder("0")
@min = @minDen
@max = @maxNum
den = @inputBuilder("0")
super.append($("<td>").append(num.append(" : ").den))
class DvUri extends Concept
constructor: (json) ->
super json
getHtml: ->
super.append($("<td>").append(@inputBuilder("input", "url").attr("placeholder", "URL")))
class DvAny extends Concept
constructor: (json) ->
super json
getHtml: ->
super.append($("<td>").append("""<span class="any">[Any]<span>"""))
class DvCluster extends Concept
constructor: (json) ->
super json
@cluster = json.cluster
getHtml: ->
newTable = $("<table>").attr("class", "adl2")
for c in @cluster
cc = conceptBuilder(c)
newTable.append(cc.getHtml())
super.append($("<td>").append(newTable))
class DvMultipleElements extends Concept
constructor: (json) ->
super json
@elements = json.elements
getHtml: ->
newTable = $("<table>").attr("class", "adl2")
for c in @elements
cc = conceptBuilder(c._2)
newTable.append(cc.getHtml())
super.append($("<td>").append(newTable))