svghmi/widget_jump.ysl2
branchsvghmi
changeset 2906 3b4a1319da09
parent 2903 881d0248b3ce
child 2912 d320367eb2ad
equal deleted inserted replaced
2905:3d7e3866cc51 2906:3b4a1319da09
     3 function "jump_widget_activity" {
     3 function "jump_widget_activity" {
     4     param "hmi_element";
     4     param "hmi_element";
     5         optional_labels("active inactive");
     5         optional_labels("active inactive");
     6 }
     6 }
     7 
     7 
       
     8 function "jump_widget_disability" {
       
     9     param "hmi_element";
       
    10         optional_labels("disabled");
       
    11 }
       
    12 
     8 template "widget[@type='Jump']", mode="widget_defs" {
    13 template "widget[@type='Jump']", mode="widget_defs" {
     9     param "hmi_element";
    14     param "hmi_element";
    10     const "opts" call "jump_widget_activity" with "hmi_element", "$hmi_element";
    15     const "activity" call "jump_widget_activity" with "hmi_element", "$hmi_element";
    11     const "have_opt","string-length($opts)>0";
    16     const "have_activity","string-length($activity)>0";
    12     value "$opts";
    17     value "$activity";
       
    18     const "disability" call "jump_widget_disability" with "hmi_element", "$hmi_element";
       
    19     const "have_disability","$have_activity and string-length($disability)>0";
       
    20     value "$disability";
       
    21     if "$have_activity" {
       
    22     |     active: false,
       
    23     if "$have_disability" {
       
    24     |     disabled: false,
       
    25     |     frequency: 2,
       
    26     |     dispatch: function(value) {
       
    27     |         this.disabled = !Number(value);
       
    28     |         console.log("disbled",value);
       
    29     |         this.update();
       
    30     |     },
       
    31     }
       
    32     |     update: function(){
       
    33     if "$have_disability" {
       
    34     |       if(this.disabled) {
       
    35     |         /* show disabled */ 
       
    36     |         this.disabled_elt.setAttribute("style", this.active_elt_style);
       
    37     |         /* hide inactive */ 
       
    38     |         this.inactive_elt.setAttribute("style", "display:none");
       
    39     |         /* hide active */ 
       
    40     |         this.active_elt.setAttribute("style", "display:none");
       
    41     |       } else {
       
    42     |         /* hide disabled */ 
       
    43     |         this.disabled_elt.setAttribute("style", "display:none");
       
    44     }
       
    45     |         if(this.active) {
       
    46     |              /* show active */ 
       
    47     |              this.active_elt.setAttribute("style", this.active_elt_style);
       
    48     |              /* hide inactive */ 
       
    49     |              this.inactive_elt.setAttribute("style", "display:none");
       
    50     |         } else {
       
    51     |              /* show inactive */ 
       
    52     |              this.inactive_elt.setAttribute("style", this.inactive_elt_style);
       
    53     |              /* hide active */ 
       
    54     |              this.active_elt.setAttribute("style", "display:none");
       
    55     |         }
       
    56     if "$have_disability" {
       
    57     |       }
       
    58     }
       
    59     |     },
       
    60     }
    13     |     on_click: function(evt) {
    61     |     on_click: function(evt) {
    14     |         const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
    62     |         const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
    15     |         const name = this.args[0];
    63     |         const name = this.args[0];
    16     |         switch_page(name, index);
    64     |         switch_page(name, index);
    17     |     },
    65     |     },
    18     if "$have_opt" {
    66     if "$have_activity" {
    19     |     notify_page_change: function(page_name, index){
    67     |     notify_page_change: function(page_name, index){
    20     |         const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
    68     |         const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
    21     |         const ref_name = this.args[0];
    69     |         const ref_name = this.args[0];
    22     |         if((ref_name == undefined || ref_name == page_name) && index == ref_index) {
    70     |         this.active =((ref_name == undefined || ref_name == page_name) && index == ref_index);
    23     |              console.log("active", ref_name, ref_index, page_name, index);
    71     |         this.update();
    24     |              /* show active */ 
       
    25     |              this.active_elt.setAttribute("style", this.active_elt_style);
       
    26     |              /* hide inactive */ 
       
    27     |              this.inactive_elt.setAttribute("style", "display:none");
       
    28     |         } else {
       
    29     |              console.log("inactive",ref_name, ref_index,  page_name, index);
       
    30     |              /* show inactive */ 
       
    31     |              this.inactive_elt.setAttribute("style", this.inactive_elt_style);
       
    32     |              /* hide active */ 
       
    33     |              this.active_elt.setAttribute("style", "display:none");
       
    34     |         }
       
    35     |     },
    72     |     },
    36     }
    73     }
    37     |     init: function() {
    74     |     init: function() {
    38     /* registering event this way does not "click" through svg:use 
    75     /* registering event this way does not "click" through svg:use 
    39     |     this.element.onclick = evt => switch_page(this.args[0]);
    76     |     this.element.onclick = evt => switch_page(this.args[0]);
    40     event must be registered by adding attribute to element instead
    77     event must be registered by adding attribute to element instead
    41     TODO : generalize mouse event handling by global event capture + getElementsAtPoint()
    78     TODO : generalize mouse event handling by global event capture + getElementsAtPoint()
    42     */
    79     */
    43     |         this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
    80     |         this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
    44     if "$have_opt" {
    81     if "$have_activity" {
    45     |         this.active_elt_style = this.active_elt.getAttribute("style");
    82     |         this.active_elt_style = this.active_elt.getAttribute("style");
    46     |         this.inactive_elt_style = this.inactive_elt.getAttribute("style");
    83     |         this.inactive_elt_style = this.inactive_elt.getAttribute("style");
    47     }
    84     }
       
    85     if "$have_disability" {
       
    86     |         this.disabled_elt_style = this.disabled_elt.getAttribute("style");
       
    87     }
    48     |     },
    88     |     },
       
    89 }
       
    90 
       
    91 // default : normal subscribing
       
    92 template "widget[@type='Jump']", mode="widget_subscribe" {
       
    93     param "hmi_element";
       
    94     const "activity" call "jump_widget_activity" with "hmi_element", "$hmi_element";
       
    95     const "have_activity","string-length($activity)>0";
       
    96     const "disability" call "jump_widget_disability" with "hmi_element", "$hmi_element";
       
    97     const "have_disability","$have_activity and string-length($disability)>0";
       
    98     choose {
       
    99         when "$have_disability" {
       
   100     |     sub: subscribe,
       
   101     |     unsub: unsubscribe,
       
   102     |     apply_cache: widget_apply_cache,
       
   103         }
       
   104         otherwise {
       
   105     |     sub: function(){},
       
   106     |     unsub: function(){},
       
   107     |     apply_cache: function(){},
       
   108         }
       
   109     }
    49 }
   110 }
    50 
   111 
    51 template "widget[@type='Jump']", mode="per_page_widget_template"{
   112 template "widget[@type='Jump']", mode="per_page_widget_template"{
    52     param "page_desc";
   113     param "page_desc";
    53     /* check that given path is compatible with page's reference path */
   114     /* check that given path is compatible with page's reference path */