designer.html 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Designer</title>
  6. <meta name="description"
  7. content="Designer Drawing Block.">
  8. <link rel="stylesheet" href="{{ static_url("style.css") }}">
  9. <link rel="stylesheet" href="{{ static_url("jquery-ui.min.css") }}">
  10. <!--[if IE]>
  11. <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  12. <![endif]-->
  13. </head>
  14. <body>
  15. <div id="page_info">Designer Block. Generated by BORA 0.0.1</div>
  16. {% if "background" in data %}
  17. <img src="{{ static_url( data['background'] ) }}"></img>
  18. {% else %}
  19. <img src="{{ static_url( 'background.png' ) }}"></img>
  20. {% end %}
  21. <button class="button showhide" onclick="showhide()">Show/Hide</button>
  22. {% if data['style'] %}
  23. {% for key in data['style'] %}
  24. {% if data['style'][key]['type'] == "calc" %}
  25. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  26. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  27. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};'
  28. {% if "condition" in data['style'][key] %}
  29. data-cond="{{ data['style'][key]['condition'] }}"
  30. {% else%}position
  31. {% end%}
  32. {% if "formula" in data['style'][key] %}
  33. data-formula="{{ data['style'][key]['formula'] }}"
  34. {% else %}
  35. {% end %}
  36. {% if "lesser" in data['style'][key] %}
  37. data-lesser="{{ data['style'][key]['lesser'] }}"
  38. {% else %}
  39. {% end %}
  40. {% if "larger" in data['style'][key] %}
  41. data-larger="{{ data['style'][key]['larger'] }}"
  42. {% else %}
  43. {% end %}
  44. data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  45. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> XXX.XX <span class='unit_title' style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" > {{ data['style'][key]['unit']['title'] }}</span></span></p>
  46. </div>
  47. {% else %}
  48. {% end %}
  49. {% if data['style'][key]['type'] == "data" %}
  50. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  51. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  52. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};'
  53. {% if "condition" in data['style'][key] %}
  54. data-cond="{{ data['style'][key]['condition'] }}"
  55. {% else%}position
  56. {% end%}
  57. {% if "formula" in data['style'][key] %}
  58. data-formula="{{ data['style'][key]['formula'] }}"
  59. {% else %}
  60. {% end %}
  61. {% if "lesser" in data['style'][key] %}
  62. data-lesser="{{ data['style'][key]['lesser'] }}"
  63. {% else %}
  64. {% end %}
  65. {% if "larger" in data['style'][key] %}
  66. data-larger="{{ data['style'][key]['larger'] }}"
  67. {% else %}
  68. {% end %}
  69. {% if "exponential" in data['style'][key] %}
  70. data-exponential="{{ data['style'][key]['exponential'] }}"
  71. {% else %}
  72. {% end %}
  73. data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  74. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> XXX.XX <span class='unit_title' style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" > {{ data['style'][key]['unit']['title'] }}</span></span></p>
  75. </div>
  76. {% else %}
  77. {% end %}
  78. {% if data['style'][key]['type'] == "ventil" %}
  79. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  80. <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
  81. </div>
  82. {% else %}
  83. {% end %}
  84. {% if data['style'][key]['type'] == "commbit" %}
  85. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  86. <img width='100%' height='100%' src='{{ static_url("Bit_inactive.svg") }}'></img>
  87. </div>
  88. {% else %}
  89. {% end %}
  90. {% if data['style'][key]['type'] == "alarm" %}
  91. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  92. <img width='100%' height='100%' src='{{ static_url("alarm_inactive.svg") }}'></img>
  93. </div>
  94. {% else %}
  95. {% end %}
  96. {% if data['style'][key]['type'] == "integer-to-string" %}
  97. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  98. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  99. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};'
  100. {% if "cond" in data['style'][key] %}
  101. data-cond="{{ data['style'][key]['cond'] }}"
  102. {% else%}
  103. {% end%}
  104. data-dict="{{ data['style'][key]['dict'] }}" data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  105. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><br /><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}px; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval">??? </span></p>
  106. </div>
  107. {% else %}
  108. {% end %}
  109. {% if data['style'][key]['type'] == "header" %}
  110. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  111. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  112. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};' data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  113. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span></p>
  114. </div>
  115. {% else %}
  116. {% end %}
  117. {% end %}
  118. {% else %}
  119. {% end %}
  120. <div id="tool-btn">
  121. <span class="info">Variable</span>
  122. <select id="varname" style="font-size:16pt;">
  123. {% if data['index'] %}
  124. {% for key in data['index'] %}
  125. {% if key != "time" %}
  126. <option value={{ key }}>{{key}}</option>
  127. {% else %}
  128. {% end %}
  129. {% end %}
  130. {% else %}
  131. {% end %}
  132. </select>
  133. <span class="info">Type</span>
  134. <select id="vartype" style="font-size:16pt;">
  135. <option value="data">data</option>
  136. <option value="valve">valve</option>
  137. <option value="commbit">commbit</option>
  138. <option value="alarm">alarm</option>
  139. <option value="integer-to-string">integer-to-string</option>
  140. <option value="header">header</option>
  141. <option value="calc">calc</option>
  142. </select>
  143. <span class="info">Attribute</span>
  144. <select id="varattr" style="font-size:16pt;">
  145. <option value="normal">Normal</option>
  146. <option value="virtual">Virtual</option>
  147. </select>
  148. <span class="info">Virtual ID</span>
  149. <input type="text" id="virtual_id_text" placeholder="text" style="font-size:16pt; width=100px;"/>
  150. <br /><br />
  151. <span class="info">Title</span>:
  152. <input type="text" id="elem_title_text" placeholder="text" style="font-size:16pt; width=100px;"/>
  153. <input type="text" id="elem_title_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  154. <input type="text" id="elem_lesser_range" placeholder="smaller than (red)" style="font-size:16pt; width=100px;"/>
  155. <input type="text" id="elem_larger_range" placeholder="larger than (red)" style="font-size:16pt; width=100px;"/>
  156. <select id="elem_title_style" style="font-size:16pt;">
  157. <option value="400">normal</option>
  158. <option value="700">bold</option>
  159. </select>
  160. <br /><br />
  161. <span class="info">Value</span>
  162. <input type="text" id="elem_unit_text" placeholder="unit" style="font-size:16pt; width=100px;"/>
  163. <input type="text" id="elem_unit_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  164. <input type="text" id="elem_condition_range" placeholder="condition (red)" style="font-size:16pt; width=100px;"/>
  165. <input type="text" id="elem_formula" placeholder="Equation" style="font-size:16pt; width=100px;"/>
  166. <select id="elem_unit_style" style="font-size:16pt;">
  167. <option value="400">normal</option>
  168. <option value="700">bold</option>
  169. </select>
  170. <span class="info">Exp</span><input type="checkbox" id="elem_exponential" style="font-size:16pt; width:20px; height:20px;"/>
  171. <br /><br />
  172. <span class="info">Background colour</span>
  173. <input type="text" id="background_color" placeholder="hex code" style="font-size:16pt; width=100px;"/>
  174. <br /><br />
  175. <button class="button save" onclick="backup()">Backup</button>
  176. <button style="display:none;" id="buttonHighlight" class="button highlight" onclick="highlight({{ data['cache'] }})">Highlight</button>
  177. <button class="button add" onclick="add()">Add</button>
  178. <button class="button remove" onclick="myremove()">Remove</button>
  179. <button class="button save" onclick="mysave({{ data['cache'] }})">Save</button>
  180. </div>
  181. <!-- java script -->
  182. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  183. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  184. <script>
  185. function backup() {
  186. $.ajax({
  187. url: '/backup/',
  188. type: 'POST',
  189. success: function (response) {
  190. alert("Backup success!");
  191. },
  192. error: function () {
  193. console.log("Error.")
  194. }
  195. });
  196. }
  197. function showhide() {
  198. console.log("Show or Hide");
  199. $("#tool-btn").toggle();
  200. }
  201. function add() {
  202. console.log("add element");
  203. title_text = $("#elem_title_text").val();
  204. title_text = title_text.trim();
  205. title_color = "#000000";
  206. //title_color = $("#elem_title_color").val();
  207. title_size = $("#elem_title_size").val();
  208. title_style = $("#elem_title_style option:selected").val();
  209. unit_text = $("#elem_unit_text").val();
  210. unit_text = unit_text.trim();
  211. unit_color = "#000";
  212. //unit_color = $("#elem_unit_color").val();
  213. unit_size = $("#elem_unit_size").val();
  214. unit_style = $("#elem_unit_style option:selected").val();
  215. data_condition = $("#elem_condition_range").val();
  216. //data_max = $("#elem_max_range").val();
  217. data_formula = $("#elem_formula").val();
  218. virtual_id = $("#virtual_id_text").val();
  219. virtual_id = virtual_id.trim();
  220. if (virtual_id == "") {
  221. virtual_id = "0";
  222. }
  223. if ($('#elem_exponential').is(":checked")) {
  224. data_exponential = true;
  225. $("#"+key).attr("data-exponential", true);
  226. } else {
  227. data_exponential = false;
  228. $("#"+key).attr("data-exponential", false);
  229. }
  230. data_lesser = $("#elem_lesser_range").val();
  231. data_larger = $("#elem_larger_range").val();
  232. background_color = $("#background_color").val();
  233. varval = $( "#varname option:selected").val();
  234. varname = $("#varname option:selected").text();
  235. vartype = $("#vartype option:selected").val();
  236. varattr = $("#varattr option:selected").val();
  237. console.log("Selected");
  238. console.log(varattr);
  239. console.log(virtual_id);
  240. console.log(vartype);
  241. console.log(title_text, unit_text, background_color, varname, varval, vartype);
  242. if(($("#" + varname).length == 0) || (vartype=="header") || (vartype=="calc") || (varattr=="virtual")) {
  243. console.log("Must enter here");
  244. console.log(vartype);
  245. if (vartype == "data") {
  246. if (varattr=="virtual") {
  247. virtual_name = "virtual_" + varname + "_" + virtual_id;
  248. if ( $("#" + virtual_name).length > 0 ) {
  249. for (i = 0; i < 50; i++) {
  250. virtual_name = "virtual_" + varname + "_" + i.toString();
  251. console.log($("#" + virtual_name).length);
  252. if (!$("#" + virtual_name).length){
  253. break;
  254. }
  255. }
  256. }
  257. varname = virtual_name;
  258. }
  259. console.log("Data");
  260. html_text = "<div " +
  261. "style='position: absolute; " +
  262. "top:0; " +
  263. "left:0; " +
  264. "background-color:" + background_color + "'" +
  265. "class='varbox box_highlight' " +
  266. "id='" + varname +
  267. "' data-type='" + vartype +
  268. "' data-cond='" + data_condition +
  269. "' data-formula='" + data_formula +
  270. "' data-lesser='" + data_lesser +
  271. "' data-larger='" + data_larger +
  272. "' data-exponential='" + data_exponential +
  273. "'>" +
  274. "<p>" +
  275. "<span style='color: " + title_color + ";" +
  276. "font-size:" + title_size + "px; " +
  277. "font-weight: " + title_style + ";' " +
  278. "class='title'>" + title_text +
  279. " </span>" +
  280. "<span style='color: " + unit_color + "; " +
  281. "font-size:" + unit_size + "px; " +
  282. "font-weight: " + unit_style + ";' " +
  283. "class='varval'>XXX.XX </span>" +
  284. "<span class='unit_title'>" + unit_text + "</span></p>" +
  285. "</div>";
  286. } else if (vartype == "header") {
  287. console.log("Header");
  288. if (title_text.length > 0) {
  289. var clean_text = title_text.replace(/[^a-zA-Z0-9 ]/g, "")
  290. varname = "header_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  291. html_text = "<div " +
  292. "style='position: absolute; " +
  293. "top:0; " +
  294. "left:0; " +
  295. "background-color:" + background_color + "'" +
  296. "class='varbox box_highlight' " +
  297. "id='" + varname +
  298. "' data-type='" + vartype +
  299. "' data-cond='" + data_condition +
  300. "' data-lesser='" + data_lesser +
  301. "' data-larger='" + data_larger +
  302. "'>" +
  303. "<p>" +
  304. "<span style='color: " + title_color + ";" +
  305. "font-size:" + title_size + "px; " +
  306. "font-weight: " + title_style + ";' " +
  307. "class='title'>" + title_text +
  308. " </span></p>" +
  309. "</div>";
  310. $('#varname').append($('<option>', {
  311. value: varname,
  312. text: varname
  313. }));
  314. $('#varname').val(varname);
  315. $('#elem_title_text').removeClass('glowing_border');
  316. } else {
  317. console.log("NoInput");
  318. html_text = "";
  319. $('#elem_title_text').addClass('glowing_border');
  320. }
  321. } else if (vartype == "calc") {
  322. console.log("Calc");
  323. if (data_formula.length > 0) {
  324. var clean_text = data_formula.replace(/[^a-zA-Z0-9 ]/g, "")
  325. varname = "calc_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  326. console.log('Hi');
  327. console.log(varname);
  328. html_text = "<div " +
  329. "style='position: absolute; " +
  330. "top:0; " +
  331. "left:0; " +
  332. "background-color:" + background_color + "'" +
  333. "class='varbox box_highlight' " +
  334. "id='" + varname +
  335. "' data-type='" + vartype +
  336. "' data-cond='" + data_condition +
  337. "' data-lesser='" + data_lesser +
  338. "' data-larger='" + data_larger +
  339. "' data-formula='" + data_formula +
  340. "'>" +
  341. "<p>" +
  342. "<span style='color: " + title_color + ";" +
  343. "font-size:" + title_size + "px; " +
  344. "font-weight: " + title_style + ";' " +
  345. "class='title'>" + title_text +
  346. " </span>" +
  347. "<span style='color: " + unit_color + "; " +
  348. "font-size:" + unit_size + "px; " +
  349. "font-weight: " + unit_style + ";' " +
  350. "class='varval'>XXX.XX </span>" +
  351. "<span class='unit_title'>" + unit_text + "</span></p>" +
  352. "</div>";
  353. $('#varname').append($('<option>', {
  354. value: varname,
  355. text: varname
  356. }));
  357. $('#varname').val(varname);
  358. $('#elem_formula').removeClass('glowing_border');
  359. } else {
  360. console.log("NoInput");
  361. html_text = "";
  362. $('#elem_formula').addClass('glowing_border');
  363. }
  364. } else if (vartype == "valve") {
  365. if (varattr=="virtual") {
  366. virtual_name = "virtual_" + varname + "_" + virtual_id;
  367. if ( $("#" + virtual_name).length > 0 ) {
  368. for (i = 0; i < 50; i++) {
  369. virtual_name = "virtual_" + varname + "_" + i.toString();
  370. console.log($("#" + virtual_name).length);
  371. if (!$("#" + virtual_name).length){
  372. break;
  373. }
  374. }
  375. }
  376. varname = virtual_name;
  377. }
  378. console.log("Ventil");
  379. if (unit_text.length > 0) {
  380. var token = JSON.parse(unit_text);
  381. data_on = token["on"];
  382. data_off = token["off"];
  383. html_text = "<div " +
  384. "style='position: absolute; " +
  385. "top:0; " +
  386. "left:0;' " +
  387. "class='varbox box_highlight' " +
  388. "id='" + varname +
  389. "' data-type='" + vartype +
  390. "' data-cond='" + data_condition +
  391. "' data-lesser='" + data_lesser +
  392. "' data-larger='" + data_larger +
  393. "' data-on='" + data_on +
  394. "' data-off='" + data_off +
  395. "'>" +
  396. "<img width='100%' height='100%' " +
  397. "src='{{ static_url("ventil_inactive.png") }}'></img>" +
  398. "</div>";
  399. $('#elem_unit_text').removeClass('glowing_border');
  400. } else{
  401. console.log("NoInput");
  402. html_text = "";
  403. $('#elem_unit_text').addClass('glowing_border');
  404. }
  405. } else if (vartype == "commbit") {
  406. if (varattr=="virtual") {
  407. virtual_name = "virtual_" + varname + "_" + virtual_id;
  408. if ( $("#" + virtual_name).length > 0 ) {
  409. for (i = 0; i < 50; i++) {
  410. virtual_name = "virtual_" + varname + "_" + i.toString();
  411. console.log($("#" + virtual_name).length);
  412. if (!$("#" + virtual_name).length){
  413. break;
  414. }
  415. }
  416. }
  417. varname = virtual_name;
  418. }
  419. console.log("commbit");
  420. if (unit_text.length > 0) {
  421. var token = JSON.parse(unit_text);
  422. data_on = token["on"];
  423. data_off = token["off"];
  424. html_text = "<div " +
  425. "style='position: absolute; " +
  426. "top:0; " +
  427. "left:0;' " +
  428. "class='varbox box_highlight' " +
  429. "id='" + varname +
  430. "' data-type='" + vartype +
  431. "' data-cond='" + data_condition +
  432. "' data-lesser='" + data_lesser +
  433. "' data-larger='" + data_larger +
  434. "' data-on='" + data_on +
  435. "' data-off='" + data_off +
  436. "'>" +
  437. "<img width='100%' height='100%' " +
  438. "src='{{ static_url("Bit_inactive.svg") }}'></img>" +
  439. "</div>";
  440. $('#elem_unit_text').removeClass('glowing_border');
  441. } else{
  442. console.log("NoInput");
  443. html_text = "";
  444. $('#elem_unit_text').addClass('glowing_border');
  445. }
  446. } else if (vartype == "alarm") {
  447. if (varattr=="virtual") {
  448. virtual_name = "virtual_" + varname + "_" + virtual_id;
  449. if ( $("#" + virtual_name).length > 0 ) {
  450. for (i = 0; i < 50; i++) {
  451. virtual_name = "virtual_" + varname + "_" + i.toString();
  452. console.log($("#" + virtual_name).length);
  453. if (!$("#" + virtual_name).length){
  454. break;
  455. }
  456. }
  457. }
  458. varname = virtual_name;
  459. }
  460. console.log("alarm");
  461. if (unit_text.length > 0) {
  462. var token = JSON.parse(unit_text);
  463. data_on = token["on"];
  464. data_off = token["off"];
  465. html_text = "<div " +
  466. "style='position: absolute; " +
  467. "top:0; " +
  468. "left:0;' " +
  469. "class='varbox box_highlight' " +
  470. "id='" + varname +
  471. "' data-type='" + vartype +
  472. "' data-cond='" + data_condition +
  473. "' data-lesser='" + data_lesser +
  474. "' data-larger='" + data_larger +
  475. "' data-on='" + data_on +
  476. "' data-off='" + data_off +
  477. "'>" +
  478. "<img width='100%' height='100%' " +
  479. "src='{{ static_url("alarm_inactive.svg") }}'></img>" +
  480. "</div>";
  481. $('#elem_unit_text').removeClass('glowing_border');
  482. } else{
  483. console.log("NoInput");
  484. html_text = "";
  485. $('#elem_unit_text').addClass('glowing_border');
  486. }
  487. } else if (vartype == "integer-to-string") {
  488. console.log("Integer2String");
  489. if (unit_text.length > 0) {
  490. html_text = "<div " +
  491. "style='position: absolute; " +
  492. "top:0; " +
  493. "left:0; " +
  494. "background-color:" + background_color + "'" +
  495. "class='varbox box_highlight' " +
  496. "id='" + varname +
  497. "' data-type='" + vartype +
  498. "' data-dict='" + unit_text +
  499. "' data-cond='" + data_condition +
  500. "'>" +
  501. "<p>" +
  502. "<span style='color: " + title_color + ";" +
  503. "font-size:" + title_size + "px; " +
  504. "font-weight: " + title_style + ";' " +
  505. "class='title'>" + title_text +
  506. " </span><br />" +
  507. "<span style='color: " + unit_color + "; " +
  508. "font-size:" + unit_size + "px; " +
  509. "font-weight: " + unit_style + ";' " +
  510. "class='varval'>??? </span>" +
  511. "</p>" +
  512. "</div>";
  513. $('#elem_unit_text').removeClass('glowing_border');
  514. } else {
  515. console.log("NoInput");
  516. html_text = "";
  517. $('#elem_unit_text').addClass('glowing_border');
  518. }
  519. }
  520. console.log("Adding element");
  521. console.log(html_text);
  522. if (html_text.length > 0) {
  523. $( "body" ).append(html_text);
  524. $("#"+varname).draggable();
  525. $("#"+varname).resizable();
  526. }
  527. }
  528. }
  529. function myremove() {
  530. varname = $("#varname option:selected").text();
  531. vartype = $("#vartype option:selected").val();
  532. if($("#" + varname).length > 0) {
  533. $("#"+varname).remove();
  534. console.log(varname +" removed.");
  535. }
  536. }
  537. function mysave(data) {
  538. console.log("saving...");
  539. varname = $("#varname option:selected").text();
  540. varattr = $("#varattr option:selected").val();
  541. console.log("debug");
  542. console.log(varattr);
  543. var position = {};
  544. for(key in data) {
  545. var tmp = {};
  546. //console.log(key);
  547. if($("#" + key).length > 0 ) {
  548. tmp["ref"] = key;
  549. tmp["left"] = $("#"+key).css("left");
  550. tmp["top"] = $("#"+key).css("top");
  551. tmp["width"] = $("#"+key).width();
  552. tmp["height"] = $("#"+key).height();
  553. tmp["type"] = $("#"+key).attr("data-type");
  554. if ( $("#"+key).attr("data-type") == "data" ) {
  555. if ( (varname == key) && (varattr == "normal") ) {
  556. tmp["condition"] = $("#elem_condtion_range").val();
  557. tmp["formula"] = $("#elem_formula").val();
  558. tmp["lesser"] = $("#elem_lesser_range").val();
  559. tmp["larger"] = $("#elem_larger_range").val();
  560. if ($('#elem_exponential').is(":checked")) {
  561. tmp["exponential"] = true;
  562. } else {
  563. tmp["exponential"] = false;
  564. }
  565. if ($('#background_color').val().length > 0) {
  566. tmp["background_color"] = $('#background_color').val();
  567. } else {
  568. tmp["background_color"] = '#0000ffff';
  569. }
  570. console.log('Hi');
  571. console.log($("#"+key).css("background-color"));
  572. header = {};
  573. header["title"] = $("#elem_title_text").val().trim();
  574. //header["color"] = $(".title", "#"+key).css("color");
  575. header["size"] = $("#elem_title_size").val();
  576. header["weight"] = $("#elem_title_style").val();
  577. // update field
  578. $(".title", "#"+key).text(header["title"]);
  579. $(".title", "#"+key).css("font-size", header["size"] + "px");
  580. $(".title", "#"+key).css("font-weight", header["weight"]);
  581. unit = {};
  582. unit["title"] = $("#elem_unit_text").val().trim();
  583. //unit["color"] = $(".varval", "#"+key).css("color");
  584. unit["size"] = $("#elem_unit_size").val();
  585. unit["weight"] = $("#elem_unit_style").val();
  586. $(".varval", "#"+key).css("font-size", unit["size"] + "px");
  587. $(".unit_title", "#"+key).css("font-size", unit["size"] + "px");
  588. $(".unit_title", "#"+key).css("font-weight", unit["weight"]);
  589. $(".varval", "#"+key).css("font-weight", unit["weight"]);
  590. } else {
  591. tmp["condition"] = $("#"+key).attr("data-cond");
  592. tmp["formula"] = $("#"+key).attr("data-formula");
  593. tmp["lesser"] = $("#"+key).attr("data-lesser");
  594. tmp["larger"] = $("#"+key).attr("data-larger");
  595. tmp["exponential"] = $("#"+key).attr("data-exponential");
  596. //tmp["min"] = $("#"+key).attr("min");
  597. //tmp["max"] = $("#"+key).attr("max");
  598. header = {};
  599. header["title"] = $(".title", "#"+key).text();
  600. //header["color"] = $(".title", "#"+key).css("color");
  601. header["size"] = parseInt($(".title", "#"+key).css("font-size")) || 28;
  602. tmp["background_color"] = $("#"+key).css("background-color");
  603. var fontWeight = $(".title", "#"+key).css("font-weight");
  604. if (fontWeight == 'bold' || fontWeight == '700') {
  605. header["weight"] = "700";
  606. } else {
  607. header["weight"] = "400";
  608. }
  609. unit = {};
  610. unit["title"] = $(".unit_title", "#"+key).text();
  611. //unit["color"] = $(".varval", "#"+key).css("color");
  612. unit["size"] = parseInt($(".varval", "#"+key).css("font-size")) || 28;
  613. fontWeight = $(".varval", "#"+key).css("font-weight");
  614. if (fontWeight == 'bold' || fontWeight == '700') {
  615. unit["weight"] = "700";
  616. } else {
  617. unit["weight"] = "400";
  618. }
  619. }
  620. tmp["header"] = header;
  621. tmp["unit"] = unit;
  622. //} else if ( $("#"+key).attr("data-type") == "header" ) {
  623. // header = {};
  624. // header["title"] = $(".title", "#"+key).text();
  625. // header["size"] = $(".title", "#"+key).css("font-size");
  626. // header["weight"] = $(".title", "#"+key).css("font-weight");
  627. // tmp["header"] = header;
  628. } else if ( $("#"+key).attr("data-type") == "valve" ) {
  629. if ((varname == key) && (varattr == "normal")) {
  630. var unit_text = $("#elem_unit_text").val();
  631. unit_text = unit_text.trim();
  632. var dtoken = JSON.parse(unit_text);
  633. tmp["on"] = dtoken["on"];
  634. tmp["off"] = dtoken["off"];
  635. } else {
  636. tmp["on"] = $("#"+key).attr("data-on");
  637. tmp["off"] = $("#"+key).attr("data-off");
  638. }
  639. } else if ( $("#"+key).attr("data-type") == "commbit" ) {
  640. if ((varname == key) && (varattr == "normal")) {
  641. var unit_text = $("#elem_unit_text").val();
  642. unit_text = unit_text.trim();
  643. var dtoken = JSON.parse(unit_text);
  644. tmp["on"] = dtoken["on"];
  645. tmp["off"] = dtoken["off"];
  646. } else {
  647. tmp["on"] = $("#"+key).attr("data-on");
  648. tmp["off"] = $("#"+key).attr("data-off");
  649. }
  650. } else if ( $("#"+key).attr("data-type") == "alarm" ) {
  651. if ((varname == key) && (varattr == "normal")) {
  652. var unit_text = $("#elem_unit_text").val();
  653. unit_text = unit_text.trim();
  654. var dtoken = JSON.parse(unit_text);
  655. tmp["on"] = dtoken["on"];
  656. tmp["off"] = dtoken["off"];
  657. } else {
  658. tmp["on"] = $("#"+key).attr("data-on");
  659. tmp["off"] = $("#"+key).attr("data-off");
  660. }
  661. } else if ( $("#"+key).attr("data-type") == "integer-to-string" ) {
  662. if ((varname == key)&& (varattr == "normal")) {
  663. var unit_text = $("#elem_unit_text").val();
  664. unit_text = unit_text.trim();
  665. var data_condition = $("#elem_condition_range").val();
  666. tmp["cond"] = data_condition;
  667. tmp["dict"] = unit_text;
  668. if ($('#background_color').val().length > 0) {
  669. tmp["background_color"] = $('#background_color').val();
  670. } else {
  671. tmp["background_color"] = '#0000ffff';
  672. }
  673. header = {};
  674. header["title"] = $("#elem_title_text").val().trim();
  675. header["size"] = $("#elem_title_size").val();
  676. header["weight"] = $("#elem_title_style").val();
  677. unit = {};
  678. //unit["color"] = $(".varval", "#"+key).css("color");
  679. unit["size"] = $("#elem_unit_size").val();
  680. unit["weight"] = $("#elem_unit_style option:selected").val();
  681. } else {
  682. tmp["dict"] = $("#"+key).attr("data-dict");
  683. tmp["cond"] = $("#"+key).attr("data-cond");
  684. tmp["background_color"] = $("#"+key).css("background-color");
  685. header = {};
  686. header["title"] = $(".title", "#"+key).text();
  687. //header["color"] = $(".title", "#"+key).css("color");
  688. header["size"] = $(".title", "#"+key).css("font-size");
  689. header["weight"] = $(".title", "#"+key).css("font-weight");
  690. unit = {};
  691. //unit["title"] = $(".unit_title", "#"+key).text();
  692. //unit["color"] = $(".varval", "#"+key).css("color");
  693. unit["size"] = $(".varval", "#"+key).css("font-size");
  694. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  695. }
  696. tmp["header"] = header;
  697. tmp["unit"] = unit;
  698. }
  699. position[key] = tmp;
  700. }
  701. }
  702. var title_text = $("#elem_title_text").val();
  703. title_text = title_text.trim();
  704. var clean_text = title_text.replace(/[^a-zA-Z0-9 ]/g, "")
  705. var token = "header_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  706. $('[id^=virtual_]').each(function( index ) {
  707. var tmp = {};
  708. var key = this.id;
  709. var ref = key.split("_");
  710. ref.shift();
  711. ref.pop();
  712. ref = ref.join("_");
  713. //ref = ref[1];
  714. if (key != "virtual_id_text") {
  715. console.log("Check this");
  716. console.log(key);
  717. if($("#" + key).length > 0 ) {
  718. tmp["ref"] = ref;
  719. tmp["left"] = $("#"+key).css("left");
  720. tmp["top"] = $("#"+key).css("top");
  721. tmp["width"] = $("#"+key).width();
  722. tmp["height"] = $("#"+key).height();
  723. tmp["type"] = $("#"+key).attr("data-type");
  724. if ( $("#"+key).attr("data-type") == "data" ) {
  725. if (varname == key) {
  726. tmp["condition"] = $("#elem_condtion_range").val();
  727. tmp["formula"] = $("#elem_formula").val();
  728. tmp["lesser"] = $("#elem_lesser_range").val();
  729. tmp["larger"] = $("#elem_larger_range").val();
  730. header = {};
  731. header["title"] = $("#elem_title_text").val().trim();
  732. //header["color"] = $(".title", "#"+key).css("color");
  733. header["size"] = $("#elem_title_size").val();
  734. header["weight"] = $("#elem_title_style option:selected").val();
  735. if ($('#background_color').val().length > 0) {
  736. tmp["background_color"] = $('#background_color').val();
  737. } else {
  738. tmp["background_color"] = '#0000ffff';
  739. }
  740. // update field
  741. $(".title", "#"+key).css("font-size", header["size"] + "px");
  742. $(".title", "#"+key).css("font-weight", header["weight"] + "px");
  743. unit = {};
  744. unit["title"] = $("#elem_unit_text").val().trim();
  745. //unit["color"] = $(".varval", "#"+key).css("color");
  746. unit["size"] = $("#elem_unit_size").val();
  747. unit["weight"] = $("#elem_unit_style option:selected").val();
  748. // update field
  749. $(".varval", "#"+key).css("font-size", unit["size"] + "px");
  750. $(".unit_title", "#"+key).css("font-size", unit["size"] + "px");
  751. $(".varval", "#"+key).css("font-weight", unit["weight"] + "px");
  752. } else {
  753. tmp["condition"] = $("#"+key).attr("data-cond");
  754. tmp["formula"] = $("#"+key).attr("data-formula");
  755. tmp["lesser"] = $("#"+key).attr("data-lesser");
  756. tmp["larger"] = $("#"+key).attr("data-larger");
  757. //tmp["min"] = $("#"+key).attr("min");
  758. //tmp["max"] = $("#"+key).attr("max");
  759. tmp["background_color"] = $("#"+key).css("background-color");
  760. header = {};
  761. header["title"] = $(".title", "#"+key).text();
  762. //header["color"] = $(".title", "#"+key).css("color");
  763. header["size"] = parseInt($(".title", "#"+key).css("font-size")) || 28;
  764. header["weight"] = parseInt($(".title", "#"+key).css("font-weight")) || 28;
  765. unit = {};
  766. unit["title"] = $(".unit_title", "#"+key).text();
  767. //unit["color"] = $(".varval", "#"+key).css("color");
  768. unit["size"] = parseInt($(".varval", "#"+key).css("font-size")) || 28;
  769. unit["weight"] = parseInt($(".varval", "#"+key).css("font-weight")) || 28;
  770. }
  771. tmp["header"] = header;
  772. tmp["unit"] = unit;
  773. //} else if ( $("#"+key).attr("data-type") == "header" ) {
  774. // header = {};
  775. // header["title"] = $(".title", "#"+key).text();
  776. // header["size"] = $(".title", "#"+key).css("font-size");
  777. // header["weight"] = $(".title", "#"+key).css("font-weight");
  778. // tmp["header"] = header;
  779. } else if ( $("#"+key).attr("data-type") == "valve" ) {
  780. if (varname == key) {
  781. var unit_text = $("#elem_unit_text").val();
  782. unit_text = unit_text.trim();
  783. var dtoken = JSON.parse(unit_text);
  784. tmp["on"] = dtoken["on"];
  785. tmp["off"] = dtoken["off"];
  786. } else {
  787. tmp["on"] = $("#"+key).attr("data-on");
  788. tmp["off"] = $("#"+key).attr("data-off");
  789. }
  790. } else if ( $("#"+key).attr("data-type") == "commbit" ) {
  791. if (varname == key) {
  792. var unit_text = $("#elem_unit_text").val();
  793. unit_text = unit_text.trim();
  794. var dtoken = JSON.parse(unit_text);
  795. tmp["on"] = dtoken["on"];
  796. tmp["off"] = dtoken["off"];
  797. } else {
  798. tmp["on"] = $("#"+key).attr("data-on");
  799. tmp["off"] = $("#"+key).attr("data-off");
  800. }
  801. } else if ( $("#"+key).attr("data-type") == "alarm" ) {
  802. if (varname == key) {
  803. var unit_text = $("#elem_unit_text").val();
  804. unit_text = unit_text.trim();
  805. var dtoken = JSON.parse(unit_text);
  806. tmp["on"] = dtoken["on"];
  807. tmp["off"] = dtoken["off"];
  808. } else {
  809. tmp["on"] = $("#"+key).attr("data-on");
  810. tmp["off"] = $("#"+key).attr("data-off");
  811. }
  812. } else if ( $("#"+key).attr("data-type") == "integer-to-string" ) {
  813. if (varname == key) {
  814. var unit_text = $("#elem_unit_text").val();
  815. unit_text = unit_text.trim();
  816. var data_condition = $("#elem_condition_range").val();
  817. if ($('#background_color').val().length > 0) {
  818. tmp["background_color"] = $('#background_color').val();
  819. } else {
  820. tmp["background_color"] = '#0000ffff';
  821. }
  822. tmp["cond"] = data_condition;
  823. tmp["dict"] = unit_text;
  824. header = {};
  825. header["title"] = $("#elem_title_text").val().trim();
  826. header["size"] = $("#elem_title_size").val();
  827. header["weight"] = $("#elem_title_style option:selected").val();
  828. unit = {};
  829. //unit["color"] = $(".varval", "#"+key).css("color");
  830. unit["size"] = $("#elem_unit_size").val();
  831. unit["weight"] = $("#elem_unit_style option:selected").val();
  832. } else {
  833. tmp["dict"] = $("#"+key).attr("data-dict");
  834. tmp["cond"] = $("#"+key).attr("data-cond");
  835. tmp["background_color"] = $("#"+key).css("background-color");
  836. header = {};
  837. header["title"] = $(".title", "#"+key).text();
  838. //header["color"] = $(".title", "#"+key).css("color");
  839. header["size"] = $(".title", "#"+key).css("font-size");
  840. header["weight"] = $(".title", "#"+key).css("font-weight");
  841. unit = {};
  842. //unit["title"] = $(".unit_title", "#"+key).text();
  843. //unit["color"] = $(".varval", "#"+key).css("color");
  844. unit["size"] = $(".varval", "#"+key).css("font-size");
  845. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  846. }
  847. tmp["header"] = header;
  848. tmp["unit"] = unit;
  849. }
  850. position[key] = tmp;
  851. }
  852. }
  853. });
  854. $('[id^=header_]').each(function( index ) {
  855. tmp = {};
  856. var hkey = $( this ).attr('id');
  857. console.log('Hi');
  858. console.log(hkey);
  859. tmp["left"] = $("#"+hkey).css("left");
  860. tmp["top"] = $("#"+hkey).css("top");
  861. tmp["width"] = $("#"+hkey).width();
  862. tmp["height"] = $("#"+hkey).height();
  863. tmp["type"] = $("#"+hkey).attr("data-type");
  864. header = {};
  865. if (token == hkey) {
  866. header["title"] = $("#elem_title_text").val().trim();
  867. //header["color"] = $(".title", "#"+key).css("color");
  868. header["size"] = $("#elem_title_size").val();
  869. header["weight"] = $("#elem_title_style option:selected").val();
  870. if ($('#background_color').val().length > 0) {
  871. tmp["background_color"] = $('#background_color').val();
  872. } else {
  873. tmp["background_color"] = '#0000ffff';
  874. }
  875. // update field
  876. $(".title", "#"+hkey).css("font-size", header["size"] + "px");
  877. $(".title", "#"+hkey).css("font-weight", header["weight"]);
  878. } else {
  879. header["title"] = $(".title", "#"+hkey).text();
  880. //header["color"] = $(".title", "#"+hkey).css("color");
  881. header["size"] = parseInt($(".title", "#"+hkey).css("font-size")) || 28;
  882. header["weight"] = parseInt($(".title", "#"+hkey).css("font-weight")) || 28;
  883. tmp["background_color"] = $("#"+hkey).css("background-color");
  884. var fontWeight = $(".title", "#"+hkey).css("font-weight");
  885. if (fontWeight == 'bold' || fontWeight == '700') {
  886. header["weight"] = "700";
  887. } else {
  888. header["weight"] = "400";
  889. }
  890. }
  891. tmp["header"] = header;
  892. position[hkey] = tmp;
  893. //console.log( index + ": " + $( this ).text() );
  894. });
  895. $('[id^=calc_]').each(function( index ) {
  896. var tmp = {};
  897. var key = this.id;
  898. if($("#" + key).length > 0 ) {
  899. tmp["ref"] = "";
  900. tmp["left"] = $("#"+key).css("left");
  901. tmp["top"] = $("#"+key).css("top");
  902. tmp["width"] = $("#"+key).width();
  903. tmp["height"] = $("#"+key).height();
  904. tmp["type"] = $("#"+key).attr("data-type");
  905. if ( $("#"+key).attr("data-type") == "calc" ) {
  906. if (varname == key) {
  907. tmp["condition"] = $("#elem_condtion_range").val();
  908. tmp["formula"] = $("#elem_formula").val();
  909. tmp["lesser"] = $("#elem_lesser_range").val();
  910. tmp["larger"] = $("#elem_larger_range").val();
  911. header = {};
  912. header["title"] = $("#elem_title_text").val().trim();
  913. //header["color"] = $(".title", "#"+key).css("color");
  914. header["size"] = $("#elem_title_size").val();
  915. header["weight"] = $("#elem_title_style option:selected").val();
  916. if ($('#background_color').val().length > 0) {
  917. tmp["background_color"] = $('#background_color').val();
  918. } else {
  919. tmp["background_color"] = '#0000ffff';
  920. }
  921. unit = {};
  922. unit["title"] = $("#elem_unit_text").val().trim();
  923. //unit["color"] = $(".varval", "#"+key).css("color");
  924. unit["size"] = $("#elem_unit_size").val();
  925. unit["weight"] = $("#elem_unit_style option:selected").val();
  926. } else {
  927. tmp["condition"] = $("#"+key).attr("data-cond");
  928. tmp["formula"] = $("#"+key).attr("data-formula");
  929. tmp["lesser"] = $("#"+key).attr("data-lesser");
  930. tmp["larger"] = $("#"+key).attr("data-larger");
  931. //tmp["min"] = $("#"+key).attr("min");
  932. //tmp["max"] = $("#"+key).attr("max");
  933. tmp["background_color"] = $("#"+key).css("background-color");
  934. header = {};
  935. header["title"] = $(".title", "#"+key).text();
  936. //header["color"] = $(".title", "#"+key).css("color");
  937. header["size"] = $(".title", "#"+key).css("font-size");
  938. header["weight"] = $(".title", "#"+key).css("font-weight");
  939. unit = {};
  940. unit["title"] = $(".unit_title", "#"+key).text();
  941. //unit["color"] = $(".varval", "#"+key).css("color");
  942. unit["size"] = $(".varval", "#"+key).css("font-size");
  943. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  944. }
  945. tmp["header"] = header;
  946. tmp["unit"] = unit;
  947. }
  948. position[key] = tmp;
  949. }
  950. });
  951. console.log("Check here");
  952. //console.log(position);
  953. var dataToSend = JSON.stringify(position);
  954. console.log(dataToSend);
  955. $.ajax({
  956. url: '/save/',
  957. type: 'POST',
  958. data: dataToSend,
  959. success: function (response) {
  960. var objresponse = JSON.parse(response);
  961. console.log(objresponse);
  962. },
  963. error: function () {
  964. console.log("Error.")
  965. }
  966. });
  967. }
  968. function highlight(mydata) {
  969. console.log("highlight");
  970. varname = $("#varname option:selected").text();
  971. vartype = $("#"+varname).attr("data-type");
  972. $("#vartype").val(vartype);
  973. console.log(varname, vartype);
  974. // clear values
  975. $("#elem_title_text").val("");
  976. $("#elem_title_size").val("");
  977. $("#elem_unit_text").val("");
  978. $("#elem_unit_size").val("");
  979. $("#elem_lesser_range").val("");
  980. $("#elem_larger_range").val("");
  981. $("#elem_condition_range").val("");
  982. $("#elem_formula").val("");
  983. $("#virtual_id_text").val("");
  984. $("#background_color").val("");
  985. $('#elem_exponential').prop('checked', false);
  986. $('#elem_unit_text').removeClass('glowing_border');
  987. $('#elem_title_text').removeClass('glowing_border');
  988. $('#elem_formula').removeClass('glowing_border');
  989. if (vartype == "header") {
  990. $("#elem_title_text").val($("#"+varname + " .title").text());
  991. $("#elem_title_size").val(parseInt($("#"+varname + " .title").css("font-size")));
  992. $("#elem_title_style").val("400");
  993. var fontWeight = $("#"+varname + " .title").css("font-weight");
  994. if (fontWeight == 'bold' || fontWeight == '700') {
  995. $("#elem_title_style").val("700");
  996. }
  997. $("#elem_unit_style").val("400");
  998. var fontWeight = $("#"+varname + " .varval").css("font-weight");
  999. if (fontWeight == 'bold' || fontWeight == '700') {
  1000. $("#elem_unit_style").val("700");
  1001. }
  1002. $("#background_color").val("");
  1003. if ($("#"+varname).css("background-color") ) {
  1004. $("#background_color").val($("#"+varname).css("background-color"));
  1005. }
  1006. } else if (vartype == "data") {
  1007. if ($("#"+varname).attr("data-exponential")) {
  1008. $('#elem_exponential').prop('checked', true);
  1009. } else {
  1010. $('#elem_exponential').prop('checked', false);
  1011. }
  1012. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  1013. $("#elem_title_size").val("");
  1014. if ($("#"+varname + " .title").css("font-size")) {
  1015. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  1016. }
  1017. $("#elem_unit_text").val($("#"+varname + " .unit_title").text().trim());
  1018. $("#elem_unit_size").val("");
  1019. if ($("#"+varname + " .varval").css("font-size")) {
  1020. $("#elem_unit_size").val(parseFloat($("#"+varname + " .varval").css("font-size")));
  1021. }
  1022. $("#elem_lesser_range").val("");
  1023. if ($("#"+varname).attr("data-lesser") ) {
  1024. $("#elem_lesser_range").val($("#"+varname).attr("data-lesser"));
  1025. }
  1026. $("#elem_larger_range").val("");
  1027. if ($("#"+varname).attr("data-larger") ) {
  1028. $("#elem_larger_range").val($("#"+varname).attr("data-larger"));
  1029. }
  1030. $("#background_color").val("");
  1031. if ($("#"+varname).css("background-color") ) {
  1032. $("#background_color").val($("#"+varname).css("background-color"));
  1033. }
  1034. $("#elem_condition_range").val("");
  1035. if ($("#"+varname).attr("data-cond") ) {
  1036. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  1037. }
  1038. $("#elem_formula").val("");
  1039. if ($("#"+varname).attr("data-formula") ) {
  1040. $("#elem_formula").val($("#"+varname).attr("data-formula"));
  1041. }
  1042. $("#elem_title_style").val("400");
  1043. var fontWeight = $("#"+varname + " .title").css("font-weight");
  1044. if (fontWeight == 'bold' || fontWeight == '700') {
  1045. $("#elem_title_style").val("700");
  1046. }
  1047. $("#elem_unit_style").val("400");
  1048. var fontWeight = $("#"+varname + " .varval").css("font-weight");
  1049. if (fontWeight == 'bold' || fontWeight == '700') {
  1050. $("#elem_unit_style").val("700");
  1051. }
  1052. } else if (vartype == "calc") {
  1053. var vid = varname.split("_");
  1054. vid = vid[1];
  1055. $("#virtual_id_text").val(vid);
  1056. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  1057. $("#elem_title_size").val("");
  1058. if ($("#"+varname + " .title").css("font-size")) {
  1059. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  1060. }
  1061. $("#elem_unit_text").val($("#"+varname + " .unit_title").text().trim());
  1062. $("#elem_unit_size").val("");
  1063. if ($("#"+varname + " .varval").css("font-size")) {
  1064. $("#elem_unit_size").val(parseFloat($("#"+varname + " .varval").css("font-size")));
  1065. }
  1066. $("#elem_lesser_range").val("");
  1067. if ($("#"+varname).attr("data-lesser") ) {
  1068. $("#elem_lesser_range").val($("#"+varname).attr("data-lesser"));
  1069. }
  1070. $("#elem_larger_range").val("");
  1071. if ($("#"+varname).attr("data-larger") ) {
  1072. $("#elem_larger_range").val($("#"+varname).attr("data-larger"));
  1073. }
  1074. $("#elem_condition_range").val("");
  1075. if ($("#"+varname).attr("data-cond") ) {
  1076. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  1077. }
  1078. $("#elem_formula").val("");
  1079. if ($("#"+varname).attr("data-formula") ) {
  1080. $("#elem_formula").val($("#"+varname).attr("data-formula"));
  1081. }
  1082. $("#background_color").val("");
  1083. if ($("#"+varname).css("background-color") ) {
  1084. $("#background_color").val($("#"+varname).css("background-color"));
  1085. }
  1086. } else if (vartype == "valve") {
  1087. $("#elem_unit_text").val("{'on':"+$("#"+varname).attr("data-on") + ",'off':"+$("#"+varname).attr("data-off")+"}" );
  1088. } else if (vartype == "commbit") {
  1089. $("#elem_unit_text").val("{'on':"+$("#"+varname).attr("data-on") + ",'off':"+$("#"+varname).attr("data-off")+"}" );
  1090. } else if (vartype == "alarm") {
  1091. $("#elem_unit_text").val("{'on':"+$("#"+varname).attr("data-on") + ",'off':"+$("#"+varname).attr("data-off")+"}" );
  1092. } else if (vartype == "integer-to-string") {
  1093. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  1094. $("#elem_title_size").val("");
  1095. if ($("#"+varname + " .title").css("font-size")) {
  1096. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  1097. }
  1098. $("#elem_unit_text").val($("#"+varname).attr("data-dict"));
  1099. $("#elem_condition_range").val("");
  1100. if ($("#"+varname).attr("data-cond") ) {
  1101. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  1102. }
  1103. $("#background_color").val("");
  1104. if ($("#"+varname).css("background-color") ) {
  1105. $("#background_color").val($("#"+varname).css("background-color"));
  1106. }
  1107. }
  1108. for(key in mydata) {
  1109. //console.log(key, varname);
  1110. if(($("#" + key).length > 0) && (key == varname) ) {
  1111. //if (!$("#"+varname).hasClass("box_highlight")) {
  1112. $("#"+key).addClass("box_highlight");
  1113. //}
  1114. } else {
  1115. $("#"+key).removeClass("box_highlight");
  1116. }
  1117. }
  1118. }
  1119. jQuery(window).load(function () {
  1120. $("#varname > option").each(function() {
  1121. if ($('#'+this.text).length){
  1122. $('#'+this.text).draggable();
  1123. $('#'+this.text).resizable();
  1124. $('#'+this.text).click(function() {
  1125. //console.log($(this).attr("id"));
  1126. $("#varname").val($(this).attr("id"));
  1127. $("#buttonHighlight").trigger("click");
  1128. });
  1129. }
  1130. //console.log(this.text + ' ' + this.value);
  1131. });
  1132. $("#buttonHighlight").trigger("click");
  1133. $("#varname").change(function() {
  1134. varval = $( "#varname option:selected").val();
  1135. varname = $("#varname option:selected").text();
  1136. //console.log(varval, varname);
  1137. $("#buttonHighlight").trigger("click");
  1138. });
  1139. $("#vartype").change(function() {
  1140. vartype = $("#vartype option:selected").val();
  1141. if ((vartype == "header") || (vartype == "calc")) {
  1142. $("#varname").val("");
  1143. // clear values
  1144. $("#elem_title_text").val("");
  1145. $("#elem_title_size").val("");
  1146. $("#elem_unit_text").val("");
  1147. $("#elem_unit_size").val("");
  1148. $("#elem_lesser_range").val("");
  1149. $("#elem_larger_range").val("");
  1150. $("#elem_condition_range").val("");
  1151. $("#elem_formula").val("");
  1152. $("#background_color").val("");
  1153. }
  1154. });
  1155. });
  1156. </script>
  1157. </body>
  1158. </html>