designer.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Designer</title>
  6. <meta name="description"
  7. content="Designer Drawing Block.">
  8. <link rel="stylesheet" href="{{ static_url("style.css") }}">
  9. <link rel="stylesheet" href="{{ static_url("jquery-ui.min.css") }}">
  10. <!--[if IE]>
  11. <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  12. <![endif]-->
  13. </head>
  14. <body>
  15. <div id="page_info">Designer Block. Generated by BORA 0.0.1</div>
  16. <img src="{{ static_url('background.png') }}"></img>
  17. <button class="button showhide" onclick="showhide()">Show/Hide</button>
  18. {% if data['style'] %}
  19. {% for key in data['style'] %}
  20. {% if data['style'][key]['type'] == "data" %}
  21. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-cond="{{ data['style'][key]['condition'] }}" data-lesser="{{ data['style'][key]['lesser'] }}" data-type="{{ data['style'][key]['type'] }}" data-larger="{{ data['style'][key]['larger'] }}" class='varbox' id="{{ key }}">
  22. <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}; 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'] }}; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> XXX.XX <span class='unit_title'> {{ data['style'][key]['unit']['title'] }}</span></span></p>
  23. </div>
  24. {% else %}
  25. {% end %}
  26. {% if data['style'][key]['type'] == "ventil" %}
  27. <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
  28. <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
  29. </div>
  30. {% else %}
  31. {% end %}
  32. {% end %}
  33. {% else %}
  34. {% end %}
  35. <div id="tool-btn">
  36. <span class="info">Variable</span>
  37. <select id="varname" style="font-size:16pt;">
  38. {% for key in data['cache'] %}
  39. <option value={{data['cache'][key]}}>{{key}}</option>
  40. {% end %}
  41. </select>
  42. <span class="info">Type</span>
  43. <select id="vartype" style="font-size:16pt;">
  44. <option value="data">data</option>
  45. <option value="ventil">ventil</option>
  46. <option value="integer-to-string">integer-to-string</option>
  47. </select>
  48. <br /><br />
  49. <span class="info">Title</span>
  50. <input type="text" id="elem_title_text" placeholder="text" style="font-size:16pt; width=100px;"/>
  51. <input type="text" id="elem_title_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  52. <input type="text" id="elem_lesser_range" placeholder="smaller than (red)" style="font-size:16pt; width=100px;"/>
  53. <input type="text" id="elem_larger_range" placeholder="larger than (red)" style="font-size:16pt; width=100px;"/>
  54. <select id="elem_title_style" style="font-size:16pt;">
  55. <option value="400">normal</option>
  56. <option value="700">bold</option>
  57. </select>
  58. <br /><br />
  59. <span class="info">Value</span>
  60. <input type="text" id="elem_unit_text" placeholder="unit" style="font-size:16pt; width=100px;"/>
  61. <input type="text" id="elem_unit_size" placeholder="size" style="font-size:16pt; width=100px;"/>
  62. <input type="text" id="elem_condition_range" placeholder="condition (red)" style="font-size:16pt; width=100px;"/>
  63. <select id="elem_unit_style" style="font-size:16pt;">
  64. <option value="400">normal</option>
  65. <option value="700">bold</option>
  66. </select>
  67. <br /><br />
  68. <button class="button highlight" onclick="highlight()">Highlight</button>
  69. <button class="button add" onclick="add()">Add</button>
  70. <button class="button remove" onclick="myremove()">Remove</button>
  71. <button class="button save" onclick="mysave({{ data['cache'] }})">Save</button>
  72. </div>
  73. <!-- java script -->
  74. <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
  75. <script src="{{ static_url("jquery-ui.min.js") }}"></script>
  76. <script>
  77. function showhide() {
  78. console.log("Show or Hide");
  79. $("#tool-btn").toggle();
  80. }
  81. function add() {
  82. console.log("add element");
  83. title_text = $("#elem_title_text").val();
  84. title_color = "#000000";
  85. //title_color = $("#elem_title_color").val();
  86. title_size = $("#elem_title_size").val();
  87. title_style = $("#elem_title_style option:selected").val();
  88. unit_text = $("#elem_unit_text").val();
  89. unit_color = "#000";
  90. //unit_color = $("#elem_unit_color").val();
  91. unit_size = $("#elem_unit_size").val();
  92. unit_style = $("#elem_unit_style option:selected").val();
  93. data_condition = $("#elem_condition_range").val();
  94. //data_max = $("#elem_max_range").val();
  95. data_lesser = $("#elem_lesser_range").val();
  96. data_larger = $("#elem_larger_range").val();
  97. varval = $( "#varname option:selected").val();
  98. varname = $("#varname option:selected").text();
  99. vartype = $("#vartype option:selected").val();
  100. console.log(title_text, unit_text, varname, varval, vartype);
  101. if($("#" + varname).length == 0) {
  102. if (vartype == "data") {
  103. html_text = "<div " +
  104. "style='position: absolute; " +
  105. "top:0; " +
  106. "left:0;' " +
  107. "class='varbox' " +
  108. "id='" + varname +
  109. "' data-type='" + vartype +
  110. "' data-cond='" + data_condition +
  111. "' data-lesser='" + data_lesser +
  112. "' data-larger='" + data_larger +
  113. "'>" +
  114. "<p>" +
  115. "<span style='color: " + title_color + ";" +
  116. "font-size:" + title_size + "px; " +
  117. "font-weight: " + title_style + ";' " +
  118. "class='title'>" + title_text +
  119. " </span>" +
  120. "<span style='color: " + unit_color + "; " +
  121. "font-size:" + unit_size + "px; " +
  122. "font-weight: " + unit_style + ";' " +
  123. "class='varval'>" + parseFloat(varval).toFixed(2) + " </span>" +
  124. "<span class='unit_title'>" + unit_text + "</span></p>" +
  125. "</div>";
  126. } else if (vartype == "ventil") {
  127. var token = unit_text.split(";");
  128. var lhs = token[0];
  129. var rhs = token[1];
  130. var data_on, data_off;
  131. if (lhs.split(":")[0] == "on") {
  132. data_on = lhs.split(":")[1];
  133. data_off = rhs.split(":")[1];
  134. } else {
  135. data_off = lhs.split(":")[1];
  136. data_on = rhs.split(":")[1];
  137. }
  138. html_text = "<div " +
  139. "style='position: absolute; " +
  140. "top:0; " +
  141. "left:0;' " +
  142. "class='varbox' " +
  143. "id='" + varname +
  144. "' data-type='" + vartype +
  145. "' data-cond='" + data_condition +
  146. "' data-lesser='" + data_lesser +
  147. "' data-larger='" + data_larger +
  148. "' data-on='" + data_on +
  149. "' data-off='" + data_off +
  150. "'>" +
  151. "<img width='100%' height='100%' " +
  152. "src='{{ static_url("ventil_inactive.png") }}'></img>" +
  153. "</div>";
  154. }
  155. $( "body" ).append(html_text);
  156. $("#"+varname).draggable();
  157. $("#"+varname).resizable();
  158. }
  159. }
  160. function myremove() {
  161. varname = $("#varname option:selected").text();
  162. if($("#" + varname).length > 0) {
  163. $("#"+varname).remove();
  164. console.log(varname +" removed.");
  165. }
  166. }
  167. function mysave(data) {
  168. console.log("saving...");
  169. console.log(data);
  170. var position = {};
  171. for(key in data) {
  172. var tmp = {};
  173. console.log(key);
  174. if($("#" + key).length > 0) {
  175. tmp["left"] = $("#"+key).css("left");
  176. tmp["top"] = $("#"+key).css("top");
  177. tmp["width"] = $("#"+key).width();
  178. tmp["height"] = $("#"+key).height();
  179. //tmp["type"] = $("#vartype option:selected").val();
  180. //tmp["min"] = $("#elem_min_range").val();
  181. //tmp["max"] = $("#elem_max_range").val();
  182. tmp["min"] = $("#"+key).attr("min");
  183. tmp["max"] = $("#"+key).attr("max");
  184. tmp["type"] = $("#"+key).attr("data-type");
  185. if ( $("#"+key).attr("data-type") == "data" ) {
  186. tmp["condition"] = $("#"+key).attr("data-cond");
  187. tmp["lesser"] = $("#"+key).attr("data-lesser");
  188. tmp["larger"] = $("#"+key).attr("data-larger");
  189. header = {};
  190. header["title"] = $(".title", "#"+key).text();
  191. //header["color"] = $(".title", "#"+key).css("color");
  192. header["size"] = $(".title", "#"+key).css("font-size");
  193. header["weight"] = $(".title", "#"+key).css("font-weight");
  194. unit = {};
  195. unit["title"] = $(".unit_title", "#"+key).text();
  196. //unit["color"] = $(".varval", "#"+key).css("color");
  197. unit["size"] = $(".varval", "#"+key).css("font-size");
  198. unit["weight"] = $(".varval", "#"+key).css("font-weight");
  199. tmp["header"] = header;
  200. tmp["unit"] = unit;
  201. } else if ( $("#"+key).attr("data-type") == "ventil" ) {
  202. //console.log("Ventil !!");
  203. //console.log($(".unit_title", "#"+key).text());
  204. tmp["on"] = $("#"+key).attr("data-on");
  205. tmp["off"] = $("#"+key).attr("data-off");
  206. }
  207. position[key] = tmp;
  208. }
  209. }
  210. console.log(position);
  211. var dataToSend = JSON.stringify(position);
  212. $.ajax({
  213. url: '/save/',
  214. type: 'POST',
  215. data: dataToSend,
  216. success: function (response) {
  217. var objresponse = JSON.parse(response);
  218. console.log(objresponse);
  219. },
  220. error: function () {
  221. console.log("Error.")
  222. }
  223. });
  224. }
  225. function highlight() {
  226. varname = $("#varname option:selected").text();
  227. console.log(varname);
  228. if ($("#"+varname).hasClass("box_highlight")) {
  229. $("#"+varname).removeClass("box_highlight");
  230. } else {
  231. $("#"+varname).addClass("box_highlight");
  232. }
  233. }
  234. jQuery(window).load(function () {
  235. $("#varname > option").each(function() {
  236. if ($('#'+this.text).length){
  237. $('#'+this.text).draggable();
  238. $('#'+this.text).resizable();
  239. }
  240. //console.log(this.text + ' ' + this.value);
  241. });
  242. });
  243. </script>
  244. </body>
  245. </html>