designer.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. <img src="{{ static_url('background.png') }}"></img>
  17. <button class="button showhide" onclick="showhide()">Show/Hide</button>
  18. {% if data['style'] %}
  19. {% for key in data['style'] %}
  20. {% if data['style'][key]['type'] == "calc" %}
  21. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  22. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  23. height:{{ data['style'][key]['height'] }}px;'
  24. {% if "condition" in data['style'][key] %}
  25. data-cond="{{ data['style'][key]['condition'] }}"
  26. {% else%}position
  27. {% end%}
  28. {% if "formula" in data['style'][key] %}
  29. data-formula="{{ data['style'][key]['formula'] }}"
  30. {% else %}
  31. {% end %}
  32. {% if "lesser" in data['style'][key] %}
  33. data-lesser="{{ data['style'][key]['lesser'] }}"
  34. {% else %}
  35. {% end %}
  36. {% if "larger" in data['style'][key] %}
  37. data-larger="{{ data['style'][key]['larger'] }}"
  38. {% else %}
  39. {% end %}
  40. data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  41. <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>
  42. </div>
  43. {% else %}
  44. {% end %}
  45. {% if data['style'][key]['type'] == "data" %}
  46. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  47. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  48. height:{{ data['style'][key]['height'] }}px;'
  49. {% if "condition" in data['style'][key] %}
  50. data-cond="{{ data['style'][key]['condition'] }}"
  51. {% else%}position
  52. {% end%}
  53. {% if "formula" in data['style'][key] %}
  54. data-formula="{{ data['style'][key]['formula'] }}"
  55. {% else %}
  56. {% end %}
  57. {% if "lesser" in data['style'][key] %}
  58. data-lesser="{{ data['style'][key]['lesser'] }}"
  59. {% else %}
  60. {% end %}
  61. {% if "larger" in data['style'][key] %}
  62. data-larger="{{ data['style'][key]['larger'] }}"
  63. {% else %}
  64. {% end %}
  65. data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  66. <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>
  67. </div>
  68. {% else %}
  69. {% end %}
  70. {% if data['style'][key]['type'] == "ventil" %}
  71. <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 }}">
  72. <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
  73. </div>
  74. {% else %}
  75. {% end %}
  76. {% if data['style'][key]['type'] == "integer-to-string" %}
  77. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  78. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  79. height:{{ data['style'][key]['height'] }}px;'
  80. {% if "cond" in data['style'][key] %}
  81. data-cond="{{ data['style'][key]['cond'] }}"
  82. {% else%}
  83. {% end%}
  84. data-dict="{{ data['style'][key]['dict'] }}" data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  85. <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>
  86. </div>
  87. {% else %}
  88. {% end %}
  89. {% if data['style'][key]['type'] == "header" %}
  90. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  91. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  92. height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  93. <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>
  94. </div>
  95. {% else %}
  96. {% end %}
  97. {% end %}
  98. {% else %}
  99. {% end %}
  100. <div id="tool-btn">
  101. <span class="info">Variable</span>
  102. <select id="varname" style="font-size:16pt;">
  103. {% if data['index'] %}
  104. {% for key in data['index'] %}
  105. {% if key != "time" %}
  106. <option value={{ key }}>{{key}}</option>
  107. {% else %}
  108. {% end %}
  109. {% end %}
  110. {% else %}
  111. {% end %}
  112. </select>
  113. <span class="info">Type</span>
  114. <select id="vartype" style="font-size:16pt;">
  115. <option value="data">data</option>
  116. <option value="ventil">ventil</option>
  117. <option value="integer-to-string">integer-to-string</option>
  118. <option value="header">header</option>
  119. <option value="calc">calc</option>
  120. </select>
  121. <span class="info">Attribute</span>
  122. <select id="varattr" style="font-size:16pt;">
  123. <option value="normal">Normal</option>
  124. <option value="virtual">Virtual</option>
  125. </select>
  126. <span class="info">Virtual ID</span>
  127. <input type="text" id="virtual_id_text" placeholder="text" style="font-size:16pt; width=100px;"/>
  128. <br /><br />
  129. <span class="info">Title</span>
  130. <input type="text" id="elem_title_text" placeholder="text" style="font-size:16pt; width=100px;"/>
  131. <input type="text" id="elem_title_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  132. <input type="text" id="elem_lesser_range" placeholder="smaller than (red)" style="font-size:16pt; width=100px;"/>
  133. <input type="text" id="elem_larger_range" placeholder="larger than (red)" style="font-size:16pt; width=100px;"/>
  134. <select id="elem_title_style" style="font-size:16pt;">
  135. <option value="400">normal</option>
  136. <option value="700">bold</option>
  137. </select>
  138. <br /><br />
  139. <span class="info">Value</span>
  140. <input type="text" id="elem_unit_text" placeholder="unit" style="font-size:16pt; width=100px;"/>
  141. <input type="text" id="elem_unit_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  142. <input type="text" id="elem_condition_range" placeholder="condition (red)" style="font-size:16pt; width=100px;"/>
  143. <input type="text" id="elem_formula" placeholder="Equation" style="font-size:16pt; width=100px;"/>
  144. <select id="elem_unit_style" style="font-size:16pt;">
  145. <option value="400">normal</option>
  146. <option value="700">bold</option>
  147. </select>
  148. <br /><br />
  149. <button class="button save" onclick="backup()">Backup</button>
  150. <button style="display:none;" id="buttonHighlight" class="button highlight" onclick="highlight({{ data['style'] }})">Highlight</button>
  151. <button class="button add" onclick="add()">Add</button>
  152. <button class="button remove" onclick="myremove()">Remove</button>
  153. <button class="button save" onclick="mysave({{ data['cache'] }})">Save</button>
  154. </div>
  155. <!-- java script -->
  156. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  157. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  158. <script>
  159. function backup() {
  160. $.ajax({
  161. url: '/backup/',
  162. type: 'POST',
  163. success: function (response) {
  164. alert("Backup success!");
  165. },
  166. error: function () {
  167. console.log("Error.")
  168. }
  169. });
  170. }
  171. function showhide() {
  172. console.log("Show or Hide");
  173. $("#tool-btn").toggle();
  174. }
  175. function add() {
  176. console.log("add element");
  177. title_text = $("#elem_title_text").val();
  178. title_text = title_text.trim();
  179. title_color = "#000000";
  180. //title_color = $("#elem_title_color").val();
  181. title_size = $("#elem_title_size").val();
  182. title_style = $("#elem_title_style option:selected").val();
  183. unit_text = $("#elem_unit_text").val();
  184. unit_text = unit_text.trim();
  185. unit_color = "#000";
  186. //unit_color = $("#elem_unit_color").val();
  187. unit_size = $("#elem_unit_size").val();
  188. unit_style = $("#elem_unit_style option:selected").val();
  189. data_condition = $("#elem_condition_range").val();
  190. //data_max = $("#elem_max_range").val();
  191. data_formula = $("#elem_formula").val();
  192. virtual_id = $("#virtual_id_text").val();
  193. virtual_id = virtual_id.trim();
  194. if (virtual_id == "") {
  195. virtual_id = "0";
  196. }
  197. data_lesser = $("#elem_lesser_range").val();
  198. data_larger = $("#elem_larger_range").val();
  199. varval = $( "#varname option:selected").val();
  200. varname = $("#varname option:selected").text();
  201. vartype = $("#vartype option:selected").val();
  202. varattr = $("#varattr option:selected").val();
  203. console.log("Selected");
  204. console.log(varattr);
  205. console.log(virtual_id);
  206. console.log(vartype);
  207. console.log(title_text, unit_text, varname, varval, vartype);
  208. if(($("#" + varname).length == 0) || (vartype=="header") || (varattr=="virtual")) {
  209. console.log("Must enter here");
  210. console.log(vartype);
  211. if (vartype == "data") {
  212. if (varattr=="virtual") {
  213. virtual_name = "virtual_" + varname + "_" + virtual_id;
  214. if ( $("#" + virtual_name).length > 0 ) {
  215. for (i = 0; i < 50; i++) {
  216. virtual_name = "virtual_" + varname + "_" + i.toString();
  217. console.log($("#" + virtual_name).length);
  218. if (!$("#" + virtual_name).length){
  219. break;
  220. }
  221. }
  222. }
  223. varname = virtual_name;
  224. }
  225. console.log("Data");
  226. html_text = "<div " +
  227. "style='position: absolute; " +
  228. "top:0; " +
  229. "left:0;' " +
  230. "class='varbox box_highlight' " +
  231. "id='" + varname +
  232. "' data-type='" + vartype +
  233. "' data-cond='" + data_condition +
  234. "' data-formula='" + data_formula +
  235. "' data-lesser='" + data_lesser +
  236. "' data-larger='" + data_larger +
  237. "'>" +
  238. "<p>" +
  239. "<span style='color: " + title_color + ";" +
  240. "font-size:" + title_size + "px; " +
  241. "font-weight: " + title_style + ";' " +
  242. "class='title'>" + title_text +
  243. " </span>" +
  244. "<span style='color: " + unit_color + "; " +
  245. "font-size:" + unit_size + "px; " +
  246. "font-weight: " + unit_style + ";' " +
  247. "class='varval'>" + parseFloat(varval).toFixed(2) + " </span>" +
  248. "<span class='unit_title'>" + unit_text + "</span></p>" +
  249. "</div>";
  250. } else if (vartype == "header") {
  251. console.log("Header");
  252. var clean_text = title_text.replace(/[^a-zA-Z0-9 ]/g, "")
  253. varname = "header_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  254. html_text = "<div " +
  255. "style='position: absolute; " +
  256. "top:0; " +
  257. "left:0;' " +
  258. "class='varbox box_highlight' " +
  259. "id='" + varname +
  260. "' data-type='" + vartype +
  261. "' data-cond='" + data_condition +
  262. "' data-lesser='" + data_lesser +
  263. "' data-larger='" + data_larger +
  264. "'>" +
  265. "<p>" +
  266. "<span style='color: " + title_color + ";" +
  267. "font-size:" + title_size + "px; " +
  268. "font-weight: " + title_style + ";' " +
  269. "class='title'>" + title_text +
  270. " </span></p>" +
  271. "</div>";
  272. $('#varname').append($('<option>', {
  273. value: varname,
  274. text: varname
  275. }));
  276. $('#varname').val(varname);
  277. } else if (vartype == "calc") {
  278. console.log("Calc");
  279. var clean_text = title_text.replace(/[^a-zA-Z0-9 ]/g, "")
  280. varname = "calc_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  281. html_text = "<div " +
  282. "style='position: absolute; " +
  283. "top:0; " +
  284. "left:0;' " +
  285. "class='varbox box_highlight' " +
  286. "id='" + varname +
  287. "' data-type='" + vartype +
  288. "' data-cond='" + data_condition +
  289. "' data-lesser='" + data_lesser +
  290. "' data-larger='" + data_larger +
  291. "' data-formula='" + data_formula +
  292. "'>" +
  293. "<p>" +
  294. "<span style='color: " + title_color + ";" +
  295. "font-size:" + title_size + "px; " +
  296. "font-weight: " + title_style + ";' " +
  297. "class='title'>" + title_text +
  298. " </span>" +
  299. "<span style='color: " + unit_color + "; " +
  300. "font-size:" + unit_size + "px; " +
  301. "font-weight: " + unit_style + ";' " +
  302. "class='varval'>" + parseFloat(varval).toFixed(2) + " </span>" +
  303. "<span class='unit_title'>" + unit_text + "</span></p>" +
  304. "</div>";
  305. $('#varname').append($('<option>', {
  306. value: varname,
  307. text: varname
  308. }));
  309. $('#varname').val(varname);
  310. } else if (vartype == "ventil") {
  311. console.log("Ventil");
  312. var token = JSON.parse(unit_text);
  313. data_on = token["on"];
  314. data_off = token["off"];
  315. html_text = "<div " +
  316. "style='position: absolute; " +
  317. "top:0; " +
  318. "left:0;' " +
  319. "class='varbox box_highlight' " +
  320. "id='" + varname +
  321. "' data-type='" + vartype +
  322. "' data-cond='" + data_condition +
  323. "' data-lesser='" + data_lesser +
  324. "' data-larger='" + data_larger +
  325. "' data-on='" + data_on +
  326. "' data-off='" + data_off +
  327. "'>" +
  328. "<img width='100%' height='100%' " +
  329. "src='{{ static_url("ventil_inactive.png") }}'></img>" +
  330. "</div>";
  331. } else if (vartype == "integer-to-string") {
  332. console.log("Integer2String");
  333. html_text = "<div " +
  334. "style='position: absolute; " +
  335. "top:0; " +
  336. "left:0;' " +
  337. "class='varbox box_highlight' " +
  338. "id='" + varname +
  339. "' data-type='" + vartype +
  340. "' data-dict='" + unit_text +
  341. "' data-cond='" + data_condition +
  342. "'>" +
  343. "<p>" +
  344. "<span style='color: " + title_color + ";" +
  345. "font-size:" + title_size + "px; " +
  346. "font-weight: " + title_style + ";' " +
  347. "class='title'>" + title_text +
  348. " </span><br />" +
  349. "<span style='color: " + unit_color + "; " +
  350. "font-size:" + unit_size + "px; " +
  351. "font-weight: " + unit_style + ";' " +
  352. "class='varval'>??? </span>" +
  353. "</p>" +
  354. "</div>";
  355. }
  356. console.log("Adding element");
  357. console.log(html_text);
  358. $( "body" ).append(html_text);
  359. $("#"+varname).draggable();
  360. $("#"+varname).resizable();
  361. }
  362. }
  363. function myremove() {
  364. varname = $("#varname option:selected").text();
  365. vartype = $("#vartype option:selected").val();
  366. if($("#" + varname).length > 0) {
  367. $("#"+varname).remove();
  368. console.log(varname +" removed.");
  369. }
  370. }
  371. function mysave(data) {
  372. console.log("saving...");
  373. varname = $("#varname option:selected").text();
  374. varattr = $("#varattr option:selected").val();
  375. console.log("debug");
  376. console.log(varattr);
  377. var position = {};
  378. for(key in data) {
  379. var tmp = {};
  380. //console.log(key);
  381. if($("#" + key).length > 0 ) {
  382. tmp["ref"] = key;
  383. tmp["left"] = $("#"+key).css("left");
  384. tmp["top"] = $("#"+key).css("top");
  385. tmp["width"] = $("#"+key).width();
  386. tmp["height"] = $("#"+key).height();
  387. tmp["type"] = $("#"+key).attr("data-type");
  388. if ( $("#"+key).attr("data-type") == "data" ) {
  389. if ( (varname == key) && (varattr == "normal") ) {
  390. tmp["condition"] = $("#elem_condtion_range").val();
  391. tmp["formula"] = $("#elem_formula").val();
  392. tmp["lesser"] = $("#elem_lesser_range").val();
  393. tmp["larger"] = $("#elem_larger_range").val();
  394. header = {};
  395. header["title"] = $("#elem_title_text").val().trim();
  396. //header["color"] = $(".title", "#"+key).css("color");
  397. header["size"] = $("#elem_title_size").val();
  398. header["weight"] = $("#elem_title_style option:selected").val();
  399. unit = {};
  400. unit["title"] = $("#elem_unit_text").val().trim();
  401. //unit["color"] = $(".varval", "#"+key).css("color");
  402. unit["size"] = $("#elem_unit_size").val();
  403. unit["weight"] = $("#elem_unit_style option:selected").val();
  404. } else {
  405. tmp["condition"] = $("#"+key).attr("data-cond");
  406. tmp["formula"] = $("#"+key).attr("data-formula");
  407. tmp["lesser"] = $("#"+key).attr("data-lesser");
  408. tmp["larger"] = $("#"+key).attr("data-larger");
  409. //tmp["min"] = $("#"+key).attr("min");
  410. //tmp["max"] = $("#"+key).attr("max");
  411. header = {};
  412. header["title"] = $(".title", "#"+key).text();
  413. //header["color"] = $(".title", "#"+key).css("color");
  414. header["size"] = $(".title", "#"+key).css("font-size");
  415. header["weight"] = $(".title", "#"+key).css("font-weight");
  416. unit = {};
  417. unit["title"] = $(".unit_title", "#"+key).text();
  418. //unit["color"] = $(".varval", "#"+key).css("color");
  419. unit["size"] = $(".varval", "#"+key).css("font-size");
  420. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  421. }
  422. tmp["header"] = header;
  423. tmp["unit"] = unit;
  424. } else if ( $("#"+key).attr("data-type") == "header" ) {
  425. header = {};
  426. header["title"] = $(".title", "#"+key).text();
  427. header["size"] = $(".title", "#"+key).css("font-size");
  428. header["weight"] = $(".title", "#"+key).css("font-weight");
  429. tmp["header"] = header;
  430. } else if ( $("#"+key).attr("data-type") == "ventil" ) {
  431. if ((varname == key) && (varattr == "normal")) {
  432. var unit_text = $("#elem_unit_text").val();
  433. unit_text = unit_text.trim();
  434. var dtoken = JSON.parse(unit_text);
  435. tmp["on"] = dtoken["on"];
  436. tmp["off"] = dtoken["off"];
  437. } else {
  438. tmp["on"] = $("#"+key).attr("data-on");
  439. tmp["off"] = $("#"+key).attr("data-off");
  440. }
  441. } else if ( $("#"+key).attr("data-type") == "integer-to-string" ) {
  442. if ((varname == key)&& (varattr == "normal")) {
  443. var unit_text = $("#elem_unit_text").val();
  444. unit_text = unit_text.trim();
  445. var data_condition = $("#elem_condition_range").val();
  446. tmp["cond"] = data_condition;
  447. tmp["dict"] = unit_text;
  448. header = {};
  449. header["title"] = $("#elem_title_text").val().trim();
  450. header["size"] = $("#elem_title_size").val();
  451. header["weight"] = $("#elem_title_style option:selected").val();
  452. unit = {};
  453. //unit["color"] = $(".varval", "#"+key).css("color");
  454. unit["size"] = $("#elem_unit_size").val();
  455. unit["weight"] = $("#elem_unit_style option:selected").val();
  456. } else {
  457. tmp["dict"] = $("#"+key).attr("data-dict");
  458. tmp["cond"] = $("#"+key).attr("data-cond");
  459. header = {};
  460. header["title"] = $(".title", "#"+key).text();
  461. //header["color"] = $(".title", "#"+key).css("color");
  462. header["size"] = $(".title", "#"+key).css("font-size");
  463. header["weight"] = $(".title", "#"+key).css("font-weight");
  464. unit = {};
  465. //unit["title"] = $(".unit_title", "#"+key).text();
  466. //unit["color"] = $(".varval", "#"+key).css("color");
  467. unit["size"] = $(".varval", "#"+key).css("font-size");
  468. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  469. }
  470. tmp["header"] = header;
  471. tmp["unit"] = unit;
  472. }
  473. position[key] = tmp;
  474. }
  475. }
  476. var title_text = $("#elem_title_text").val();
  477. title_text = title_text.trim();
  478. var clean_text = title_text.replace(/[^a-zA-Z0-9 ]/g, "")
  479. var token = "header_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  480. $('[id^=virtual_]').each(function( index ) {
  481. var tmp = {};
  482. var key = this.id;
  483. var ref = key.split("_");
  484. ref = ref[1];
  485. if (key != "virtual_id_text") {
  486. console.log("Check this");
  487. console.log(key);
  488. if($("#" + key).length > 0 ) {
  489. tmp["ref"] = ref;
  490. tmp["left"] = $("#"+key).css("left");
  491. tmp["top"] = $("#"+key).css("top");
  492. tmp["width"] = $("#"+key).width();
  493. tmp["height"] = $("#"+key).height();
  494. tmp["type"] = $("#"+key).attr("data-type");
  495. if ( $("#"+key).attr("data-type") == "data" ) {
  496. if (varname == key) {
  497. tmp["condition"] = $("#elem_condtion_range").val();
  498. tmp["formula"] = $("#elem_formula").val();
  499. tmp["lesser"] = $("#elem_lesser_range").val();
  500. tmp["larger"] = $("#elem_larger_range").val();
  501. header = {};
  502. header["title"] = $("#elem_title_text").val().trim();
  503. //header["color"] = $(".title", "#"+key).css("color");
  504. header["size"] = $("#elem_title_size").val();
  505. header["weight"] = $("#elem_title_style option:selected").val();
  506. unit = {};
  507. unit["title"] = $("#elem_unit_text").val().trim();
  508. //unit["color"] = $(".varval", "#"+key).css("color");
  509. unit["size"] = $("#elem_unit_size").val();
  510. unit["weight"] = $("#elem_unit_style option:selected").val();
  511. } else {
  512. tmp["condition"] = $("#"+key).attr("data-cond");
  513. tmp["formula"] = $("#"+key).attr("data-formula");
  514. tmp["lesser"] = $("#"+key).attr("data-lesser");
  515. tmp["larger"] = $("#"+key).attr("data-larger");
  516. //tmp["min"] = $("#"+key).attr("min");
  517. //tmp["max"] = $("#"+key).attr("max");
  518. header = {};
  519. header["title"] = $(".title", "#"+key).text();
  520. //header["color"] = $(".title", "#"+key).css("color");
  521. header["size"] = $(".title", "#"+key).css("font-size");
  522. header["weight"] = $(".title", "#"+key).css("font-weight");
  523. unit = {};
  524. unit["title"] = $(".unit_title", "#"+key).text();
  525. //unit["color"] = $(".varval", "#"+key).css("color");
  526. unit["size"] = $(".varval", "#"+key).css("font-size");
  527. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  528. }
  529. tmp["header"] = header;
  530. tmp["unit"] = unit;
  531. } else if ( $("#"+key).attr("data-type") == "header" ) {
  532. header = {};
  533. header["title"] = $(".title", "#"+key).text();
  534. header["size"] = $(".title", "#"+key).css("font-size");
  535. header["weight"] = $(".title", "#"+key).css("font-weight");
  536. tmp["header"] = header;
  537. } else if ( $("#"+key).attr("data-type") == "ventil" ) {
  538. if (varname == key) {
  539. var unit_text = $("#elem_unit_text").val();
  540. unit_text = unit_text.trim();
  541. var dtoken = JSON.parse(unit_text);
  542. tmp["on"] = dtoken["on"];
  543. tmp["off"] = dtoken["off"];
  544. } else {
  545. tmp["on"] = $("#"+key).attr("data-on");
  546. tmp["off"] = $("#"+key).attr("data-off");
  547. }
  548. } else if ( $("#"+key).attr("data-type") == "integer-to-string" ) {
  549. if (varname == key) {
  550. var unit_text = $("#elem_unit_text").val();
  551. unit_text = unit_text.trim();
  552. var data_condition = $("#elem_condition_range").val();
  553. tmp["cond"] = data_condition;
  554. tmp["dict"] = unit_text;
  555. header = {};
  556. header["title"] = $("#elem_title_text").val().trim();
  557. header["size"] = $("#elem_title_size").val();
  558. header["weight"] = $("#elem_title_style option:selected").val();
  559. unit = {};
  560. //unit["color"] = $(".varval", "#"+key).css("color");
  561. unit["size"] = $("#elem_unit_size").val();
  562. unit["weight"] = $("#elem_unit_style option:selected").val();
  563. } else {
  564. tmp["dict"] = $("#"+key).attr("data-dict");
  565. tmp["cond"] = $("#"+key).attr("data-cond");
  566. header = {};
  567. header["title"] = $(".title", "#"+key).text();
  568. //header["color"] = $(".title", "#"+key).css("color");
  569. header["size"] = $(".title", "#"+key).css("font-size");
  570. header["weight"] = $(".title", "#"+key).css("font-weight");
  571. unit = {};
  572. //unit["title"] = $(".unit_title", "#"+key).text();
  573. //unit["color"] = $(".varval", "#"+key).css("color");
  574. unit["size"] = $(".varval", "#"+key).css("font-size");
  575. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  576. }
  577. tmp["header"] = header;
  578. tmp["unit"] = unit;
  579. }
  580. position[key] = tmp;
  581. }
  582. }
  583. });
  584. $('[id^=header_]').each(function( index ) {
  585. tmp = {};
  586. var hkey = $( this ).attr('id');
  587. console.log(hkey);
  588. tmp["left"] = $("#"+hkey).css("left");
  589. tmp["top"] = $("#"+hkey).css("top");
  590. tmp["width"] = $("#"+hkey).width();
  591. tmp["height"] = $("#"+hkey).height();
  592. tmp["type"] = $("#"+hkey).attr("data-type");
  593. header = {};
  594. if (token == hkey) {
  595. header["title"] = $("#elem_title_text").val().trim();
  596. //header["color"] = $(".title", "#"+key).css("color");
  597. header["size"] = $("#elem_title_size").val();
  598. header["weight"] = $("#elem_title_style option:selected").val();
  599. } else {
  600. header["title"] = $(".title", "#"+hkey).text();
  601. //header["color"] = $(".title", "#"+hkey).css("color");
  602. header["size"] = $(".title", "#"+hkey).css("font-size");
  603. header["weight"] = $(".title", "#"+hkey).css("font-weight");
  604. }
  605. tmp["header"] = header;
  606. position[hkey] = tmp;
  607. //console.log( index + ": " + $( this ).text() );
  608. });
  609. $('[id^=calc_]').each(function( index ) {
  610. var tmp = {};
  611. var key = this.id;
  612. if($("#" + key).length > 0 ) {
  613. tmp["ref"] = "";
  614. tmp["left"] = $("#"+key).css("left");
  615. tmp["top"] = $("#"+key).css("top");
  616. tmp["width"] = $("#"+key).width();
  617. tmp["height"] = $("#"+key).height();
  618. tmp["type"] = $("#"+key).attr("data-type");
  619. if ( $("#"+key).attr("data-type") == "calc" ) {
  620. if (varname == key) {
  621. tmp["condition"] = $("#elem_condtion_range").val();
  622. tmp["formula"] = $("#elem_formula").val();
  623. tmp["lesser"] = $("#elem_lesser_range").val();
  624. tmp["larger"] = $("#elem_larger_range").val();
  625. header = {};
  626. header["title"] = $("#elem_title_text").val().trim();
  627. //header["color"] = $(".title", "#"+key).css("color");
  628. header["size"] = $("#elem_title_size").val();
  629. header["weight"] = $("#elem_title_style option:selected").val();
  630. unit = {};
  631. unit["title"] = $("#elem_unit_text").val().trim();
  632. //unit["color"] = $(".varval", "#"+key).css("color");
  633. unit["size"] = $("#elem_unit_size").val();
  634. unit["weight"] = $("#elem_unit_style option:selected").val();
  635. } else {
  636. tmp["condition"] = $("#"+key).attr("data-cond");
  637. tmp["formula"] = $("#"+key).attr("data-formula");
  638. tmp["lesser"] = $("#"+key).attr("data-lesser");
  639. tmp["larger"] = $("#"+key).attr("data-larger");
  640. //tmp["min"] = $("#"+key).attr("min");
  641. //tmp["max"] = $("#"+key).attr("max");
  642. header = {};
  643. header["title"] = $(".title", "#"+key).text();
  644. //header["color"] = $(".title", "#"+key).css("color");
  645. header["size"] = $(".title", "#"+key).css("font-size");
  646. header["weight"] = $(".title", "#"+key).css("font-weight");
  647. unit = {};
  648. unit["title"] = $(".unit_title", "#"+key).text();
  649. //unit["color"] = $(".varval", "#"+key).css("color");
  650. unit["size"] = $(".varval", "#"+key).css("font-size");
  651. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  652. }
  653. tmp["header"] = header;
  654. tmp["unit"] = unit;
  655. }
  656. position[key] = tmp;
  657. }
  658. });
  659. //console.log("Check here");
  660. //console.log(position);
  661. var dataToSend = JSON.stringify(position);
  662. //console.log(dataToSend);
  663. $.ajax({
  664. url: '/save/',
  665. type: 'POST',
  666. data: dataToSend,
  667. success: function (response) {
  668. var objresponse = JSON.parse(response);
  669. console.log(objresponse);
  670. },
  671. error: function () {
  672. console.log("Error.")
  673. }
  674. });
  675. }
  676. function highlight(mydata) {
  677. varname = $("#varname option:selected").text();
  678. vartype = $("#"+varname).attr("data-type");
  679. $("#vartype").val(vartype);
  680. //console.log(varname, vartype);
  681. // clear values
  682. $("#elem_title_text").val("");
  683. $("#elem_title_size").val("");
  684. $("#elem_unit_text").val("");
  685. $("#elem_unit_size").val("");
  686. $("#elem_lesser_range").val("");
  687. $("#elem_larger_range").val("");
  688. $("#elem_condition_range").val("");
  689. $("#elem_formula").val("");
  690. if (vartype == "header") {
  691. $("#elem_title_text").val($("#"+varname + " .title").text());
  692. $("#elem_title_size").val(parseInt($("#"+varname + " .title").css("font-size")));
  693. } else if (vartype == "data") {
  694. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  695. $("#elem_title_size").val("");
  696. if ($("#"+varname + " .title").css("font-size")) {
  697. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  698. }
  699. $("#elem_unit_text").val($("#"+varname + " .unit_title").text().trim());
  700. $("#elem_unit_size").val("");
  701. if ($("#"+varname + " .varval").css("font-size")) {
  702. $("#elem_unit_size").val(parseFloat($("#"+varname + " .varval").css("font-size")));
  703. }
  704. $("#elem_lesser_range").val("");
  705. if ($("#"+varname).attr("data-lesser") ) {
  706. $("#elem_lesser_range").val($("#"+varname).attr("data-lesser"));
  707. }
  708. $("#elem_larger_range").val("");
  709. if ($("#"+varname).attr("data-larger") ) {
  710. $("#elem_larger_range").val($("#"+varname).attr("data-larger"));
  711. }
  712. $("#elem_condition_range").val("");
  713. if ($("#"+varname).attr("data-cond") ) {
  714. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  715. }
  716. $("#elem_formula").val("");
  717. if ($("#"+varname).attr("data-formula") ) {
  718. $("#elem_formula").val($("#"+varname).attr("data-formula"));
  719. }
  720. } else if (vartype == "calc") {
  721. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  722. $("#elem_title_size").val("");
  723. if ($("#"+varname + " .title").css("font-size")) {
  724. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  725. }
  726. $("#elem_unit_text").val($("#"+varname + " .unit_title").text().trim());
  727. $("#elem_unit_size").val("");
  728. if ($("#"+varname + " .varval").css("font-size")) {
  729. $("#elem_unit_size").val(parseFloat($("#"+varname + " .varval").css("font-size")));
  730. }
  731. $("#elem_lesser_range").val("");
  732. if ($("#"+varname).attr("data-lesser") ) {
  733. $("#elem_lesser_range").val($("#"+varname).attr("data-lesser"));
  734. }
  735. $("#elem_larger_range").val("");
  736. if ($("#"+varname).attr("data-larger") ) {
  737. $("#elem_larger_range").val($("#"+varname).attr("data-larger"));
  738. }
  739. $("#elem_condition_range").val("");
  740. if ($("#"+varname).attr("data-cond") ) {
  741. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  742. }
  743. $("#elem_formula").val("");
  744. if ($("#"+varname).attr("data-formula") ) {
  745. $("#elem_formula").val($("#"+varname).attr("data-formula"));
  746. }
  747. } else if (vartype == "ventil") {
  748. $("#elem_unit_text").val("{'on':"+$("#"+varname).attr("data-on") + ",'off':"+$("#"+varname).attr("data-off")+"}" );
  749. } else if (vartype == "integer-to-string") {
  750. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  751. $("#elem_title_size").val("");
  752. if ($("#"+varname + " .title").css("font-size")) {
  753. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  754. }
  755. $("#elem_unit_text").val($("#"+varname).attr("data-dict"));
  756. $("#elem_condition_range").val("");
  757. if ($("#"+varname).attr("data-cond") ) {
  758. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  759. }
  760. }
  761. for(key in mydata) {
  762. //console.log(key, varname);
  763. if(($("#" + key).length > 0) && (key == varname) ) {
  764. //if (!$("#"+varname).hasClass("box_highlight")) {
  765. $("#"+key).addClass("box_highlight");
  766. //}
  767. } else {
  768. $("#"+key).removeClass("box_highlight");
  769. }
  770. }
  771. }
  772. jQuery(window).load(function () {
  773. $("#varname > option").each(function() {
  774. if ($('#'+this.text).length){
  775. $('#'+this.text).draggable();
  776. $('#'+this.text).resizable();
  777. $('#'+this.text).click(function() {
  778. console.log($(this).attr("id"));
  779. $("#varname").val($(this).attr("id"));
  780. $("#buttonHighlight").trigger("click");
  781. });
  782. }
  783. //console.log(this.text + ' ' + this.value);
  784. });
  785. //$('[id^=header_]').each(function( index ) {
  786. // $(this).draggable();
  787. // $(this).resizable();
  788. //});
  789. $("#buttonHighlight").trigger("click");
  790. $("#varname").change(function() {
  791. varval = $( "#varname option:selected").val();
  792. varname = $("#varname option:selected").text();
  793. console.log(varval, varname);
  794. $("#buttonHighlight").trigger("click");
  795. });
  796. $("#vartype").change(function() {
  797. vartype = $("#vartype option:selected").val();
  798. if ((vartype == "header") || (vartype == "calc")) {
  799. $("#varname").val("");
  800. // clear values
  801. $("#elem_title_text").val("");
  802. $("#elem_title_size").val("");
  803. $("#elem_unit_text").val("");
  804. $("#elem_unit_size").val("");
  805. $("#elem_lesser_range").val("");
  806. $("#elem_larger_range").val("");
  807. $("#elem_condition_range").val("");
  808. $("#elem_formula").val("");
  809. }
  810. });
  811. });
  812. </script>
  813. </body>
  814. </html>