123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Designer</title>
- <meta name="description"
- content="Designer Drawing Block.">
- <link rel="stylesheet" href="{{ static_url("style.css") }}">
- <link rel="stylesheet" href="{{ static_url("jquery-ui.min.css") }}">
- <!--[if IE]>
- <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- </head>
- <body>
- <div id="page_info">Designer Block. Generated by BORA 0.0.1</div>
- <img src="{{ static_url('background.png') }}"></img>
- <button class="button showhide" onclick="showhide()">Show/Hide</button>
- {% if data['style'] %}
- {% for key in data['style'] %}
- {% if data['style'][key]['type'] == "data" %}
- <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 }}">
- <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>
- </div>
- {% else %}
- {% end %}
- {% if data['style'][key]['type'] == "ventil" %}
- <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 }}">
- <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
- </div>
- {% else %}
- {% end %}
- {% end %}
- {% else %}
- {% end %}
-
-
- <div id="tool-btn">
- <span class="info">Variable</span>
- <select id="varname" style="font-size:16pt;">
- {% for key in data['cache'] %}
- <option value={{data['cache'][key]}}>{{key}}</option>
- {% end %}
- </select>
- <span class="info">Type</span>
- <select id="vartype" style="font-size:16pt;">
- <option value="data">data</option>
- <option value="ventil">ventil</option>
- <option value="integer-to-string">integer-to-string</option>
- </select>
- <br /><br />
- <span class="info">Title</span>
- <input type="text" id="elem_title_text" placeholder="text" style="font-size:16pt; width=100px;"/>
- <input type="text" id="elem_title_size" placeholder="size" style="font-size:16pt; width=100px;"/>
- <input type="text" id="elem_lesser_range" placeholder="smaller than (red)" style="font-size:16pt; width=100px;"/>
- <input type="text" id="elem_larger_range" placeholder="larger than (red)" style="font-size:16pt; width=100px;"/>
- <select id="elem_title_style" style="font-size:16pt;">
- <option value="400">normal</option>
- <option value="700">bold</option>
- </select>
- <br /><br />
- <span class="info">Value</span>
- <input type="text" id="elem_unit_text" placeholder="unit" style="font-size:16pt; width=100px;"/>
- <input type="text" id="elem_unit_size" placeholder="size" style="font-size:16pt; width=100px;"/>
- <input type="text" id="elem_condition_range" placeholder="condition (red)" style="font-size:16pt; width=100px;"/>
- <select id="elem_unit_style" style="font-size:16pt;">
- <option value="400">normal</option>
- <option value="700">bold</option>
- </select>
- <br /><br />
- <button class="button highlight" onclick="highlight()">Highlight</button>
- <button class="button add" onclick="add()">Add</button>
- <button class="button remove" onclick="myremove()">Remove</button>
- <button class="button save" onclick="mysave({{ data['cache'] }})">Save</button>
- </div>
-
- <!-- java script -->
- <script src="{{ static_url("jquery-1.12.3.min.js") }}"></script>
- <script src="{{ static_url("jquery-ui.min.js") }}"></script>
- <script>
-
-
-
- function showhide() {
- console.log("Show or Hide");
- $("#tool-btn").toggle();
- }
-
- function add() {
- console.log("add element");
- title_text = $("#elem_title_text").val();
- title_color = "#000000";
- //title_color = $("#elem_title_color").val();
- title_size = $("#elem_title_size").val();
- title_style = $("#elem_title_style option:selected").val();
-
- unit_text = $("#elem_unit_text").val();
- unit_color = "#000";
- //unit_color = $("#elem_unit_color").val();
- unit_size = $("#elem_unit_size").val();
- unit_style = $("#elem_unit_style option:selected").val();
-
- data_condition = $("#elem_condition_range").val();
- //data_max = $("#elem_max_range").val();
-
- data_lesser = $("#elem_lesser_range").val();
- data_larger = $("#elem_larger_range").val();
-
- varval = $( "#varname option:selected").val();
- varname = $("#varname option:selected").text();
- vartype = $("#vartype option:selected").val();
- console.log(title_text, unit_text, varname, varval, vartype);
-
-
- if($("#" + varname).length == 0) {
- if (vartype == "data") {
- html_text = "<div " +
- "style='position: absolute; " +
- "top:0; " +
- "left:0;' " +
- "class='varbox' " +
- "id='" + varname +
- "' data-type='" + vartype +
- "' data-cond='" + data_condition +
- "' data-lesser='" + data_lesser +
- "' data-larger='" + data_larger +
- "'>" +
- "<p>" +
- "<span style='color: " + title_color + ";" +
- "font-size:" + title_size + "px; " +
- "font-weight: " + title_style + ";' " +
- "class='title'>" + title_text +
- " </span>" +
- "<span style='color: " + unit_color + "; " +
- "font-size:" + unit_size + "px; " +
- "font-weight: " + unit_style + ";' " +
- "class='varval'>" + parseFloat(varval).toFixed(2) + " </span>" +
- "<span class='unit_title'>" + unit_text + "</span></p>" +
- "</div>";
- } else if (vartype == "ventil") {
- var token = unit_text.split(";");
- var lhs = token[0];
- var rhs = token[1];
- var data_on, data_off;
- if (lhs.split(":")[0] == "on") {
- data_on = lhs.split(":")[1];
- data_off = rhs.split(":")[1];
- } else {
- data_off = lhs.split(":")[1];
- data_on = rhs.split(":")[1];
- }
- html_text = "<div " +
- "style='position: absolute; " +
- "top:0; " +
- "left:0;' " +
- "class='varbox' " +
- "id='" + varname +
- "' data-type='" + vartype +
- "' data-cond='" + data_condition +
- "' data-lesser='" + data_lesser +
- "' data-larger='" + data_larger +
- "' data-on='" + data_on +
- "' data-off='" + data_off +
- "'>" +
- "<img width='100%' height='100%' " +
- "src='{{ static_url("ventil_inactive.png") }}'></img>" +
- "</div>";
- }
- $( "body" ).append(html_text);
- $("#"+varname).draggable();
- $("#"+varname).resizable();
- }
- }
-
- function myremove() {
- varname = $("#varname option:selected").text();
- if($("#" + varname).length > 0) {
- $("#"+varname).remove();
- console.log(varname +" removed.");
- }
- }
-
- function mysave(data) {
- console.log("saving...");
- console.log(data);
- var position = {};
- for(key in data) {
- var tmp = {};
- console.log(key);
- if($("#" + key).length > 0) {
- tmp["left"] = $("#"+key).css("left");
- tmp["top"] = $("#"+key).css("top");
- tmp["width"] = $("#"+key).width();
- tmp["height"] = $("#"+key).height();
- //tmp["type"] = $("#vartype option:selected").val();
- //tmp["min"] = $("#elem_min_range").val();
- //tmp["max"] = $("#elem_max_range").val();
- tmp["min"] = $("#"+key).attr("min");
- tmp["max"] = $("#"+key).attr("max");
- tmp["type"] = $("#"+key).attr("data-type");
- if ( $("#"+key).attr("data-type") == "data" ) {
- tmp["condition"] = $("#"+key).attr("data-cond");
- tmp["lesser"] = $("#"+key).attr("data-lesser");
- tmp["larger"] = $("#"+key).attr("data-larger");
-
- header = {};
- header["title"] = $(".title", "#"+key).text();
- //header["color"] = $(".title", "#"+key).css("color");
- header["size"] = $(".title", "#"+key).css("font-size");
- header["weight"] = $(".title", "#"+key).css("font-weight");
-
- unit = {};
- unit["title"] = $(".unit_title", "#"+key).text();
- //unit["color"] = $(".varval", "#"+key).css("color");
- unit["size"] = $(".varval", "#"+key).css("font-size");
- unit["weight"] = $(".varval", "#"+key).css("font-weight");
- tmp["header"] = header;
- tmp["unit"] = unit;
- } else if ( $("#"+key).attr("data-type") == "ventil" ) {
- //console.log("Ventil !!");
- //console.log($(".unit_title", "#"+key).text());
- tmp["on"] = $("#"+key).attr("data-on");
- tmp["off"] = $("#"+key).attr("data-off");
- }
- position[key] = tmp;
- }
- }
- console.log(position);
- var dataToSend = JSON.stringify(position);
- $.ajax({
- url: '/save/',
- type: 'POST',
- data: dataToSend,
- success: function (response) {
- var objresponse = JSON.parse(response);
- console.log(objresponse);
- },
- error: function () {
- console.log("Error.")
- }
- });
- }
-
-
- function highlight() {
- varname = $("#varname option:selected").text();
- console.log(varname);
- if ($("#"+varname).hasClass("box_highlight")) {
- $("#"+varname).removeClass("box_highlight");
- } else {
- $("#"+varname).addClass("box_highlight");
- }
- }
- jQuery(window).load(function () {
- $("#varname > option").each(function() {
- if ($('#'+this.text).length){
- $('#'+this.text).draggable();
- $('#'+this.text).resizable();
- }
- //console.log(this.text + ' ' + this.value);
- });
- });
- </script>
- </body>
- </html>
|