svghmi/widget_jump.ysl2
changeset 3595 375626e60b63
parent 3577 6c7a7b22bec9
child 3596 9c725829d8f0
equal deleted inserted replaced
3594:30f7eade322f 3595:375626e60b63
     1 // widget_jump.ysl2
     1 // widget_jump.ysl2
     2 
     2 
     3 widget_desc("Jump") {
     3 widget_desc("Jump") {
     4     longdesc
     4     longdesc
     5     ||
     5     ||
     6     Jump widget brings focus to a different page. Mandatory single argument
     6     Jump widget brings focus to a different page. Mandatory first argument
     7     gives name of the page.
     7     gives name of the page.
     8 
     8 
     9     Optional single path is used as new reference when jumping to a relative
     9     If first path is pointint to HMI_NODE variable is used as new reference 
    10     page, it must point to a HMI_NODE.
    10     when jumping to a relative page.
    11 
    11 
       
    12     Additional arguments are unordered options:
       
    13 
       
    14     - Absolute: force page jump to be not relative even if first path is of type HMI_NODE
       
    15 
       
    16     - name=value: Notify jump by setting variable with path having same name assigned
       
    17         
    12     "active"+"inactive" labeled elements can be provided and reflect current
    18     "active"+"inactive" labeled elements can be provided and reflect current
    13     page being shown.
    19     page being shown.
    14 
    20 
    15     "disabled" labeled element, if provided, is shown instead of "active" or
    21     Exemples:
    16     "inactive" widget when pointed HMI_NODE is null.
    22     
       
    23     Relative jump:
       
    24 
       
    25     HMI:Jump:RelativePage@/PUMP9
       
    26     HMI:Jump:RelativePage@/PUMP9@role=.userrole#role=="admin"
       
    27 
       
    28     Absolute jump:
       
    29 
       
    30     HMI:Jump:AbsolutePage
       
    31     HMI:Jump:AbsolutePage@role=.userrole#role=="admin"
       
    32 
       
    33     Forced absolute jump:
       
    34 
       
    35     HMI:Jump:AbsolutePage:Absolute@/PUMP9
       
    36     HMI:Jump:AbsolutePage:Absolute:notify=1@notify=/PUMP9
       
    37 
    17     ||
    38     ||
    18 
    39 
    19     shortdesc > Jump to given page
    40     shortdesc > Jump to given page
    20 
    41 
    21     arg name="page" accepts="string" > name of page to jump to
    42     arg name="page" accepts="string" > name of page to jump to
    25 
    46 
    26 widget_class("Jump") {
    47 widget_class("Jump") {
    27 ||
    48 ||
    28         activable = false;
    49         activable = false;
    29         active = false;
    50         active = false;
    30         disabled = false;
       
    31         frequency = 2;
    51         frequency = 2;
    32 
    52 
    33         update_activity() {
    53         update_activity() {
    34             if(this.active) {
    54             this.set_activation_state(this.active);
    35                  /* show active */ 
       
    36                  this.active_elt.style.display = "";
       
    37                  /* hide inactive */ 
       
    38                  this.inactive_elt.style.display = "none";
       
    39             } else {
       
    40                  /* show inactive */ 
       
    41                  this.inactive_elt.style.display = "";
       
    42                  /* hide active */ 
       
    43                  this.active_elt.style.display = "none";
       
    44             }
       
    45         }
    55         }
    46 
    56 
    47         update_disability() {
    57         update_disability() {
    48             if(this.disabled) {
    58             this.animate_enable();
    49                 /* show disabled */ 
    59             if(this.enable_state) {
    50                 this.disabled_elt.style.display = "";
       
    51                 /* hide inactive */ 
       
    52                 this.inactive_elt.style.display = "none";
       
    53                 /* hide active */ 
       
    54                 this.active_elt.style.display = "none";
       
    55             } else {
       
    56                 /* hide disabled */ 
       
    57                 this.disabled_elt.style.display = "none";
       
    58                 this.update_activity();
    60                 this.update_activity();
    59             }
    61             }
    60         }
    62         }
    61 
    63 
    62         make_on_click() {
    64         make_on_click() {
    64             const name = this.args[0];
    66             const name = this.args[0];
    65             return function(evt){
    67             return function(evt){
    66                 /* TODO: in order to allow jumps to page selected through for exemple a dropdown,
    68                 /* TODO: in order to allow jumps to page selected through for exemple a dropdown,
    67                    support path pointing to local variable whom value 
    69                    support path pointing to local variable whom value 
    68                    would be an HMI_TREE index and then jump to a relative page not hard-coded in advance */
    70                    would be an HMI_TREE index and then jump to a relative page not hard-coded in advance */
    69                 if(!that.disabled) {
    71                 if(that.enable_state) {
    70                     const index = that.indexes.length > 0 ? that.indexes[0] + that.offset : undefined;
    72                     const index = (that.is_relative && that.indexes.length > 0) ? that.indexes[0] + that.offset : undefined;
    71                     fading_page_switch(name, index);
    73                     fading_page_switch(name, index);
    72                 }
    74                 }
    73             }
    75             }
    74         }
    76         }
    75 
    77 
    80                 this.active = ((ref_name == undefined || ref_name == page_name) && index == ref_index);
    82                 this.active = ((ref_name == undefined || ref_name == page_name) && index == ref_index);
    81                 this.update_state();
    83                 this.update_state();
    82             }
    84             }
    83         }
    85         }
    84 
    86 
    85         dispatch(value) {
    87         animate() {
    86             this.disabled = !Number(value);
       
    87 
       
    88             // TODO : use RequestAnimate and animate()
       
    89 
       
    90             this.update_state();
    88             this.update_state();
    91         }
    89         }
    92 ||
    90 ||
    93 }
    91 }
    94 
    92 
       
    93 def "func:is_relative_jump" {
       
    94     param "widget";
       
    95     result "$widget/path and $widget/path[1]/@type='HMI_NODE' and not($widget/arg[position()>1 and @value = 'Absolute'])";
       
    96 }
       
    97 
    95 widget_defs("Jump") {
    98 widget_defs("Jump") {
    96     // TODO: ensure both active and inactive are provided
    99     optional_activable();
    97     const "activity" optional_labels("active inactive");
       
    98     const "have_activity","string-length($activity)>0";
       
    99     value "$activity";
       
   100 
   100 
   101     const "disability" optional_labels("disabled");
   101     const "jump_disability","$has_activity and $has_disability";
   102     const "have_disability","$have_activity and string-length($disability)>0";
       
   103     value "$disability";
       
   104 
   102 
   105     |     init: function() {
   103     |     init: function() {
   106     |         this.element.onclick = this.make_on_click();
   104     |         this.element.onclick = this.make_on_click();
   107     if "$have_activity" {
   105     if "$has_activity" {
   108     |         this.activable = true;
   106     |         this.activable = true;
   109     }
       
   110     if "not($have_disability)" {
       
   111     |         this.unsubscribable = true;
       
   112     }
   107     }
   113     >         this.update_state = 
   108     >         this.update_state = 
   114     choose {
   109     choose {
   115         when "$have_disability" {
   110         when "$jump_disability" {
   116             > this.update_disability
   111             > this.update_disability
   117         }
   112         }
   118         when "$have_activity" {
   113         when "$has_activity" {
   119             > this.update_activity
   114             > this.update_activity
   120         }
   115         }
   121         otherwise > null
   116         otherwise > function(){}
       
   117     }
       
   118     > ;\n
       
   119 
       
   120     >         this.is_relative = 
       
   121     choose{
       
   122         when "func:is_relative_jump(.)" > true
       
   123         otherwise > false
   122     }
   124     }
   123     > ;\n
   125     > ;\n
   124     |     },
   126     |     },
   125 
   127 
   126 }
   128 }
   127 
   129 
   128 widget_page("Jump"){
   130 widget_page("Jump"){
   129     param "page_desc";
   131     param "page_desc";
   130     /* check that given path is compatible with page's reference path */
   132     /* jump is considered relative jump if first path points to HMI_NODE
   131     if "path" {
   133        but a jump can be forced Absolute by adding a "Absolute" argument */
   132         /* TODO: suport local variable containing an HMI_TREE index to jump to a relative page */
   134     if "func:is_relative_jump(.)" {
       
   135         /* if relative check that given path is compatible with page's reference path */
       
   136 
   133         /* when no page name provided, check for same page */
   137         /* when no page name provided, check for same page */
   134         const "target_page_name" choose {
   138         const "target_page_name" choose {
   135             when "arg" value "arg[1]/@value";
   139             when "arg" value "arg[1]/@value";
   136             otherwise value "$page_desc/arg[1]/@value";
   140             otherwise value "$page_desc/arg[1]/@value";
   137         }
   141         }
   140             otherwise value "$page_desc/path[1]/@value";
   144             otherwise value "$page_desc/path[1]/@value";
   141         }
   145         }
   142 
   146 
   143         if "not(func:same_class_paths($target_page_path, path[1]/@value))"
   147         if "not(func:same_class_paths($target_page_path, path[1]/@value))"
   144             error > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value» (must be same class as "«$target_page_path»")
   148             error > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value» (must be same class as "«$target_page_path»")
       
   149 
   145     }
   150     }
   146 }
   151 }
       
   152 
       
   153 
   147 
   154 
   148 /* TODO: move to detachable pages ysl2 */
   155 /* TODO: move to detachable pages ysl2 */
   149 emit "cssdefs:jump"
   156 emit "cssdefs:jump"
   150 ||
   157 ||
   151 .fade-out-page {
   158 .fade-out-page {