summaryrefslogtreecommitdiffstats
path: root/pywrap/templates/base.html
blob: fdb95e8f1bfb274b97537320686c49e89d19174a (plain)
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<html>
<head>
	<title>{% block title %}Device {{ device }}{% endblock %}</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<link rel="stylesheet" type="text/css" href="codebase/dhtmlx.css"/>
   <script type=text/javascript src="{{ url_for('static', filename='jquery-2.2.1.js') }}"></script>
	<script src="codebase/dhtmlx.js"></script>
   <script src="pcilib_tree.js"></script>
	<script>
      var propsTree
      
      function checkError(json)
      {
         if(json.error)
            alert('Error:\n' + json.error)
      }
      
      function createPropertyTree(branch, id)
      {
         function getPropertyItemsOnLevel(branch, id)
         {
            pathToProperties = "{{ url_for('get_property_list_json') }}"
            completePath = pathToProperties + '?branch=' + branch
            
            $.getJSON(completePath, 
                      function(json) {
                         checkError(json)
                         parsePropertyItems(json, branch, id)
                         });
         }
         
         function parsePropertyItems(json, branch, id)
         {
            function updatePropertyValue(id, path)
            {
               pathToGetProperty = "{{ url_for('get_property_json') }}"
               completePath = pathToGetProperty + '?prop=' + path
               
               $.getJSON(completePath, function(json){
                           checkError(json)
                           propsTree.updateItem(id, 'value: ' + json.value);
                        })
            }
         
            function writePropertyValue(id, path)
            {
               value = window.prompt("Enter new property value");
               
               if(value != null)
               {
                  pathToGetProperty = "{{ url_for('set_property_json') }}"
                  completePath = pathToGetProperty + '?prop=' + path +'&val=' + value
                  
                  $.getJSON(completePath, 
                            function(json) {
                              checkError(json)
                              updatePropertyValue(id, path)
                             })
               }
               else
                  updatePropertyValue(id, path)
            }
            
            function setCurrentValueField(id, path, mode)
            {
               var propValId = id + 'CurrVal'
               var func = 0
               
               if(mode)
                  func = function(){writePropertyValue(propValId, path)}
               else
                  func = function(){updatePropertyValue(propValId, path)}
                  
               propsTree.insertNewItem(id, propValId,
                                    'value: ', 
                                    func);
               
               updatePropertyValue(propValId, path)
            }
            
            for(var i = 0; i < json.length; i++)
            {
               propsTree.insertNewItem(id, json[i].path, json[i].name, 0);
               
               if(json[i].flags.indexOf("childs") != -1)
               {
                  getPropertyItemsOnLevel(json[i].path, json[i].path)
               }
               else
               {
                  if(json[i].mode.indexOf("R") != -1)
                  {
                     var mode = (json[i].mode.indexOf("W") != -1)
                     setCurrentValueField(json[i].path, json[i].path, mode)
                  }
               }
               
               //show aviable info
               if(json[i].description)
                  propsTree.insertNewItem(json[i].path, json[i].path + 'Desc',
                                       'description:\n' + json[i].description, 0);
               if(json[i].type)
                  propsTree.insertNewItem(json[i].path, json[i].path + 'Type',
                                       'type: ' + json[i].type, 0);
               if(json[i].unit)
                  propsTree.insertNewItem(json[i].path, json[i].path + 'Unit',
                                       'unit: ' + json[i].unit, 0);
                                       
               if(json[i].mode)
               {
                  var modeId = json[i].path + 'Mode'
                  propsTree.insertNewItem(json[i].path, modeId,
                                       'mode', 0);
                  
                  for(var j = 0; j < json[i].mode.length; j++)
                     propsTree.insertNewItem(modeId, modeId + j,
                                       json[i].mode[j], 0);
                  propsTree.closeItem(modeId)
               }
               
               if(json[i].path)
                  propsTree.insertNewItem(json[i].path, json[i].path + 'Path',
                                       'path: ' + json[i].path, 0);
                                       
               propsTree.closeItem(json[i].path);
            }  
      }
         
         getPropertyItemsOnLevel(branch, id)
      }
      
      var regTree
      function createRegistersList()
      {
         function parseJsonRegisterList(json)
         {
            checkError(json)
            
            function compareRegistersByBank(a,b) 
            {
               if (a.bank < b.bank)
                  return -1;
               else if (a.bank > b.bank)
                  return 1;
               else 
                  return 0;
            }
            
            if(json.lenght <= 0)
               return
            
            //sort registers by bank
            json.sort(compareRegistersByBank)
            
            //create bank dirs
            var curBankName = json[0].bank
            var created = 0
            for(var i = 0; i < json.length; i++)
            {
               //create new bank tab if it has not created already
               if(json[i].bank != curBankName)
               {
                  curBankName = json[i].bank
                  created = 0
               }
               if(!created)
               {
                  regTree.insertNewItem(0, json[i].bank, json[i].bank, 0);
                  created = 1
               }
               
               //insert register info to bank
               var itemId = json[i].bank + "_" + json[i].name
               regTree.insertNewItem(json[i].bank, itemId, json[i].name)
               
               function updateRegisterValue(id, bank, name)
               {
                  pathToGetProperty = "{{ url_for('read_register_json') }}"
                  completePath = pathToGetProperty + '?bank=' + bank +
                                 '&name=' + name
                  
                  $.getJSON(completePath, function(json){
                              checkError(json)
                              regTree.updateItem(id, 'value: ' + json.value);
                           })
               }
         

               function writeRegisterValue(id, bank, name)
               {
                  value = window.prompt("Enter new register value");
                  
                  if(value != null)
                  {
                     pathToGetProperty = "{{ url_for('write_register_json') }}"
                     completePath = pathToGetProperty + '?bank=' + bank +
                                    '&name=' + name + '&val=' + value;
                     
                     $.getJSON(completePath, 
                               function(json) {
                                 checkError(json)
                                 updateRegisterValue(id, bank, name)
                                })
                  }
                  else
                     updateRegisterValue(id, bank, name)
               }

               function setCurrentValueField(id, bank, name, mode)
               {
                  var regValId = id + 'CurrVal'
                  var func = 0
                  
                  if(mode)
                     func = function(){writeRegisterValue(regValId, bank, name)}
                  else
                     func = function(){updateRegisterValue(regValId, bank, name)}
                     
                  regTree.insertNewItem(id, regValId,
                                       'value: ', 
                                       func);
                  updateRegisterValue(regValId, bank, name)
               }
               
               if(json[i].mode.indexOf("R") != -1)
               {
                  var mode = (json[i].mode.indexOf("W") != -1)
                  setCurrentValueField(itemId, json[i].bank, json[i].name, mode)
               }
               
               //show aviable info
               if(json[i].description)
                  regTree.insertNewItem(itemId, itemId + 'Desc',
                                        'description:\n' + json[i].description, 0);
               if(json[i].defvalue)
                  regTree.insertNewItem(itemId, itemId + 'Defvalue',
                                       'defvalue: ' + json[i].defvalue, 0);
               
               if(json[i].mode)
               {
                  var modeId = itemId + 'Mode'
                  regTree.insertNewItem(itemId, modeId,
                                       'mode', 0);
                  
                  for(var j = 0; j < json[i].mode.length; j++)
                     regTree.insertNewItem(modeId, modeId + j,
                                       json[i].mode[j], 0);
                  regTree.closeItem(modeId)
               }
               
               if(json[i].range)
               {
                  var rangeId = itemId + 'Range'
                  regTree.insertNewItem(itemId, rangeId,
                                       'range', 0);
                  regTree.insertNewItem(rangeId, rangeId + 'Min',
                                       'min: ' + json[i].range.min, 0);
                  regTree.insertNewItem(rangeId, rangeId + 'Max',
                                       'max: ' + json[i].range.max, 0);
                  regTree.closeItem(rangeId)
               }
               
               if(json[i].values)
               {
                  var valuesId = itemId + 'Values'
                  regTree.insertNewItem(itemId, valuesId,
                                       'values', 0);
                                       
                  function addValueInfo(valuesId, value)
                  {
                     var valueId = valuesId + value.name
                     regTree.insertNewItem(valuesId, valueId, value.name, 0);
                     
                     if(value.description)
                        regTree.insertNewItem(valueId, valueId + 'Desc',
                                              'description: ' + value.description, 0);
                     if(value.value)
                        regTree.insertNewItem(valueId, valueId + 'Value',
                                              'value: ' + value.value, 0);
                     if(value.min)
                        regTree.insertNewItem(valueId, valueId + 'Min',
                                              'min: ' + value.min, 0);
                     if(value.max)
                        regTree.insertNewItem(valueId, valueId + 'Max',
                                              'max: ' + value.max, 0);   
                  }
                  
                  for(var j = 0; j < json[i].values.length; j++)
                  {
                     addValueInfo(valuesId, json[i].values[j])
                  }
                  regTree.closeItem(valuesId)
               }
                                       
               propsTree.closeItem(json[i].path);
               
               regTree.closeItem(itemId);
            }
         }
         
         //get registers json list
         getRegistersListPath = "{{ url_for('get_registers_list_json') }}" 
         $.getJSON(getRegistersListPath, parseJsonRegisterList);
      }
      
		function doOnLoad()
      {
			propsTree = new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
			propsTree.setImagePath("codebase/imgs/dhxtree_skyblue/");
         //generating properties list
         createPropertyTree('', 0)
         
			regTree = new dhtmlXTreeObject("treeboxbox_tree2","100%","100%",0,0,0,0,'SELECT')
			regTree.setImagePath("codebase/imgs/dhxtree_skyblue/");
         createRegistersList()
		}
	</script>
</head>
<body onload="doOnLoad()">
	{% block info %}
      <h2>Device {{ device }} model={{ model }} control page </h2>
   {% endblock %}
   
   {% block content %}
   {% endblock %}
	<table>
		<tr>
         <td>
            <h3>Properties Tree</h3>
         </td>
         <td>
            <h3>Registers Tree</h3>
         </td>
		</tr>
		<tr>
         <td valign="top">
				<div id="treeboxbox_tree" style="background-color:#f5f5f5;border :1px solid Silver; overflow:auto;"></div>
			</td>
			<td valign="top">
				<div id="treeboxbox_tree2" style="background-color:#f5f5f5;border :1px solid Silver; overflow:auto;"></div>
			</td>
		</tr>
	</table>
</body>
</html>