designer.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  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. var position = {};
  375. for(key in data) {
  376. var tmp = {};
  377. //console.log(key);
  378. if($("#" + key).length > 0 ) {
  379. tmp["ref"] = key;
  380. tmp["left"] = $("#"+key).css("left");
  381. tmp["top"] = $("#"+key).css("top");
  382. tmp["width"] = $("#"+key).width();
  383. tmp["height"] = $("#"+key).height();
  384. tmp["type"] = $("#"+key).attr("data-type");
  385. if ( $("#"+key).attr("data-type") == "data" ) {
  386. if (varname == key) {
  387. tmp["condition"] = $("#elem_condtion_range").val();
  388. tmp["formula"] = $("#elem_formula").val();
  389. tmp["lesser"] = $("#elem_lesser_range").val();
  390. tmp["larger"] = $("#elem_larger_range").val();
  391. header = {};
  392. header["title"] = $("#elem_title_text").val().trim();
  393. //header["color"] = $(".title", "#"+key).css("color");
  394. header["size"] = $("#elem_title_size").val();
  395. header["weight"] = $("#elem_title_style option:selected").val();
  396. unit = {};
  397. unit["title"] = $("#elem_unit_text").val().trim();
  398. //unit["color"] = $(".varval", "#"+key).css("color");
  399. unit["size"] = $("#elem_unit_size").val();
  400. unit["weight"] = $("#elem_unit_style option:selected").val();
  401. } else {
  402. tmp["condition"] = $("#"+key).attr("data-cond");
  403. tmp["formula"] = $("#"+key).attr("data-formula");
  404. tmp["lesser"] = $("#"+key).attr("data-lesser");
  405. tmp["larger"] = $("#"+key).attr("data-larger");
  406. //tmp["min"] = $("#"+key).attr("min");
  407. //tmp["max"] = $("#"+key).attr("max");
  408. header = {};
  409. header["title"] = $(".title", "#"+key).text();
  410. //header["color"] = $(".title", "#"+key).css("color");
  411. header["size"] = $(".title", "#"+key).css("font-size");
  412. header["weight"] = $(".title", "#"+key).css("font-weight");
  413. unit = {};
  414. unit["title"] = $(".unit_title", "#"+key).text();
  415. //unit["color"] = $(".varval", "#"+key).css("color");
  416. unit["size"] = $(".varval", "#"+key).css("font-size");
  417. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  418. }
  419. tmp["header"] = header;
  420. tmp["unit"] = unit;
  421. } else if ( $("#"+key).attr("data-type") == "header" ) {
  422. header = {};
  423. header["title"] = $(".title", "#"+key).text();
  424. header["size"] = $(".title", "#"+key).css("font-size");
  425. header["weight"] = $(".title", "#"+key).css("font-weight");
  426. tmp["header"] = header;
  427. } else if ( $("#"+key).attr("data-type") == "ventil" ) {
  428. if (varname == key) {
  429. var unit_text = $("#elem_unit_text").val();
  430. unit_text = unit_text.trim();
  431. var dtoken = JSON.parse(unit_text);
  432. tmp["on"] = dtoken["on"];
  433. tmp["off"] = dtoken["off"];
  434. } else {
  435. tmp["on"] = $("#"+key).attr("data-on");
  436. tmp["off"] = $("#"+key).attr("data-off");
  437. }
  438. } else if ( $("#"+key).attr("data-type") == "integer-to-string" ) {
  439. if (varname == key) {
  440. var unit_text = $("#elem_unit_text").val();
  441. unit_text = unit_text.trim();
  442. var data_condition = $("#elem_condition_range").val();
  443. tmp["cond"] = data_condition;
  444. tmp["dict"] = unit_text;
  445. header = {};
  446. header["title"] = $("#elem_title_text").val().trim();
  447. header["size"] = $("#elem_title_size").val();
  448. header["weight"] = $("#elem_title_style option:selected").val();
  449. unit = {};
  450. //unit["color"] = $(".varval", "#"+key).css("color");
  451. unit["size"] = $("#elem_unit_size").val();
  452. unit["weight"] = $("#elem_unit_style option:selected").val();
  453. } else {
  454. tmp["dict"] = $("#"+key).attr("data-dict");
  455. tmp["cond"] = $("#"+key).attr("data-cond");
  456. header = {};
  457. header["title"] = $(".title", "#"+key).text();
  458. //header["color"] = $(".title", "#"+key).css("color");
  459. header["size"] = $(".title", "#"+key).css("font-size");
  460. header["weight"] = $(".title", "#"+key).css("font-weight");
  461. unit = {};
  462. //unit["title"] = $(".unit_title", "#"+key).text();
  463. //unit["color"] = $(".varval", "#"+key).css("color");
  464. unit["size"] = $(".varval", "#"+key).css("font-size");
  465. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  466. }
  467. tmp["header"] = header;
  468. tmp["unit"] = unit;
  469. }
  470. position[key] = tmp;
  471. }
  472. }
  473. var title_text = $("#elem_title_text").val();
  474. title_text = title_text.trim();
  475. var clean_text = title_text.replace(/[^a-zA-Z0-9 ]/g, "")
  476. var token = "header_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  477. $('[id^=virtual_]').each(function( index ) {
  478. var tmp = {};
  479. var key = this.id;
  480. var ref = key.split("_");
  481. ref = ref[1];
  482. if (key != "virtual_id_text") {
  483. console.log("Check this");
  484. console.log(key);
  485. if($("#" + key).length > 0 ) {
  486. tmp["ref"] = ref;
  487. tmp["left"] = $("#"+key).css("left");
  488. tmp["top"] = $("#"+key).css("top");
  489. tmp["width"] = $("#"+key).width();
  490. tmp["height"] = $("#"+key).height();
  491. tmp["type"] = $("#"+key).attr("data-type");
  492. if ( $("#"+key).attr("data-type") == "data" ) {
  493. if (varname == key) {
  494. tmp["condition"] = $("#elem_condtion_range").val();
  495. tmp["formula"] = $("#elem_formula").val();
  496. tmp["lesser"] = $("#elem_lesser_range").val();
  497. tmp["larger"] = $("#elem_larger_range").val();
  498. header = {};
  499. header["title"] = $("#elem_title_text").val().trim();
  500. //header["color"] = $(".title", "#"+key).css("color");
  501. header["size"] = $("#elem_title_size").val();
  502. header["weight"] = $("#elem_title_style option:selected").val();
  503. unit = {};
  504. unit["title"] = $("#elem_unit_text").val().trim();
  505. //unit["color"] = $(".varval", "#"+key).css("color");
  506. unit["size"] = $("#elem_unit_size").val();
  507. unit["weight"] = $("#elem_unit_style option:selected").val();
  508. } else {
  509. tmp["condition"] = $("#"+key).attr("data-cond");
  510. tmp["formula"] = $("#"+key).attr("data-formula");
  511. tmp["lesser"] = $("#"+key).attr("data-lesser");
  512. tmp["larger"] = $("#"+key).attr("data-larger");
  513. //tmp["min"] = $("#"+key).attr("min");
  514. //tmp["max"] = $("#"+key).attr("max");
  515. header = {};
  516. header["title"] = $(".title", "#"+key).text();
  517. //header["color"] = $(".title", "#"+key).css("color");
  518. header["size"] = $(".title", "#"+key).css("font-size");
  519. header["weight"] = $(".title", "#"+key).css("font-weight");
  520. unit = {};
  521. unit["title"] = $(".unit_title", "#"+key).text();
  522. //unit["color"] = $(".varval", "#"+key).css("color");
  523. unit["size"] = $(".varval", "#"+key).css("font-size");
  524. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  525. }
  526. tmp["header"] = header;
  527. tmp["unit"] = unit;
  528. } else if ( $("#"+key).attr("data-type") == "header" ) {
  529. header = {};
  530. header["title"] = $(".title", "#"+key).text();
  531. header["size"] = $(".title", "#"+key).css("font-size");
  532. header["weight"] = $(".title", "#"+key).css("font-weight");
  533. tmp["header"] = header;
  534. } else if ( $("#"+key).attr("data-type") == "ventil" ) {
  535. if (varname == key) {
  536. var unit_text = $("#elem_unit_text").val();
  537. unit_text = unit_text.trim();
  538. var dtoken = JSON.parse(unit_text);
  539. tmp["on"] = dtoken["on"];
  540. tmp["off"] = dtoken["off"];
  541. } else {
  542. tmp["on"] = $("#"+key).attr("data-on");
  543. tmp["off"] = $("#"+key).attr("data-off");
  544. }
  545. } else if ( $("#"+key).attr("data-type") == "integer-to-string" ) {
  546. if (varname == key) {
  547. var unit_text = $("#elem_unit_text").val();
  548. unit_text = unit_text.trim();
  549. var data_condition = $("#elem_condition_range").val();
  550. tmp["cond"] = data_condition;
  551. tmp["dict"] = unit_text;
  552. header = {};
  553. header["title"] = $("#elem_title_text").val().trim();
  554. header["size"] = $("#elem_title_size").val();
  555. header["weight"] = $("#elem_title_style option:selected").val();
  556. unit = {};
  557. //unit["color"] = $(".varval", "#"+key).css("color");
  558. unit["size"] = $("#elem_unit_size").val();
  559. unit["weight"] = $("#elem_unit_style option:selected").val();
  560. } else {
  561. tmp["dict"] = $("#"+key).attr("data-dict");
  562. tmp["cond"] = $("#"+key).attr("data-cond");
  563. header = {};
  564. header["title"] = $(".title", "#"+key).text();
  565. //header["color"] = $(".title", "#"+key).css("color");
  566. header["size"] = $(".title", "#"+key).css("font-size");
  567. header["weight"] = $(".title", "#"+key).css("font-weight");
  568. unit = {};
  569. //unit["title"] = $(".unit_title", "#"+key).text();
  570. //unit["color"] = $(".varval", "#"+key).css("color");
  571. unit["size"] = $(".varval", "#"+key).css("font-size");
  572. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  573. }
  574. tmp["header"] = header;
  575. tmp["unit"] = unit;
  576. }
  577. position[key] = tmp;
  578. }
  579. }
  580. });
  581. $('[id^=header_]').each(function( index ) {
  582. tmp = {};
  583. var hkey = $( this ).attr('id');
  584. console.log(hkey);
  585. tmp["left"] = $("#"+hkey).css("left");
  586. tmp["top"] = $("#"+hkey).css("top");
  587. tmp["width"] = $("#"+hkey).width();
  588. tmp["height"] = $("#"+hkey).height();
  589. tmp["type"] = $("#"+hkey).attr("data-type");
  590. header = {};
  591. if (token == hkey) {
  592. header["title"] = $("#elem_title_text").val().trim();
  593. //header["color"] = $(".title", "#"+key).css("color");
  594. header["size"] = $("#elem_title_size").val();
  595. header["weight"] = $("#elem_title_style option:selected").val();
  596. } else {
  597. header["title"] = $(".title", "#"+hkey).text();
  598. //header["color"] = $(".title", "#"+hkey).css("color");
  599. header["size"] = $(".title", "#"+hkey).css("font-size");
  600. header["weight"] = $(".title", "#"+hkey).css("font-weight");
  601. }
  602. tmp["header"] = header;
  603. position[hkey] = tmp;
  604. //console.log( index + ": " + $( this ).text() );
  605. });
  606. $('[id^=calc_]').each(function( index ) {
  607. var tmp = {};
  608. var key = this.id;
  609. if($("#" + key).length > 0 ) {
  610. tmp["ref"] = "";
  611. tmp["left"] = $("#"+key).css("left");
  612. tmp["top"] = $("#"+key).css("top");
  613. tmp["width"] = $("#"+key).width();
  614. tmp["height"] = $("#"+key).height();
  615. tmp["type"] = $("#"+key).attr("data-type");
  616. if ( $("#"+key).attr("data-type") == "calc" ) {
  617. if (varname == key) {
  618. tmp["condition"] = $("#elem_condtion_range").val();
  619. tmp["formula"] = $("#elem_formula").val();
  620. tmp["lesser"] = $("#elem_lesser_range").val();
  621. tmp["larger"] = $("#elem_larger_range").val();
  622. header = {};
  623. header["title"] = $("#elem_title_text").val().trim();
  624. //header["color"] = $(".title", "#"+key).css("color");
  625. header["size"] = $("#elem_title_size").val();
  626. header["weight"] = $("#elem_title_style option:selected").val();
  627. unit = {};
  628. unit["title"] = $("#elem_unit_text").val().trim();
  629. //unit["color"] = $(".varval", "#"+key).css("color");
  630. unit["size"] = $("#elem_unit_size").val();
  631. unit["weight"] = $("#elem_unit_style option:selected").val();
  632. } else {
  633. tmp["condition"] = $("#"+key).attr("data-cond");
  634. tmp["formula"] = $("#"+key).attr("data-formula");
  635. tmp["lesser"] = $("#"+key).attr("data-lesser");
  636. tmp["larger"] = $("#"+key).attr("data-larger");
  637. //tmp["min"] = $("#"+key).attr("min");
  638. //tmp["max"] = $("#"+key).attr("max");
  639. header = {};
  640. header["title"] = $(".title", "#"+key).text();
  641. //header["color"] = $(".title", "#"+key).css("color");
  642. header["size"] = $(".title", "#"+key).css("font-size");
  643. header["weight"] = $(".title", "#"+key).css("font-weight");
  644. unit = {};
  645. unit["title"] = $(".unit_title", "#"+key).text();
  646. //unit["color"] = $(".varval", "#"+key).css("color");
  647. unit["size"] = $(".varval", "#"+key).css("font-size");
  648. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  649. }
  650. tmp["header"] = header;
  651. tmp["unit"] = unit;
  652. }
  653. position[key] = tmp;
  654. }
  655. });
  656. //console.log("Check here");
  657. //console.log(position);
  658. var dataToSend = JSON.stringify(position);
  659. //console.log(dataToSend);
  660. $.ajax({
  661. url: '/save/',
  662. type: 'POST',
  663. data: dataToSend,
  664. success: function (response) {
  665. var objresponse = JSON.parse(response);
  666. console.log(objresponse);
  667. },
  668. error: function () {
  669. console.log("Error.")
  670. }
  671. });
  672. }
  673. function highlight(mydata) {
  674. varname = $("#varname option:selected").text();
  675. vartype = $("#"+varname).attr("data-type");
  676. $("#vartype").val(vartype);
  677. //console.log(varname, vartype);
  678. // clear values
  679. $("#elem_title_text").val("");
  680. $("#elem_title_size").val("");
  681. $("#elem_unit_text").val("");
  682. $("#elem_unit_size").val("");
  683. $("#elem_lesser_range").val("");
  684. $("#elem_larger_range").val("");
  685. $("#elem_condition_range").val("");
  686. $("#elem_formula").val("");
  687. if (vartype == "header") {
  688. $("#elem_title_text").val($("#"+varname + " .title").text());
  689. $("#elem_title_size").val(parseInt($("#"+varname + " .title").css("font-size")));
  690. } else if (vartype == "data") {
  691. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  692. $("#elem_title_size").val("");
  693. if ($("#"+varname + " .title").css("font-size")) {
  694. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  695. }
  696. $("#elem_unit_text").val($("#"+varname + " .unit_title").text().trim());
  697. $("#elem_unit_size").val("");
  698. if ($("#"+varname + " .varval").css("font-size")) {
  699. $("#elem_unit_size").val(parseFloat($("#"+varname + " .varval").css("font-size")));
  700. }
  701. $("#elem_lesser_range").val("");
  702. if ($("#"+varname).attr("data-lesser") ) {
  703. $("#elem_lesser_range").val($("#"+varname).attr("data-lesser"));
  704. }
  705. $("#elem_larger_range").val("");
  706. if ($("#"+varname).attr("data-larger") ) {
  707. $("#elem_larger_range").val($("#"+varname).attr("data-larger"));
  708. }
  709. $("#elem_condition_range").val("");
  710. if ($("#"+varname).attr("data-cond") ) {
  711. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  712. }
  713. $("#elem_formula").val("");
  714. if ($("#"+varname).attr("data-formula") ) {
  715. $("#elem_formula").val($("#"+varname).attr("data-formula"));
  716. }
  717. } else if (vartype == "calc") {
  718. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  719. $("#elem_title_size").val("");
  720. if ($("#"+varname + " .title").css("font-size")) {
  721. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  722. }
  723. $("#elem_unit_text").val($("#"+varname + " .unit_title").text().trim());
  724. $("#elem_unit_size").val("");
  725. if ($("#"+varname + " .varval").css("font-size")) {
  726. $("#elem_unit_size").val(parseFloat($("#"+varname + " .varval").css("font-size")));
  727. }
  728. $("#elem_lesser_range").val("");
  729. if ($("#"+varname).attr("data-lesser") ) {
  730. $("#elem_lesser_range").val($("#"+varname).attr("data-lesser"));
  731. }
  732. $("#elem_larger_range").val("");
  733. if ($("#"+varname).attr("data-larger") ) {
  734. $("#elem_larger_range").val($("#"+varname).attr("data-larger"));
  735. }
  736. $("#elem_condition_range").val("");
  737. if ($("#"+varname).attr("data-cond") ) {
  738. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  739. }
  740. $("#elem_formula").val("");
  741. if ($("#"+varname).attr("data-formula") ) {
  742. $("#elem_formula").val($("#"+varname).attr("data-formula"));
  743. }
  744. } else if (vartype == "ventil") {
  745. $("#elem_unit_text").val("{'on':"+$("#"+varname).attr("data-on") + ",'off':"+$("#"+varname).attr("data-off")+"}" );
  746. } else if (vartype == "integer-to-string") {
  747. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  748. $("#elem_title_size").val("");
  749. if ($("#"+varname + " .title").css("font-size")) {
  750. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  751. }
  752. $("#elem_unit_text").val($("#"+varname).attr("data-dict"));
  753. $("#elem_condition_range").val("");
  754. if ($("#"+varname).attr("data-cond") ) {
  755. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  756. }
  757. }
  758. for(key in mydata) {
  759. //console.log(key, varname);
  760. if(($("#" + key).length > 0) && (key == varname) ) {
  761. //if (!$("#"+varname).hasClass("box_highlight")) {
  762. $("#"+key).addClass("box_highlight");
  763. //}
  764. } else {
  765. $("#"+key).removeClass("box_highlight");
  766. }
  767. }
  768. }
  769. jQuery(window).load(function () {
  770. $("#varname > option").each(function() {
  771. if ($('#'+this.text).length){
  772. $('#'+this.text).draggable();
  773. $('#'+this.text).resizable();
  774. $('#'+this.text).click(function() {
  775. console.log($(this).attr("id"));
  776. $("#varname").val($(this).attr("id"));
  777. $("#buttonHighlight").trigger("click");
  778. });
  779. }
  780. //console.log(this.text + ' ' + this.value);
  781. });
  782. //$('[id^=header_]').each(function( index ) {
  783. // $(this).draggable();
  784. // $(this).resizable();
  785. //});
  786. $("#buttonHighlight").trigger("click");
  787. $("#varname").change(function() {
  788. varval = $( "#varname option:selected").val();
  789. varname = $("#varname option:selected").text();
  790. console.log(varval, varname);
  791. $("#buttonHighlight").trigger("click");
  792. });
  793. $("#vartype").change(function() {
  794. vartype = $("#vartype option:selected").val();
  795. if ((vartype == "header") || (vartype == "calc")) {
  796. $("#varname").val("");
  797. // clear values
  798. $("#elem_title_text").val("");
  799. $("#elem_title_size").val("");
  800. $("#elem_unit_text").val("");
  801. $("#elem_unit_size").val("");
  802. $("#elem_lesser_range").val("");
  803. $("#elem_larger_range").val("");
  804. $("#elem_condition_range").val("");
  805. $("#elem_formula").val("");
  806. }
  807. });
  808. });
  809. </script>
  810. </body>
  811. </html>