designer.html 66 KB

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