# HG changeset patch
# User Edouard Tisserant
# Date 1585833495 -7200
# Node ID ac4328e69079e7bc4e3384b5a7116c8453ece395
# Parent d320367eb2ad2a59bdb5e7b303d7bd2c655d380a
SVGHMI: Keypad: added code to re-attach keypad when starting edit.
diff -r d320367eb2ad -r ac4328e69079 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Thu Apr 02 14:04:21 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Thu Apr 02 15:18:15 2020 +0200
@@ -127,6 +127,9 @@
+
+
+
@@ -259,6 +262,8 @@
+
+
@@ -311,7 +316,7 @@
-
+
@@ -331,7 +336,7 @@
-
+
@@ -726,8 +731,6 @@
on_click: function(evt) {
- console.log("Back !");
-
if(jump_history.length > 1){
jump_history.pop();
@@ -897,8 +900,12 @@
frequency: 5,
+ last_val: undefined,
+
dispatch: function(value) {
+ this.last_val = value;
+
this.value_elt.textContent = String(value);
@@ -911,33 +918,53 @@
id("
- ").addEventListener(
-
- "click",
-
- evt => alert('XXX TODO : Edit value'));
+ ").setAttribute("onclick", "hmi_widgets['
+
+ '].on_edit_click()");
id("
- ").addEventListener(
-
- "click",
-
- evt => {let new_val = change_hmi_value(this.indexes[0], "
+ ").setAttribute("onclick", "hmi_widgets['
+
+ '].on_op_click('
- ");
-
-
- this.value_elt.textContent = String(new_val);
-
-
- });
+ ')");
},
+ on_op_click: function(opstr) {
+
+ let new_val = change_hmi_value(this.indexes[0], opstr);
+
+
+ this.value_elt.textContent = String(new_val);
+
+
+ },
+
+ on_edit_click: function(opstr) {
+
+ edit_value("
+
+ ", "
+
+ ", this.edit_callback, this.last_val);
+
+ },
+
+ edit_callback: function(new_val) {
+
+ apply_hmi_value(this.indexes[0], opstr);
+
+
+ this.value_elt.textContent = String(new_val);
+
+
+ },
+
@@ -987,8 +1014,6 @@
this.disabled = !Number(value);
- console.log("disbled",value);
-
this.update();
},
@@ -1161,6 +1186,12 @@
+
+ init: function() {
+
+ },
+
+
frequency: 10,
@@ -1288,6 +1319,7 @@
Made with SVGHMI. https://beremiz.org
+
@@ -1367,6 +1399,26 @@
}
+ var keypads = {
+
+
+
+
+
+ "
+
+ ":["
+
+ ",
+
+ ,
+
+ ],
+
+
+
+ }
+
var default_page = "
@@ -1859,6 +1911,20 @@
+ function apply_hmi_value(index, new_val) {
+
+ let old_val = cache[index]
+
+ if(new_val != undefined && old_val != new_val)
+
+ send_hmi_value(index, new_val);
+
+ return new_val;
+
+ }
+
+
+
function change_hmi_value(index, opstr) {
let op = opstr[0];
@@ -2189,8 +2255,6 @@
requestHMIAnimation();
- console.log(opstr, new_item_offset);
-
}
@@ -2301,5 +2365,47 @@
};
+
+
+ var edit_callback;
+
+ function edit_value(path, valuetype, callback, initial) {
+
+
+
+ let [keypadid, xcoord, ycoord] = keypads[valuetype];
+
+ console.log('XXX TODO : Edit value', path, valuetype, callback, initial, keypadid);
+
+ edit_callback = callback;
+
+
+
+ let [element, parent] = detachable_elements[keypadid];
+
+ tmpgrp = document.createElement("g");
+
+ tmpgrpattr = document.createAttribute("transform");
+
+
+
+ let [xdest,ydest] = page_desc[current_visible_page].bbox;
+
+ tmpgrpattr.value = "translate("+String(xdest-xcoord)+","+String(ydest-ycoord)+")";
+
+ tmpgrp.setAttributeNode(tmpgrpattr);
+
+
+
+ tmpgrp.appendChild(element);
+
+ parent.appendChild(tmpgrp);
+
+
+
+ };
+
+
+
diff -r d320367eb2ad -r ac4328e69079 svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.ysl2 Thu Apr 02 14:04:21 2020 +0200
+++ b/svghmi/gen_index_xhtml.ysl2 Thu Apr 02 15:18:15 2020 +0200
@@ -113,7 +113,8 @@
foreach "$keypads_descs"{
const "keypad_id","@id";
foreach "arg"{
- | "«@value»":"«$keypad_id»",
+ const "g", "$geometry[@Id = $keypad_id]";
+ | "«@value»":["«$keypad_id»", «$g/@x», «$g/@y»],
}
}
| }
diff -r d320367eb2ad -r ac4328e69079 svghmi/svghmi.js
--- a/svghmi/svghmi.js Thu Apr 02 14:04:21 2020 +0200
+++ b/svghmi/svghmi.js Thu Apr 02 15:18:15 2020 +0200
@@ -470,9 +470,20 @@
var edit_callback;
function edit_value(path, valuetype, callback, initial) {
- keypad = keypads[valuetype];
- console.log('XXX TODO : Edit value', path, valuetype, callback, initial, keypad);
+ let [keypadid, xcoord, ycoord] = keypads[valuetype];
+ console.log('XXX TODO : Edit value', path, valuetype, callback, initial, keypadid);
edit_callback = callback;
-};
-
+ let [element, parent] = detachable_elements[keypadid];
+ tmpgrp = document.createElement("g");
+ tmpgrpattr = document.createAttribute("transform");
+
+ let [xdest,ydest] = page_desc[current_visible_page].bbox;
+ tmpgrpattr.value = "translate("+String(xdest-xcoord)+","+String(ydest-ycoord)+")";
+ tmpgrp.setAttributeNode(tmpgrpattr);
+
+ tmpgrp.appendChild(element);
+ parent.appendChild(tmpgrp);
+
+};
+