designer.html 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  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 "linkhtml" in data['style'][key] %}
  70. data-linkhtml="{{ data['style'][key]['linkhtml'] }}"
  71. {% else %}
  72. {% end %}
  73. {% if "exponential" in data['style'][key] %}
  74. data-exponential="{{ data['style'][key]['exponential'] }}"
  75. {% else %}
  76. {% end %}
  77. data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  78. <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>
  79. </div>
  80. {% else %}
  81. {% end %}
  82. {% if data['style'][key]['type'] == "icon" %}
  83. {% if data['style'][key]['icon'] == "valve" %}
  84. <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;'
  85. {% if "linkhtml" in data['style'][key] %}
  86. data-linkhtml="{{ data['style'][key]['linkhtml'] }}"
  87. {% else %}
  88. {% end %}
  89. {% if "on_condition" in data['style'][key] %}
  90. data-onexpression="{{ data['style'][key]['on_condition'] }}"
  91. {% else %}
  92. {% end %}
  93. {% if "off_condition" in data['style'][key] %}
  94. data-offexpression="{{ data['style'][key]['off_condition'] }}"
  95. {% else %}
  96. {% end %}
  97. {% if "icon" in data['style'][key] %}
  98. data-icon="{{ data['style'][key]['icon'] }}"
  99. {% else %}
  100. {% end %}
  101. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  102. <img width='100%' height='100%' src='{{ static_url("valve_inactive.png") }}'></img>
  103. </div>
  104. {% else %}
  105. {% end %}
  106. {% if data['style'][key]['icon'] == "commbit" %}
  107. <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;'
  108. {% if "linkhtml" in data['style'][key] %}
  109. data-linkhtml="{{ data['style'][key]['linkhtml'] }}"
  110. {% else %}
  111. {% end %}
  112. {% if "on_condition" in data['style'][key] %}
  113. data-onexpression="{{ data['style'][key]['on_condition'] }}"
  114. {% else %}
  115. {% end %}
  116. {% if "off_condition" in data['style'][key] %}
  117. data-offexpression="{{ data['style'][key]['off_condition'] }}"
  118. {% else %}
  119. {% end %}
  120. {% if "icon" in data['style'][key] %}
  121. data-icon="{{ data['style'][key]['icon'] }}"
  122. {% else %}
  123. {% end %}
  124. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  125. <img width='100%' height='100%' src='{{ static_url("commbit_inactive.svg") }}'></img>
  126. </div>
  127. {% else %}
  128. {% end %}
  129. {% if data['style'][key]['icon'] == "alarm" %}
  130. <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;'
  131. {% if "linkhtml" in data['style'][key] %}
  132. data-linkhtml="{{ data['style'][key]['linkhtml'] }}"
  133. {% else %}
  134. {% end %}
  135. {% if "on_condition" in data['style'][key] %}
  136. data-onexpression="{{ data['style'][key]['on_condition'] }}"
  137. {% else %}
  138. {% end %}
  139. {% if "off_condition" in data['style'][key] %}
  140. data-offexpression="{{ data['style'][key]['off_condition'] }}"
  141. {% else %}
  142. {% end %}
  143. {% if "icon" in data['style'][key] %}
  144. data-icon="{{ data['style'][key]['icon'] }}"
  145. {% else %}
  146. {% end %}
  147. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  148. <img width='100%' height='100%' src='{{ static_url("alarm_inactive.svg") }}'></img>
  149. </div>
  150. {% else %}
  151. {% end %}
  152. {% if data['style'][key]['icon'] == "TMP" %}
  153. <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;'
  154. {% if "linkhtml" in data['style'][key] %}
  155. data-linkhtml="{{ data['style'][key]['linkhtml'] }}"
  156. {% else %}
  157. {% end %}
  158. {% if "on_condition" in data['style'][key] %}
  159. data-onexpression="{{ data['style'][key]['on_condition'] }}"
  160. {% else %}
  161. {% end %}
  162. {% if "off_condition" in data['style'][key] %}
  163. data-offexpression="{{ data['style'][key]['off_condition'] }}"
  164. {% else %}
  165. {% end %}
  166. {% if "icon" in data['style'][key] %}
  167. data-icon="{{ data['style'][key]['icon'] }}"
  168. {% else %}
  169. {% end %}
  170. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  171. <img width='100%' height='100%' src='{{ static_url("TMP_inactive.svg") }}'></img>
  172. </div>
  173. {% else %}
  174. {% end %}
  175. {% if data['style'][key]['icon'] == "bottle" %}
  176. <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;'
  177. {% if "linkhtml" in data['style'][key] %}
  178. data-linkhtml="{{ data['style'][key]['linkhtml'] }}"
  179. {% else %}
  180. {% end %}
  181. {% if "on_condition" in data['style'][key] %}
  182. data-onexpression="{{ data['style'][key]['on_condition'] }}"
  183. {% else %}
  184. {% end %}
  185. {% if "off_condition" in data['style'][key] %}
  186. data-offexpression="{{ data['style'][key]['off_condition'] }}"
  187. {% else %}
  188. {% end %}
  189. {% if "icon" in data['style'][key] %}
  190. data-icon="{{ data['style'][key]['icon'] }}"
  191. {% else %}
  192. {% end %}
  193. data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  194. <img width='100%' height='100%' src='{{ static_url("bottle_inactive.svg") }}'></img>
  195. </div>
  196. {% else %}
  197. {% end %}
  198. {% else %}
  199. {% end %}
  200. {% if data['style'][key]['type'] == "integer-to-string" %}
  201. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  202. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  203. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};'
  204. {% if "cond" in data['style'][key] %}
  205. data-cond="{{ data['style'][key]['cond'] }}"
  206. {% else%}
  207. {% end%}
  208. {% if "linkhtml" in data['style'][key] %}
  209. data-linkhtml="{{ data['style'][key]['linkhtml'] }}"
  210. {% else %}
  211. {% end %}
  212. data-dict="{{ data['style'][key]['dict'] }}" data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  213. <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>
  214. </div>
  215. {% else %}
  216. {% end %}
  217. {% if data['style'][key]['type'] == "header" %}
  218. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
  219. data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
  220. height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};' data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
  221. <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>
  222. </div>
  223. {% else %}
  224. {% end %}
  225. {% end %}
  226. {% else %}
  227. {% end %}
  228. <div id="tool-btn">
  229. <span class="info">Variable</span>
  230. <select id="varname" style="font-size:16pt;">
  231. {% if data['index'] %}
  232. {% for key in data['index'] %}
  233. {% if key != "time" %}
  234. <option value={{ key }}>{{key}}</option>
  235. {% else %}
  236. {% end %}
  237. {% end %}
  238. {% else %}
  239. {% end %}
  240. </select>
  241. <span class="info">Type</span>
  242. <select id="vartype" onchange="inputEnable()" style="font-size:16pt;">
  243. <option value="data">data</option>
  244. <option value="icon">icon</option>
  245. <option value="integer-to-string">integer-to-string</option>
  246. <option value="header">header</option>
  247. <option value="calc">calc</option>
  248. </select>
  249. <span class="info">Icon</span>
  250. <select id="icon" style="font-size:16pt;" disabled="true">
  251. <option disabled selected value></option>
  252. <option value="valve">valve</option>
  253. <option value="commbit">commbit</option>
  254. <option value="alarm">alarm</option>
  255. <option value="TMP">TMP</option>
  256. <option value="bottle">bottle</option>
  257. </select>
  258. <span class="info">Attribute</span>
  259. <select id="varattr" style="font-size:16pt;">
  260. <option value="normal">Normal</option>
  261. <option value="virtual">Virtual</option>
  262. </select>
  263. <span class="info">Virtual ID</span>
  264. <input type="text" id="virtual_id_text" placeholder="text" style="font-size:16pt; width=100px;"/>
  265. <br /><br />
  266. <span class="info">Condition: on when x </span>
  267. <select id="onexpression" style="font-size:16pt;" disabled>
  268. <option value="onsmaller"><</option>
  269. <option value="onequal">=</option>
  270. <option value="ongreater">></option>
  271. </select>
  272. <input type="text" id="onvalue" placeholder="number" style="font-size:16pt; width=100px;" disabled/>
  273. <span class="info">&nbsp;&nbsp;&nbsp;&nbsp; off when x </span>
  274. <select id="offexpression" style="font-size:16pt;" disabled>
  275. <option value="offsmaller"><</option>
  276. <option value="offequal">=</option>
  277. <option value="offgreater">></option>
  278. </select>
  279. <input type="text" id="offvalue" placeholder="number" style="font-size:16pt; width=100px;" disabled/>
  280. <br /><br />
  281. <span class="info">Title</span>:
  282. <input type="text" id="elem_title_text" placeholder="text" style="font-size:16pt; width=100px;"/>
  283. <input type="text" id="elem_title_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  284. <input type="text" id="elem_lesser_range" placeholder="smaller than (red)" style="font-size:16pt; width=100px;"/>
  285. <input type="text" id="elem_larger_range" placeholder="larger than (red)" style="font-size:16pt; width=100px;"/>
  286. <select id="elem_title_style" style="font-size:16pt;">
  287. <option value="400">normal</option>
  288. <option value="700">bold</option>
  289. </select>
  290. <br /><br />
  291. <span class="info">Value</span>
  292. <input type="text" id="elem_unit_text" placeholder="unit" style="font-size:16pt; width=100px;"/>
  293. <input type="text" id="elem_unit_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  294. <input type="text" id="elem_condition_range" placeholder="condition (red)" style="font-size:16pt; width=100px;"/>
  295. <input type="text" id="elem_formula" placeholder="Equation" style="font-size:16pt; width=100px;"/>
  296. <select id="elem_unit_style" style="font-size:16pt;">
  297. <option value="400">normal</option>
  298. <option value="700">bold</option>
  299. </select>
  300. <span class="info">Exp</span><input type="checkbox" id="elem_exponential" style="font-size:16pt; width:20px; height:20px;"/>
  301. <br /><br />
  302. <button class="button save" onclick="backup()">Backup</button>
  303. <button style="display:none;" id="buttonHighlight" class="button highlight" onclick="highlight({{ data['cache'] }})">Highlight</button>
  304. <button class="button add" onclick="add()">Add</button>
  305. <button class="button remove" onclick="myremove()">Remove</button>
  306. <button class="button save" onclick="mysave({{ data['cache'] }})">Save</button>
  307. <span class="info"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Background colour</span>
  308. <input type="text" id="background_color" placeholder="hex code" style="font-size:16pt; width=100px;"/>
  309. <span class="info">Link</span><input type="checkbox" id="elem_linkhtml" style="font-size:16pt; width:20px; height:20px;"/>
  310. </div>
  311. <!-- java script -->
  312. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  313. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  314. <script>
  315. function inputEnable() {
  316. if ($("#vartype option:selected").val()=="icon") {
  317. $("#icon").prop("disabled",false);
  318. $("#onexpression").prop("disabled",false);
  319. $("#onvalue").prop("disabled",false);
  320. $("#offexpression").prop("disabled",false);
  321. $("#offvalue").prop("disabled",false);
  322. } else {
  323. $("#icon").prop("disabled",true);
  324. $("#onexpression").prop("disabled",true);
  325. $("#onvalue").prop("disabled",true);
  326. $("#offexpression").prop("disabled",true);
  327. $("#offvalue").prop("disabled",true);
  328. }
  329. }
  330. function backup() {
  331. $.ajax({
  332. url: '/backup/',
  333. type: 'POST',
  334. success: function (response) {
  335. alert("Backup success!");
  336. },
  337. error: function () {
  338. console.log("Error.")
  339. }
  340. });
  341. }
  342. function showhide() {
  343. console.log("Show or Hide");
  344. $("#tool-btn").toggle();
  345. }
  346. function add() {
  347. console.log("add element");
  348. title_text = $("#elem_title_text").val();
  349. title_text = title_text.trim();
  350. title_color = "#000000";
  351. //title_color = $("#elem_title_color").val();
  352. title_size = $("#elem_title_size").val();
  353. title_style = $("#elem_title_style option:selected").val();
  354. unit_text = $("#elem_unit_text").val();
  355. unit_text = unit_text.trim();
  356. unit_color = "#000";
  357. //unit_color = $("#elem_unit_color").val();
  358. unit_size = $("#elem_unit_size").val();
  359. unit_style = $("#elem_unit_style option:selected").val();
  360. data_condition = $("#elem_condition_range").val();
  361. //data_max = $("#elem_max_range").val();
  362. data_formula = $("#elem_formula").val();
  363. virtual_id = $("#virtual_id_text").val();
  364. virtual_id = virtual_id.trim();
  365. if (virtual_id == "") {
  366. virtual_id = "0";
  367. }
  368. if ($('#elem_exponential').is(":checked")) {
  369. data_exponential = true;
  370. $("#"+key).attr("data-exponential", true);
  371. } else {
  372. data_exponential = false;
  373. $("#"+key).attr("data-exponential", false);
  374. }
  375. if ($('#elem_linkhtml').is(":checked")) {
  376. data_linkhtml = true;
  377. $("#"+key).attr("data-linkhtml", true);
  378. } else {
  379. data_linkhtml = false;
  380. $("#"+key).attr("data-linkhtml", false);
  381. }
  382. data_lesser = $("#elem_lesser_range").val();
  383. data_larger = $("#elem_larger_range").val();
  384. background_color = $("#background_color").val();
  385. varval = $( "#varname option:selected").val();
  386. varname = $("#varname option:selected").text();
  387. vartype = $("#vartype option:selected").val();
  388. icon = $("#icon option:selected").val();
  389. onexpression = $("#onexpression option:selected").val();
  390. onvalue = $("#onvalue").val();
  391. offexpression = $("#offexpression option:selected").val();
  392. offvalue = $("#offvalue").val();
  393. varattr = $("#varattr option:selected").val();
  394. console.log("Selected");
  395. console.log(varattr);
  396. console.log(virtual_id);
  397. console.log(vartype);
  398. console.log(title_text, unit_text, background_color, varname, varval, vartype);
  399. if(($("#" + varname).length == 0) || (vartype=="header") || (vartype=="calc") || (varattr=="virtual")) {
  400. console.log("Must enter here");
  401. console.log(vartype);
  402. if (vartype == "data") {
  403. if (varattr=="virtual") {
  404. virtual_name = "virtual_" + varname + "_" + virtual_id;
  405. if ( $("#" + virtual_name).length > 0 ) {
  406. for (i = 0; i < 50; i++) {
  407. virtual_name = "virtual_" + varname + "_" + i.toString();
  408. console.log($("#" + virtual_name).length);
  409. if (!$("#" + virtual_name).length){
  410. break;
  411. }
  412. }
  413. }
  414. varname = virtual_name;
  415. }
  416. console.log("Data");
  417. html_text = "<div " +
  418. "style='position: absolute; " +
  419. "top:0; " +
  420. "left:0; " +
  421. "background-color:" + background_color + "'" +
  422. "class='varbox box_highlight' " +
  423. "id='" + varname +
  424. "' data-type='" + vartype +
  425. "' data-cond='" + data_condition +
  426. "' data-formula='" + data_formula +
  427. "' data-lesser='" + data_lesser +
  428. "' data-larger='" + data_larger +
  429. "' data-exponential='" + data_exponential +
  430. "' data-linkhtml='" + data_linkhtml +
  431. "'>" +
  432. "<p>" +
  433. "<span style='color: " + title_color + ";" +
  434. "font-size:" + title_size + "px; " +
  435. "font-weight: " + title_style + ";' " +
  436. "class='title'>" + title_text +
  437. " </span>" +
  438. "<span style='color: " + unit_color + "; " +
  439. "font-size:" + unit_size + "px; " +
  440. "font-weight: " + unit_style + ";' " +
  441. "class='varval'>XXX.XX </span>" +
  442. "<span class='unit_title'>" + unit_text + "</span></p>" +
  443. "</div>";
  444. } else if (vartype == "header") {
  445. console.log("Header");
  446. if (title_text.length > 0) {
  447. var clean_text = title_text.replace(/[^a-zA-Z0-9 ]/g, "")
  448. varname = "header_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  449. html_text = "<div " +
  450. "style='position: absolute; " +
  451. "top:0; " +
  452. "left:0; " +
  453. "background-color:" + background_color + "'" +
  454. "class='varbox box_highlight' " +
  455. "id='" + varname +
  456. "' data-type='" + vartype +
  457. "' data-cond='" + data_condition +
  458. "' data-lesser='" + data_lesser +
  459. "' data-larger='" + data_larger +
  460. "'>" +
  461. "<p>" +
  462. "<span style='color: " + title_color + ";" +
  463. "font-size:" + title_size + "px; " +
  464. "font-weight: " + title_style + ";' " +
  465. "class='title'>" + title_text +
  466. " </span></p>" +
  467. "</div>";
  468. $('#varname').append($('<option>', {
  469. value: varname,
  470. text: varname
  471. }));
  472. $('#varname').val(varname);
  473. $('#elem_title_text').removeClass('glowing_border');
  474. } else {
  475. console.log("NoInput");
  476. html_text = "";
  477. $('#elem_title_text').addClass('glowing_border');
  478. }
  479. } else if (vartype == "calc") {
  480. console.log("Calc");
  481. if (data_formula.length > 0) {
  482. var clean_text = data_formula.replace(/[^a-zA-Z0-9 ]/g, "")
  483. varname = "calc_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  484. console.log(varname);
  485. html_text = "<div " +
  486. "style='position: absolute; " +
  487. "top:0; " +
  488. "left:0; " +
  489. "background-color:" + background_color + "'" +
  490. "class='varbox box_highlight' " +
  491. "id='" + varname +
  492. "' data-type='" + vartype +
  493. "' data-cond='" + data_condition +
  494. "' data-lesser='" + data_lesser +
  495. "' data-larger='" + data_larger +
  496. "' data-formula='" + data_formula +
  497. "'>" +
  498. "<p>" +
  499. "<span style='color: " + title_color + ";" +
  500. "font-size:" + title_size + "px; " +
  501. "font-weight: " + title_style + ";' " +
  502. "class='title'>" + title_text +
  503. " </span>" +
  504. "<span style='color: " + unit_color + "; " +
  505. "font-size:" + unit_size + "px; " +
  506. "font-weight: " + unit_style + ";' " +
  507. "class='varval'>XXX.XX </span>" +
  508. "<span class='unit_title'>" + unit_text + "</span></p>" +
  509. "</div>";
  510. $('#varname').append($('<option>', {
  511. value: varname,
  512. text: varname
  513. }));
  514. $('#varname').val(varname);
  515. $('#elem_formula').removeClass('glowing_border');
  516. } else {
  517. console.log("NoInput");
  518. html_text = "";
  519. $('#elem_formula').addClass('glowing_border');
  520. }
  521. } else if (vartype == "icon") {
  522. if (varattr=="virtual") {
  523. virtual_name = "virtual_" + varname + "_" + virtual_id;
  524. if ( $("#" + virtual_name).length > 0 ) {
  525. for (i = 0; i < 50; i++) {
  526. virtual_name = "virtual_" + varname + "_" + i.toString();
  527. console.log($("#" + virtual_name).length);
  528. if (!$("#" + virtual_name).length){
  529. break;
  530. }
  531. }
  532. }
  533. varname = virtual_name;
  534. }
  535. console.log(icon);
  536. if ((onvalue.length > 0)&&(offvalue.length > 0)) {
  537. //var token = JSON.parse(unit_text);
  538. //data_on = token["on"];
  539. //data_off = token["off"];
  540. html_text = "<div " +
  541. "style='position: absolute; " +
  542. "top:0; " +
  543. "left:0;' " +
  544. "class='varbox box_highlight' " +
  545. "id='" + varname +
  546. "' data-type='" + vartype +
  547. "' data-cond='" + data_condition +
  548. "' data-icon='" + icon +
  549. "' data-lesser='" + data_lesser +
  550. "' data-larger='" + data_larger +
  551. "' data-onexpression='" + onexpression +
  552. "' data-on='" + onvalue +
  553. "' data-offexpression='" + offexpression +
  554. "' data-off='" + offvalue +
  555. "' data-linkhtml='" + data_linkhtml +
  556. "'>" +
  557. "<img width='100%' height='100%' " +
  558. "src='/static/" + icon + "_inactive.svg' ></img>" +
  559. "</div>";
  560. $('#onvalue').removeClass('glowing_border');
  561. $('#offvalue').removeClass('glowing_border');
  562. } else{
  563. console.log("NoInput");
  564. html_text = "";
  565. $('#onvalue').addClass('glowing_border');
  566. $('#offvalue').addClass('glowing_border');
  567. }
  568. } else if (vartype == "integer-to-string") {
  569. if (varattr=="virtual") {
  570. virtual_name = "virtual_" + varname + "_" + virtual_id;
  571. if ( $("#" + virtual_name).length > 0 ) {
  572. for (i = 0; i < 50; i++) {
  573. virtual_name = "virtual_" + varname + "_" + i.toString();
  574. console.log($("#" + virtual_name).length);
  575. if (!$("#" + virtual_name).length){
  576. break;
  577. }
  578. }
  579. }
  580. varname = virtual_name;
  581. }
  582. console.log("Integer2String");
  583. if (unit_text.length > 0) {
  584. html_text = "<div " +
  585. "style='position: absolute; " +
  586. "top:0; " +
  587. "left:0; " +
  588. "background-color:" + background_color + "'" +
  589. "class='varbox box_highlight' " +
  590. "id='" + varname +
  591. "' data-type='" + vartype +
  592. "' data-dict='" + unit_text +
  593. "' data-cond='" + data_condition +
  594. "' data-linkhtml='" + data_linkhtml +
  595. "'>" +
  596. "<p>" +
  597. "<span style='color: " + title_color + ";" +
  598. "font-size:" + title_size + "px; " +
  599. "font-weight: " + title_style + ";' " +
  600. "class='title'>" + title_text +
  601. " </span><br />" +
  602. "<span style='color: " + unit_color + "; " +
  603. "font-size:" + unit_size + "px; " +
  604. "font-weight: " + unit_style + ";' " +
  605. "class='varval'>??? </span>" +
  606. "</p>" +
  607. "</div>";
  608. $('#elem_unit_text').removeClass('glowing_border');
  609. } else {
  610. console.log("NoInput");
  611. html_text = "";
  612. $('#elem_unit_text').addClass('glowing_border');
  613. }
  614. }
  615. console.log("Adding element");
  616. console.log(html_text);
  617. if (html_text.length > 0) {
  618. $( "body" ).append(html_text);
  619. $("#"+varname).draggable();
  620. $("#"+varname).resizable();
  621. }
  622. }
  623. }
  624. function myremove() {
  625. varname = $("#varname option:selected").text();
  626. vartype = $("#vartype option:selected").val();
  627. if($("#" + varname).length > 0) {
  628. $("#"+varname).remove();
  629. console.log(varname +" removed.");
  630. nexpression = $("#onexpression option:selected").val();
  631. onvalue = $("#onvalue").val();
  632. }
  633. }
  634. function mysave(data) {
  635. console.log("saving...");
  636. varname = $("#varname option:selected").text();
  637. varattr = $("#varattr option:selected").val();
  638. console.log("debug");
  639. console.log(varattr);
  640. var position = {};
  641. for(key in data) {
  642. var tmp = {};
  643. //console.log(key);
  644. if($("#" + key).length > 0 ) {
  645. tmp["ref"] = key;
  646. tmp["left"] = $("#"+key).css("left");
  647. tmp["top"] = $("#"+key).css("top");
  648. tmp["width"] = $("#"+key).width();
  649. tmp["height"] = $("#"+key).height();
  650. tmp["type"] = $("#"+key).attr("data-type");
  651. if ( $("#"+key).attr("data-type") == "data" ) {
  652. if ( (varname == key) && (varattr == "normal") ) {
  653. tmp["condition"] = $("#elem_condtion_range").val();
  654. tmp["formula"] = $("#elem_formula").val();
  655. tmp["lesser"] = $("#elem_lesser_range").val();
  656. tmp["larger"] = $("#elem_larger_range").val();
  657. if ($('#elem_exponential').is(":checked")) {
  658. tmp["exponential"] = "true";
  659. $("#"+key).attr("data-exponential", "true");
  660. } else {
  661. tmp["exponential"] = "false";
  662. $("#"+key).attr("data-exponential", "false");
  663. }
  664. if ($('#elem_linkhtml').is(":checked")) {
  665. tmp["linkhtml"] = "true";
  666. $("#"+key).attr("data-linkhtml", "true");
  667. } else {
  668. tmp["linkhtml"] = "false";
  669. $("#"+key).attr("data-linkhtml","false");
  670. }
  671. if ($('#background_color').val().length > 0) {
  672. tmp["background_color"] = $('#background_color').val();
  673. } else {
  674. tmp["background_color"] = '#0000ffff';
  675. }
  676. //console.log($("#"+key).css("background-color"));
  677. header = {};
  678. header["title"] = $("#elem_title_text").val().trim();
  679. //header["color"] = $(".title", "#"+key).css("color");
  680. header["size"] = $("#elem_title_size").val();
  681. header["weight"] = $("#elem_title_style").val();
  682. // update field
  683. $(".title", "#"+key).text(header["title"]);
  684. $(".title", "#"+key).css("font-size", header["size"] + "px");
  685. $(".title", "#"+key).css("font-weight", header["weight"]);
  686. unit = {};
  687. unit["title"] = $("#elem_unit_text").val().trim();
  688. //unit["color"] = $(".varval", "#"+key).css("color");
  689. unit["size"] = $("#elem_unit_size").val();
  690. unit["weight"] = $("#elem_unit_style").val();
  691. $(".varval", "#"+key).css("font-size", unit["size"] + "px");
  692. $(".unit_title", "#"+key).css("font-size", unit["size"] + "px");
  693. $(".unit_title", "#"+key).css("font-weight", unit["weight"]);
  694. $(".varval", "#"+key).css("font-weight", unit["weight"]);
  695. } else {
  696. tmp["condition"] = $("#"+key).attr("data-cond");
  697. tmp["formula"] = $("#"+key).attr("data-formula");
  698. tmp["lesser"] = $("#"+key).attr("data-lesser");
  699. tmp["larger"] = $("#"+key).attr("data-larger");
  700. tmp["exponential"] = $("#"+key).attr("data-exponential");
  701. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  702. //tmp["min"] = $("#"+key).attr("min");
  703. //tmp["max"] = $("#"+key).attr("max");
  704. header = {};
  705. header["title"] = $(".title", "#"+key).text();
  706. //header["color"] = $(".title", "#"+key).css("color");
  707. header["size"] = parseInt($(".title", "#"+key).css("font-size")) || 28;
  708. tmp["background_color"] = $("#"+key).css("background-color");
  709. var fontWeight = $(".title", "#"+key).css("font-weight");
  710. if (fontWeight == 'bold' || fontWeight == '700') {
  711. header["weight"] = "700";
  712. } else {
  713. header["weight"] = "400";
  714. }
  715. unit = {};
  716. unit["title"] = $(".unit_title", "#"+key).text();
  717. //unit["color"] = $(".varval", "#"+key).css("color");
  718. unit["size"] = parseInt($(".varval", "#"+key).css("font-size")) || 28;
  719. fontWeight = $(".varval", "#"+key).css("font-weight");
  720. if (fontWeight == 'bold' || fontWeight == '700') {
  721. unit["weight"] = "700";
  722. } else {
  723. unit["weight"] = "400";
  724. }
  725. }
  726. tmp["header"] = header;
  727. tmp["unit"] = unit;
  728. //} else if ( $("#"+key).attr("data-type") == "header" ) {
  729. // header = {};
  730. // header["title"] = $(".title", "#"+key).text();
  731. // header["size"] = $(".title", "#"+key).css("font-size");
  732. // header["weight"] = $(".title", "#"+key).css("font-weight");
  733. // tmp["header"] = header;
  734. } else if ( $("#"+key).attr("data-type") == "icon" ) {
  735. if ((varname == key) && (varattr == "normal")) {
  736. //var unit_text = $("#elem_unit_text").val();
  737. //unit_text = unit_text.trim();
  738. //var dtoken = JSON.parse(unit_text);
  739. tmp["on"] = $("#onvalue").val();
  740. tmp["on_condition"] = $("#onexpression").val();
  741. tmp["off"] = $("#offvalue").val();
  742. tmp["off_condition"] = $("#offexpression").val();
  743. tmp["icon"] = $("#"+key).attr("data-icon");
  744. if ($('#elem_linkhtml').is(":checked")) {
  745. tmp["linkhtml"] = "true";
  746. $("#"+key).attr("data-linkhtml", "true");
  747. } else {
  748. tmp["linkhtml"] = "false";
  749. $("#"+key).attr("data-linkhtml","false");
  750. }
  751. } else {
  752. tmp["icon"] = $("#"+key).attr("data-icon");
  753. tmp["on"] = $("#"+key).attr("data-on");
  754. tmp["on_condition"] = $("#"+key).attr("data-onexpression");
  755. tmp["off"] = $("#"+key).attr("data-off");
  756. tmp["off_condition"] = $("#"+key).attr("data-offexpression");
  757. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  758. }
  759. /*
  760. } else if ( $("#"+key).attr("data-type") == "commbit" ) {
  761. if ((varname == key) && (varattr == "normal")) {
  762. var unit_text = $("#elem_unit_text").val();
  763. unit_text = unit_text.trim();
  764. var dtoken = JSON.parse(unit_text);
  765. tmp["on"] = dtoken["on"];
  766. tmp["off"] = dtoken["off"];
  767. if ($('#elem_linkhtml').is(":checked")) {
  768. tmp["linkhtml"] = "true";
  769. $("#"+key).attr("data-linkhtml", "true");
  770. } else {
  771. tmp["linkhtml"] = "false";
  772. $("#"+key).attr("data-linkhtml","false");
  773. }
  774. } else {
  775. tmp["on"] = $("#"+key).attr("data-on");
  776. tmp["off"] = $("#"+key).attr("data-off");
  777. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  778. }
  779. } else if ( $("#"+key).attr("data-type") == "alarm" ) {
  780. if ((varname == key) && (varattr == "normal")) {
  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. if ($('#elem_linkhtml').is(":checked")) {
  787. tmp["linkhtml"] = "true";
  788. $("#"+key).attr("data-linkhtml", "true");
  789. } else {
  790. tmp["linkhtml"] = "false";
  791. $("#"+key).attr("data-linkhtml","false");
  792. }
  793. } else {
  794. tmp["on"] = $("#"+key).attr("data-on");
  795. tmp["off"] = $("#"+key).attr("data-off");
  796. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  797. }*/
  798. } else if ( $("#"+key).attr("data-type") == "integer-to-string" ) {
  799. if ((varname == key)&& (varattr == "normal")) {
  800. var unit_text = $("#elem_unit_text").val();
  801. unit_text = unit_text.trim();
  802. var data_condition = $("#elem_condition_range").val();
  803. tmp["cond"] = data_condition;
  804. tmp["dict"] = unit_text;
  805. if ($('#elem_linkhtml').is(":checked")) {
  806. tmp["linkhtml"] = "true";
  807. $("#"+key).attr("data-linkhtml", "true");
  808. } else {
  809. tmp["linkhtml"] = "false";
  810. $("#"+key).attr("data-linkhtml","false");
  811. }
  812. if ($('#background_color').val().length > 0) {
  813. tmp["background_color"] = $('#background_color').val();
  814. } else {
  815. tmp["background_color"] = '#0000ffff';
  816. }
  817. header = {};
  818. header["title"] = $("#elem_title_text").val().trim();
  819. header["size"] = $("#elem_title_size").val();
  820. header["weight"] = $("#elem_title_style").val();
  821. unit = {};
  822. //unit["color"] = $(".varval", "#"+key).css("color");
  823. unit["size"] = $("#elem_unit_size").val();
  824. unit["weight"] = $("#elem_unit_style option:selected").val();
  825. } else {
  826. tmp["dict"] = $("#"+key).attr("data-dict");
  827. tmp["cond"] = $("#"+key).attr("data-cond");
  828. tmp["background_color"] = $("#"+key).css("background-color");
  829. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  830. header = {};
  831. header["title"] = $(".title", "#"+key).text();
  832. //header["color"] = $(".title", "#"+key).css("color");
  833. header["size"] = $(".title", "#"+key).css("font-size");
  834. header["weight"] = $(".title", "#"+key).css("font-weight");
  835. unit = {};
  836. //unit["title"] = $(".unit_title", "#"+key).text();
  837. //unit["color"] = $(".varval", "#"+key).css("color");
  838. unit["size"] = $(".varval", "#"+key).css("font-size");
  839. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  840. }
  841. tmp["header"] = header;
  842. tmp["unit"] = unit;
  843. }
  844. position[key] = tmp;
  845. }
  846. }
  847. var title_text = $("#elem_title_text").val();
  848. title_text = title_text.trim();
  849. var clean_text = title_text.replace(/[^a-zA-Z0-9 ]/g, "")
  850. var token = "header_" + clean_text.replace(/\s+/g, '-').toLowerCase();
  851. $('[id^=virtual_]').each(function( index ) {
  852. var tmp = {};
  853. var key = this.id;
  854. var ref = key.split("_");
  855. ref.shift();
  856. ref.pop();
  857. ref = ref.join("_");
  858. //ref = ref[1];
  859. if (key != "virtual_id_text") {
  860. console.log("Check this");
  861. console.log(key);
  862. if($("#" + key).length > 0 ) {
  863. tmp["ref"] = ref;
  864. tmp["left"] = $("#"+key).css("left");
  865. tmp["top"] = $("#"+key).css("top");
  866. tmp["width"] = $("#"+key).width();
  867. tmp["height"] = $("#"+key).height();
  868. tmp["type"] = $("#"+key).attr("data-type");
  869. if ( $("#"+key).attr("data-type") == "data" ) {
  870. if (varname == key) {
  871. tmp["condition"] = $("#elem_condtion_range").val();
  872. tmp["formula"] = $("#elem_formula").val();
  873. tmp["lesser"] = $("#elem_lesser_range").val();
  874. tmp["larger"] = $("#elem_larger_range").val();
  875. header = {};
  876. header["title"] = $("#elem_title_text").val().trim();
  877. //header["color"] = $(".title", "#"+key).css("color");
  878. header["size"] = $("#elem_title_size").val();
  879. header["weight"] = $("#elem_title_style option:selected").val();
  880. if ($('#elem_linkhtml').is(":checked")) {
  881. tmp["linkhtml"] = "true";
  882. $("#"+key).attr("data-linkhtml", "true");
  883. } else {
  884. tmp["linkhtml"] = "false";
  885. $("#"+key).attr("data-linkhtml","false");
  886. }
  887. if ($('#background_color').val().length > 0) {
  888. tmp["background_color"] = $('#background_color').val();
  889. } else {
  890. tmp["background_color"] = '#0000ffff';
  891. }
  892. // update field
  893. $(".title", "#"+key).css("font-size", header["size"] + "px");
  894. $(".title", "#"+key).css("font-weight", header["weight"] + "px");
  895. unit = {};
  896. unit["title"] = $("#elem_unit_text").val().trim();
  897. //unit["color"] = $(".varval", "#"+key).css("color");
  898. unit["size"] = $("#elem_unit_size").val();
  899. unit["weight"] = $("#elem_unit_style option:selected").val();
  900. // update field
  901. $(".varval", "#"+key).css("font-size", unit["size"] + "px");
  902. $(".unit_title", "#"+key).css("font-size", unit["size"] + "px");
  903. $(".varval", "#"+key).css("font-weight", unit["weight"] + "px");
  904. } else {
  905. tmp["condition"] = $("#"+key).attr("data-cond");
  906. tmp["formula"] = $("#"+key).attr("data-formula");
  907. tmp["lesser"] = $("#"+key).attr("data-lesser");
  908. tmp["larger"] = $("#"+key).attr("data-larger");
  909. //tmp["min"] = $("#"+key).attr("min");
  910. //tmp["max"] = $("#"+key).attr("max");
  911. tmp["background_color"] = $("#"+key).css("background-color");
  912. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  913. header = {};
  914. header["title"] = $(".title", "#"+key).text();
  915. //header["color"] = $(".title", "#"+key).css("color");
  916. header["size"] = parseInt($(".title", "#"+key).css("font-size")) || 28;
  917. header["weight"] = parseInt($(".title", "#"+key).css("font-weight")) || 28;
  918. unit = {};
  919. unit["title"] = $(".unit_title", "#"+key).text();
  920. //unit["color"] = $(".varval", "#"+key).css("color");
  921. unit["size"] = parseInt($(".varval", "#"+key).css("font-size")) || 28;
  922. unit["weight"] = parseInt($(".varval", "#"+key).css("font-weight")) || 28;
  923. }
  924. tmp["header"] = header;
  925. tmp["unit"] = unit;
  926. //} else if ( $("#"+key).attr("data-type") == "header" ) {
  927. // header = {};
  928. // header["title"] = $(".title", "#"+key).text();
  929. // header["size"] = $(".title", "#"+key).css("font-size");
  930. // header["weight"] = $(".title", "#"+key).css("font-weight");
  931. // tmp["header"] = header;
  932. } else if ( $("#"+key).attr("data-type") == "icon" ) {
  933. if (varname == key) {
  934. //var unit_text = $("#elem_unit_text").val();
  935. //unit_text = unit_text.trim();
  936. //var dtoken = JSON.parse(unit_text);
  937. tmp["on"] = $("#onvalue").val();
  938. tmp["on_condition"] = $("#onexpression").val();
  939. tmp["off"] = $("#offvalue").val();
  940. tmp["off_condition"] = $("#offexpression").val();
  941. tmp["icon"] = $("#"+key).attr("data-icon");
  942. if ($('#elem_linkhtml').is(":checked")) {
  943. tmp["linkhtml"] = "true";
  944. $("#"+key).attr("data-linkhtml", "true");
  945. } else {
  946. tmp["linkhtml"] = "false";
  947. $("#"+key).attr("data-linkhtml","false");
  948. }
  949. } else {
  950. tmp["icon"] = $("#"+key).attr("data-icon");
  951. tmp["on"] = $("#"+key).attr("data-on");
  952. tmp["on_condition"] = $("#"+key).attr("data-onexpression");
  953. tmp["off"] = $("#"+key).attr("data-off");
  954. tmp["off_condition"] = $("#"+key).attr("data-offexpression");
  955. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  956. }
  957. /*
  958. } else if ( $("#"+key).attr("data-type") == "commbit" ) {
  959. if (varname == key) {
  960. var unit_text = $("#elem_unit_text").val();
  961. unit_text = unit_text.trim();
  962. var dtoken = JSON.parse(unit_text);
  963. tmp["on"] = dtoken["on"];
  964. tmp["off"] = dtoken["off"];
  965. if ($('#elem_linkhtml').is(":checked")) {
  966. tmp["linkhtml"] = "true";
  967. $("#"+key).attr("data-linkhtml", "true");
  968. } else {
  969. tmp["linkhtml"] = "false";
  970. $("#"+key).attr("data-linkhtml","false");
  971. }
  972. } else {
  973. tmp["on"] = $("#"+key).attr("data-on");
  974. tmp["off"] = $("#"+key).attr("data-off");
  975. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  976. }
  977. } else if ( $("#"+key).attr("data-type") == "alarm" ) {
  978. if (varname == key) {
  979. var unit_text = $("#elem_unit_text").val();
  980. unit_text = unit_text.trim();
  981. var dtoken = JSON.parse(unit_text);
  982. tmp["on"] = dtoken["on"];
  983. tmp["off"] = dtoken["off"];
  984. if ($('#elem_linkhtml').is(":checked")) {
  985. tmp["linkhtml"] = "true";
  986. $("#"+key).attr("data-linkhtml", "true");
  987. } else {
  988. tmp["linkhtml"] = "false";
  989. $("#"+key).attr("data-linkhtml","false");
  990. }
  991. } else {
  992. tmp["on"] = $("#"+key).attr("data-on");
  993. tmp["off"] = $("#"+key).attr("data-off");
  994. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  995. }*/
  996. } else if ( $("#"+key).attr("data-type") == "integer-to-string" ) {
  997. if (varname == key) {
  998. var unit_text = $("#elem_unit_text").val();
  999. unit_text = unit_text.trim();
  1000. var data_condition = $("#elem_condition_range").val();
  1001. if ($('#background_color').val().length > 0) {
  1002. tmp["background_color"] = $('#background_color').val();
  1003. } else {
  1004. tmp["background_color"] = '#0000ffff';
  1005. }
  1006. if ($('#elem_linkhtml').is(":checked")) {
  1007. tmp["linkhtml"] = "true";
  1008. $("#"+key).attr("data-linkhtml", "true");
  1009. } else {
  1010. tmp["linkhtml"] = "false";
  1011. $("#"+key).attr("data-linkhtml","false");
  1012. }
  1013. tmp["cond"] = data_condition;
  1014. tmp["dict"] = unit_text;
  1015. header = {};
  1016. header["title"] = $("#elem_title_text").val().trim();
  1017. header["size"] = $("#elem_title_size").val();
  1018. header["weight"] = $("#elem_title_style option:selected").val();
  1019. unit = {};
  1020. //unit["color"] = $(".varval", "#"+key).css("color");
  1021. unit["size"] = $("#elem_unit_size").val();
  1022. unit["weight"] = $("#elem_unit_style option:selected").val();
  1023. } else {
  1024. tmp["dict"] = $("#"+key).attr("data-dict");
  1025. tmp["cond"] = $("#"+key).attr("data-cond");
  1026. tmp["background_color"] = $("#"+key).css("background-color");
  1027. tmp["linkhtml"] = $("#"+key).attr("data-linkhtml");
  1028. header = {};
  1029. header["title"] = $(".title", "#"+key).text();
  1030. //header["color"] = $(".title", "#"+key).css("color");
  1031. header["size"] = $(".title", "#"+key).css("font-size");
  1032. header["weight"] = $(".title", "#"+key).css("font-weight");
  1033. unit = {};
  1034. //unit["title"] = $(".unit_title", "#"+key).text();
  1035. //unit["color"] = $(".varval", "#"+key).css("color");
  1036. unit["size"] = $(".varval", "#"+key).css("font-size");
  1037. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  1038. }
  1039. tmp["header"] = header;
  1040. tmp["unit"] = unit;
  1041. }
  1042. position[key] = tmp;
  1043. }
  1044. }
  1045. });
  1046. $('[id^=header_]').each(function( index ) {
  1047. tmp = {};
  1048. var hkey = $( this ).attr('id');
  1049. console.log(hkey);
  1050. tmp["left"] = $("#"+hkey).css("left");
  1051. tmp["top"] = $("#"+hkey).css("top");
  1052. tmp["width"] = $("#"+hkey).width();
  1053. tmp["height"] = $("#"+hkey).height();
  1054. tmp["type"] = $("#"+hkey).attr("data-type");
  1055. header = {};
  1056. if (token == hkey) {
  1057. header["title"] = $("#elem_title_text").val().trim();
  1058. //header["color"] = $(".title", "#"+key).css("color");
  1059. header["size"] = $("#elem_title_size").val();
  1060. header["weight"] = $("#elem_title_style option:selected").val();
  1061. if ($('#background_color').val().length > 0) {
  1062. tmp["background_color"] = $('#background_color').val();
  1063. } else {
  1064. tmp["background_color"] = '#0000ffff';
  1065. }
  1066. // update field
  1067. $(".title", "#"+hkey).css("font-size", header["size"] + "px");
  1068. $(".title", "#"+hkey).css("font-weight", header["weight"]);
  1069. } else {
  1070. header["title"] = $(".title", "#"+hkey).text();
  1071. //header["color"] = $(".title", "#"+hkey).css("color");
  1072. header["size"] = parseInt($(".title", "#"+hkey).css("font-size")) || 28;
  1073. header["weight"] = parseInt($(".title", "#"+hkey).css("font-weight")) || 28;
  1074. tmp["background_color"] = $("#"+hkey).css("background-color");
  1075. var fontWeight = $(".title", "#"+hkey).css("font-weight");
  1076. if (fontWeight == 'bold' || fontWeight == '700') {
  1077. header["weight"] = "700";
  1078. } else {
  1079. header["weight"] = "400";
  1080. }
  1081. }
  1082. tmp["header"] = header;
  1083. position[hkey] = tmp;
  1084. //console.log( index + ": " + $( this ).text() );
  1085. });
  1086. $('[id^=calc_]').each(function( index ) {
  1087. var tmp = {};
  1088. var key = this.id;
  1089. if($("#" + key).length > 0 ) {
  1090. tmp["ref"] = "";
  1091. tmp["left"] = $("#"+key).css("left");
  1092. tmp["top"] = $("#"+key).css("top");
  1093. tmp["width"] = $("#"+key).width();
  1094. tmp["height"] = $("#"+key).height();
  1095. tmp["type"] = $("#"+key).attr("data-type");
  1096. if ( $("#"+key).attr("data-type") == "calc" ) {
  1097. if (varname == key) {
  1098. tmp["condition"] = $("#elem_condtion_range").val();
  1099. tmp["formula"] = $("#elem_formula").val();
  1100. tmp["lesser"] = $("#elem_lesser_range").val();
  1101. tmp["larger"] = $("#elem_larger_range").val();
  1102. header = {};
  1103. header["title"] = $("#elem_title_text").val().trim();
  1104. //header["color"] = $(".title", "#"+key).css("color");
  1105. header["size"] = $("#elem_title_size").val();
  1106. header["weight"] = $("#elem_title_style option:selected").val();
  1107. if ($('#background_color').val().length > 0) {
  1108. tmp["background_color"] = $('#background_color').val();
  1109. } else {
  1110. tmp["background_color"] = '#0000ffff';
  1111. }
  1112. unit = {};
  1113. unit["title"] = $("#elem_unit_text").val().trim();
  1114. //unit["color"] = $(".varval", "#"+key).css("color");
  1115. unit["size"] = $("#elem_unit_size").val();
  1116. unit["weight"] = $("#elem_unit_style option:selected").val();
  1117. } else {
  1118. tmp["condition"] = $("#"+key).attr("data-cond");
  1119. tmp["formula"] = $("#"+key).attr("data-formula");
  1120. tmp["lesser"] = $("#"+key).attr("data-lesser");
  1121. tmp["larger"] = $("#"+key).attr("data-larger");
  1122. //tmp["min"] = $("#"+key).attr("min");
  1123. //tmp["max"] = $("#"+key).attr("max");
  1124. tmp["background_color"] = $("#"+key).css("background-color");
  1125. header = {};
  1126. header["title"] = $(".title", "#"+key).text();
  1127. //header["color"] = $(".title", "#"+key).css("color");
  1128. header["size"] = $(".title", "#"+key).css("font-size");
  1129. header["weight"] = $(".title", "#"+key).css("font-weight");
  1130. unit = {};
  1131. unit["title"] = $(".unit_title", "#"+key).text();
  1132. //unit["color"] = $(".varval", "#"+key).css("color");
  1133. unit["size"] = $(".varval", "#"+key).css("font-size");
  1134. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  1135. }
  1136. tmp["header"] = header;
  1137. tmp["unit"] = unit;
  1138. }
  1139. position[key] = tmp;
  1140. }
  1141. });
  1142. console.log("Check here");
  1143. //console.log(position);
  1144. var dataToSend = JSON.stringify(position);
  1145. console.log(dataToSend);
  1146. $.ajax({
  1147. url: '/save/',
  1148. type: 'POST',
  1149. data: dataToSend,
  1150. success: function (response) {
  1151. var objresponse = JSON.parse(response);
  1152. console.log(objresponse);
  1153. },
  1154. error: function () {
  1155. console.log("Error.")
  1156. }
  1157. });
  1158. }
  1159. function highlight(mydata) {
  1160. console.log("highlight");
  1161. varname = $("#varname option:selected").text();
  1162. vartype = $("#"+varname).attr("data-type");
  1163. icon = $("#"+varname).attr("data-icon");
  1164. $("#vartype").val(vartype);
  1165. console.log(varname, vartype,icon);
  1166. // clear values
  1167. $("#elem_title_text").val("");
  1168. $("#elem_title_size").val("");
  1169. $("#elem_title_style").val("");
  1170. $("#elem_unit_text").val("");
  1171. $("#elem_unit_size").val("");
  1172. $("#elem_lesser_range").val("");
  1173. $("#elem_larger_range").val("");
  1174. $("#elem_condition_range").val("");
  1175. $("#elem_formula").val("");
  1176. $("#varattr").val("normal");
  1177. $("#virtual_id_text").val("");
  1178. $("#background_color").val("");
  1179. $('#elem_exponential').prop('checked', false);
  1180. $('#elem_linkhtml').prop('checked', false);
  1181. $('#elem_unit_text').removeClass('glowing_border');
  1182. $('#elem_title_text').removeClass('glowing_border');
  1183. $('#elem_formula').removeClass('glowing_border');
  1184. $("#icon").val("");
  1185. $('#icon').prop('disabled', true);
  1186. $('#onexpression').prop('disabled', true);
  1187. $('#onvalue').prop('disabled', true);
  1188. $('#offexpression').prop('disabled', true);
  1189. $('#offvalue').prop('disabled', true);
  1190. $('#onexpression').val("");
  1191. $('#onvalue').val("");
  1192. $('#offexpression').val('disabled', true);
  1193. $('#offvalue').val("");
  1194. if (vartype == "header") {
  1195. $("#elem_title_text").val($("#"+varname + " .title").text());
  1196. $("#elem_title_size").val(parseInt($("#"+varname + " .title").css("font-size")));
  1197. $("#elem_title_style").val("400");
  1198. var fontWeight = $("#"+varname + " .title").css("font-weight");
  1199. if (fontWeight == 'bold' || fontWeight == '700') {
  1200. $("#elem_title_style").val("700");
  1201. }
  1202. $("#elem_unit_style").val("400");
  1203. var fontWeight = $("#"+varname + " .varval").css("font-weight");
  1204. if (fontWeight == 'bold' || fontWeight == '700') {
  1205. $("#elem_unit_style").val("700");
  1206. }
  1207. $("#background_color").val("");
  1208. if ($("#"+varname).css("background-color") ) {
  1209. $("#background_color").val($("#"+varname).css("background-color"));
  1210. }
  1211. } else if (vartype == "data") {
  1212. if (($("#"+varname).attr("data-exponential")) == "true" || ($("#"+varname).attr("data-exponential")) == "true") {
  1213. $('#elem_exponential').prop('checked', true);
  1214. } else {
  1215. $('#elem_exponential').prop('checked', false);
  1216. }
  1217. if (($("#"+varname).attr("data-linkhtml")) == "true" || ($("#"+varname).attr("data-linkhtml")) == "true") {
  1218. $('#elem_linkhtml').prop('checked', true);
  1219. } else {
  1220. $('#elem_linkhtml').prop('checked', false);
  1221. }
  1222. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  1223. $("#elem_title_size").val("");
  1224. if ($("#"+varname + " .title").css("font-size")) {
  1225. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  1226. }
  1227. $("#elem_unit_text").val($("#"+varname + " .unit_title").text().trim());
  1228. $("#elem_unit_size").val("");
  1229. if ($("#"+varname + " .varval").css("font-size")) {
  1230. $("#elem_unit_size").val(parseFloat($("#"+varname + " .varval").css("font-size")));
  1231. }
  1232. $("#elem_lesser_range").val("");
  1233. if ($("#"+varname).attr("data-lesser") ) {
  1234. $("#elem_lesser_range").val($("#"+varname).attr("data-lesser"));
  1235. }
  1236. $("#elem_larger_range").val("");
  1237. if ($("#"+varname).attr("data-larger") ) {
  1238. $("#elem_larger_range").val($("#"+varname).attr("data-larger"));
  1239. }
  1240. $("#background_color").val("");
  1241. if ($("#"+varname).css("background-color") ) {
  1242. $("#background_color").val($("#"+varname).css("background-color"));
  1243. }
  1244. $("#elem_condition_range").val("");
  1245. if ($("#"+varname).attr("data-cond") ) {
  1246. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  1247. }
  1248. $("#elem_formula").val("");
  1249. if ($("#"+varname).attr("data-formula") ) {
  1250. $("#elem_formula").val($("#"+varname).attr("data-formula"));
  1251. }
  1252. $("#elem_title_style").val("400");
  1253. var fontWeight = $("#"+varname + " .title").css("font-weight");
  1254. if (fontWeight == 'bold' || fontWeight == '700') {
  1255. $("#elem_title_style").val("700");
  1256. }
  1257. $("#elem_unit_style").val("400");
  1258. var fontWeight = $("#"+varname + " .varval").css("font-weight");
  1259. if (fontWeight == 'bold' || fontWeight == '700') {
  1260. $("#elem_unit_style").val("700");
  1261. }
  1262. if (varname.includes("virtual")){
  1263. $("#varattr").val("virtual");
  1264. } else {
  1265. $("#varattr").val("normal");
  1266. }
  1267. } else if (vartype == "calc") {
  1268. var vid = varname.split("_");
  1269. vid = vid[1];
  1270. $("#virtual_id_text").val(vid);
  1271. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  1272. $("#elem_title_size").val("");
  1273. if ($("#"+varname + " .title").css("font-size")) {
  1274. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  1275. }
  1276. $("#elem_unit_text").val($("#"+varname + " .unit_title").text().trim());
  1277. $("#elem_unit_size").val("");
  1278. if ($("#"+varname + " .varval").css("font-size")) {
  1279. $("#elem_unit_size").val(parseFloat($("#"+varname + " .varval").css("font-size")));
  1280. }
  1281. $("#elem_lesser_range").val("");
  1282. if ($("#"+varname).attr("data-lesser") ) {
  1283. $("#elem_lesser_range").val($("#"+varname).attr("data-lesser"));
  1284. }
  1285. $("#elem_larger_range").val("");
  1286. if ($("#"+varname).attr("data-larger") ) {
  1287. $("#elem_larger_range").val($("#"+varname).attr("data-larger"));
  1288. }
  1289. $("#elem_condition_range").val("");
  1290. if ($("#"+varname).attr("data-cond") ) {
  1291. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  1292. }
  1293. $("#elem_formula").val("");
  1294. if ($("#"+varname).attr("data-formula") ) {
  1295. $("#elem_formula").val($("#"+varname).attr("data-formula"));
  1296. }
  1297. $("#background_color").val("");
  1298. if ($("#"+varname).css("background-color") ) {
  1299. $("#background_color").val($("#"+varname).css("background-color"));
  1300. }
  1301. } else if (vartype == "icon") {
  1302. $("#icon").val(icon);
  1303. $('#icon').prop('disabled', false);
  1304. $('#onexpression').prop('disabled', false);
  1305. $('#onvalue').prop('disabled', false);
  1306. $('#offexpression').prop('disabled', false);
  1307. $('#offvalue').prop('disabled', false);
  1308. $('#onvalue').val($("#"+varname).attr("data-on"));
  1309. $('#onexpression').val($("#"+varname).attr("data-onexpression"))
  1310. $('#offvalue').val($("#"+varname).attr("data-off"));
  1311. $('#offexpression').val($("#"+varname).attr("data-offexpression"))
  1312. //$("#elem_unit_text").val('{"on":'+$("#"+varname).attr("data-on") + ',"off":'+$("#"+varname).attr("data-off")+'}' );
  1313. if (($("#"+varname).attr("data-linkhtml")) == "true" || ($("#"+varname).attr("data-linkhtml")) == "true") {
  1314. $('#elem_linkhtml').prop('checked', true);
  1315. } else {
  1316. $('#elem_linkhtml').prop('checked', false);
  1317. }
  1318. if (varname.includes("virtual")){
  1319. $("#varattr").val("virtual");
  1320. } else {
  1321. $("#varattr").val("normal");
  1322. }
  1323. /*
  1324. } else if (vartype == "commbit") {
  1325. $("#elem_unit_text").val('{"on":'+$("#"+varname).attr("data-on") + ',"off":'+$("#"+varname).attr("data-off")+'}' );
  1326. if (($("#"+varname).attr("data-linkhtml")) == "true" || ($("#"+varname).attr("data-linkhtml")) == "true") {
  1327. $('#elem_linkhtml').prop('checked', true);
  1328. } else {
  1329. $('#elem_linkhtml').prop('checked', false);
  1330. }
  1331. } else if (vartype == "alarm") {
  1332. $("#elem_unit_text").val('{"on":'+$("#"+varname).attr("data-on") + ',"off":'+$("#"+varname).attr("data-off")+'}' );
  1333. if (($("#"+varname).attr("data-linkhtml")) == "true" || ($("#"+varname).attr("data-linkhtml")) == "true") {
  1334. $('#elem_linkhtml').prop('checked', true);
  1335. } else {
  1336. $('#elem_linkhtml').prop('checked', false);
  1337. }*/
  1338. } else if (vartype == "integer-to-string") {
  1339. $("#elem_title_text").val($("#"+varname + " .title").text().trim());
  1340. $("#elem_title_size").val("");
  1341. if ($("#"+varname + " .title").css("font-size")) {
  1342. $("#elem_title_size").val(parseFloat($("#"+varname + " .title").css("font-size")));
  1343. }
  1344. $("#elem_unit_text").val($("#"+varname).attr("data-dict"));
  1345. $("#elem_condition_range").val("");
  1346. if ($("#"+varname).attr("data-cond") ) {
  1347. $("#elem_condition_range").val($("#"+varname).attr("data-cond"));
  1348. }
  1349. $("#background_color").val("");
  1350. if ($("#"+varname).css("background-color") ) {
  1351. $("#background_color").val($("#"+varname).css("background-color"));
  1352. }
  1353. if (($("#"+varname).attr("data-linkhtml")) == "true" || ($("#"+varname).attr("data-linkhtml")) == "true") {
  1354. $('#elem_linkhtml').prop('checked', true);
  1355. } else {
  1356. $('#elem_linkhtml').prop('checked', false);
  1357. }
  1358. }
  1359. for(key in mydata) {
  1360. //console.log(key, varname);
  1361. /*if(($("#" + key).length > 0) && (key == varname) ) {
  1362. //if (!$("#"+varname).hasClass("box_highlight")) {
  1363. $("#"+key).addClass("box_highlight");
  1364. //}
  1365. } else {
  1366. $("#"+key).removeClass("box_highlight");
  1367. }*/
  1368. if(($("#" + key).length > 0) && (varname.match(key))) {
  1369. //$("#"+key).addClass("box_highlight");
  1370. console.log("on", key, varname);
  1371. $("#"+varname).addClass("box_highlight");
  1372. } else {
  1373. //console.log("off");
  1374. $("div").not(document.getElementById(varname)).removeClass("box_highlight");
  1375. }
  1376. }
  1377. }
  1378. jQuery(window).load(function () {
  1379. $("#varname > option").each(function() {
  1380. if ($('#'+this.text).length){
  1381. $('#'+this.text).draggable();
  1382. $('#'+this.text).resizable();
  1383. $('#'+this.text).click(function() {
  1384. //console.log($(this).attr("id"));
  1385. $("#varname").val($(this).attr("id"));
  1386. $("#buttonHighlight").trigger("click");
  1387. });
  1388. }
  1389. //console.log(this.text + ' ' + this.value);
  1390. });
  1391. $("#buttonHighlight").trigger("click");
  1392. $("#varname").change(function() {
  1393. varval = $( "#varname option:selected").val();
  1394. varname = $("#varname option:selected").text();
  1395. //console.log(varval, varname);
  1396. $("#buttonHighlight").trigger("click");
  1397. });
  1398. $("#vartype").change(function() {
  1399. vartype = $("#vartype option:selected").val();
  1400. if ((vartype == "header") || (vartype == "calc")) {
  1401. $("#varname").val("");
  1402. // clear values
  1403. $("#elem_title_text").val("");
  1404. $("#elem_title_size").val("");
  1405. $("#elem_unit_text").val("");
  1406. $("#elem_unit_size").val("");
  1407. $("#elem_lesser_range").val("");
  1408. $("#elem_larger_range").val("");
  1409. $("#elem_condition_range").val("");
  1410. $("#elem_formula").val("");
  1411. $("#background_color").val("");
  1412. }
  1413. });
  1414. });
  1415. </script>
  1416. </body>
  1417. </html>