svghmi/widget_input.ysl2
author Edouard Tisserant
Thu, 04 Jun 2020 11:14:21 +0200
branchsvghmi
changeset 2980 2a21d6060d64
parent 2929 9179cbc6fc49
child 3001 003fd80ff0b8
permissions -rw-r--r--
SVGHMI: add "unsubscribable" property to widgets in order to generalize what already happens for jump buttons.
In most cases jump buttons do not really subscribe to pointed HMI variable, path is given as a relative page jump path. When widget.unsubscribable is set to true, no subscription is made on page switch, but still offset is updated.
This fixes bug happening on relative jump buttons without "disabled" element where offset did not change on relative page switch.
// widget_input.ysl2

template "widget[@type='Input']", mode="widget_defs" {
    param "hmi_element";
    const "value_elt" {
        optional_labels("value");
    }
    const "have_value","string-length($value_elt)>0";
    value "$value_elt";
    if "$have_value"
    |     frequency: 5,
    |     last_val: undefined,
    |     dispatch: function(value) {
    |         this.last_val = value;
    if "$have_value"
    |         this.value_elt.textContent = String(value);

    |     },
    const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id";
    |     init: function() {
    if "$edit_elt_id" {
    |         id("«$edit_elt_id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_edit_click()");
    }
    foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
    |         id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_op_click('«func:escape_quotes(@inkscape:label)»')");
    }
    |     },
    |     on_op_click: function(opstr) {
    |         let orig = this.indexes[0];
    |         let idx = this.offset ? orig - this.offset : orig;
    |         let new_val = change_hmi_value(idx, opstr);
    //     if "$have_value"{
    // |         this.value_elt.textContent = String(new_val);
    //           /* TODO gray out value until refreshed */
    //     }
    |     },
    |     on_edit_click: function(opstr) {
    |         edit_value("«path/@value»", "«path/@type»", this, this.last_val);
    |     },

    |     edit_callback: function(new_val) {
    |         let orig = this.indexes[0];
    |         let idx = this.offset ? orig - this.offset : orig;
    |         apply_hmi_value(idx, new_val);
    //     if "$have_value"{
    // |         this.value_elt.textContent = String(new_val);
    //           /* TODO gray out value until refreshed */
    //     }
    |     },
}