svghmi/widget_jump.ysl2
author Edouard Tisserant
Thu, 26 Mar 2020 13:33:20 +0100
branchsvghmi
changeset 2901 3f5194bba67d
parent 2900 3ef217f525ff
child 2902 1fcb50af0335
permissions -rw-r--r--
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
     1
// widget_jump.ysl2
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2763
diff changeset
     2
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
     3
template "widget[@type='Jump']", mode="widget_defs" {
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
     4
    param "hmi_element";
2900
3ef217f525ff SVGHMI: Check that explicit relative page jump path is consistant with destination page reference path.
Edouard Tisserant
parents: 2898
diff changeset
     5
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
     6
    |     on_click: function(evt) {
2898
a2910281fcb5 SVGHMI: Alow relative relative Jump. (i.e, relative jump from a foreach widget)
Edouard Tisserant
parents: 2883
diff changeset
     7
    |         const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
a2910281fcb5 SVGHMI: Alow relative relative Jump. (i.e, relative jump from a foreach widget)
Edouard Tisserant
parents: 2883
diff changeset
     8
    |         switch_page(this.args[0], index);
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
     9
    |     },
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    10
    |     init: function() {
2901
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    11
    /* registering event this way does not "click" through svg:use 
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    12
    |     this.element.onclick = evt => switch_page(this.args[0]);
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    13
    event must be registered by adding attribute to element instead
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    14
    TODO : generalize mouse event handling by global event capture + getElementsAtPoint()
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    15
    */
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    16
    |         this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    17
    |     },
2753
9a7e12e96399 SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
diff changeset
    18
}
2901
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    19
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    20
template "widget[@type='Jump']", mode="per_page_widget_template"{
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    21
    param "page_desc";
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    22
    /* check that given path is compatible with page's reference path */
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    23
    if "path" {
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    24
        /* when no page name provided, check for same page */
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    25
        const "target_page_name" choose {
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    26
            when "arg" value "arg[1]/@value";
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    27
            otherwise value "$page_desc/arg[1]/@value";
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    28
        }
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    29
        const "target_page_path" choose {
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    30
            when "arg" value "$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[1]/@value";
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    31
            otherwise value "$page_desc/path[1]/@value";
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    32
        }
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    33
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    34
        if "not(func:same_class_paths($target_page_path, path[1]/@value))"
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    35
            error > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value» (must be same class as "«$target_page_path»")
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    36
    }
3f5194bba67d SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents: 2900
diff changeset
    37
}