svghmi/widget_jump.ysl2
changeset 3596 9c725829d8f0
parent 3595 375626e60b63
child 3597 f69c68cffec3
equal deleted inserted replaced
3595:375626e60b63 3596:9c725829d8f0
     4     longdesc
     4     longdesc
     5     ||
     5     ||
     6     Jump widget brings focus to a different page. Mandatory first 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     If first path is pointint to HMI_NODE variable is used as new reference 
     9     If first path is pointint to HMI_NODE variable is used as new reference
    10     when jumping to a relative page.
    10     when jumping to a relative page.
    11 
    11 
    12     Additional arguments are unordered options:
    12     Additional arguments are unordered options:
    13 
    13 
    14     - Absolute: force page jump to be not relative even if first path is of type HMI_NODE
    14     - Absolute: force page jump to be not relative even if first path is of type HMI_NODE
    15 
    15 
    16     - name=value: Notify jump by setting variable with path having same name assigned
    16     - name=value: Notify jump by setting variable with path having same name assigned
    17         
    17 
    18     "active"+"inactive" labeled elements can be provided and reflect current
    18     "active"+"inactive" labeled elements can be provided and reflect current
    19     page being shown.
    19     page being shown.
    20 
    20 
    21     Exemples:
    21     Exemples:
    22     
    22 
    23     Relative jump:
    23     Relative jump:
    24 
    24 
    25     HMI:Jump:RelativePage@/PUMP9
    25     HMI:Jump:RelativePage@/PUMP9
    26     HMI:Jump:RelativePage@/PUMP9@role=.userrole#role=="admin"
    26     HMI:Jump:RelativePage@/PUMP9@role=.userrole#role=="admin"
    27 
    27 
    45 }
    45 }
    46 
    46 
    47 widget_class("Jump") {
    47 widget_class("Jump") {
    48 ||
    48 ||
    49         activable = false;
    49         activable = false;
    50         active = false;
       
    51         frequency = 2;
    50         frequency = 2;
    52 
       
    53         update_activity() {
       
    54             this.set_activation_state(this.active);
       
    55         }
       
    56 
       
    57         update_disability() {
       
    58             this.animate_enable();
       
    59             if(this.enable_state) {
       
    60                 this.update_activity();
       
    61             }
       
    62         }
       
    63 
    51 
    64         make_on_click() {
    52         make_on_click() {
    65             let that = this;
    53             let that = this;
    66             const name = this.args[0];
    54             const name = this.args[0];
    67             return function(evt){
    55             return function(evt){
    68                 /* TODO: in order to allow jumps to page selected through for exemple a dropdown,
    56                 /* TODO: in order to allow jumps to page selected through
    69                    support path pointing to local variable whom value 
    57                    for exemple a dropdown, support path pointing to local
    70                    would be an HMI_TREE index and then jump to a relative page not hard-coded in advance */
    58                    variable whom value would be an HMI_TREE index and then
       
    59                    jump to a relative page not hard-coded in advance
       
    60                 */
    71                 if(that.enable_state) {
    61                 if(that.enable_state) {
    72                     const index = (that.is_relative && that.indexes.length > 0) ? that.indexes[0] + that.offset : undefined;
    62                     const index =
       
    63                         (that.is_relative && that.indexes.length > 0) ?
       
    64                         that.indexes[0] + that.offset : undefined;
    73                     fading_page_switch(name, index);
    65                     fading_page_switch(name, index);
    74                 }
    66                 }
    75             }
    67             }
    76         }
    68         }
    77 
    69 
    78         notify_page_change(page_name, index) {
    70         notify_page_change(page_name, index) {
       
    71             // called from animate()
    79             if(this.activable) {
    72             if(this.activable) {
    80                 const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
    73                 const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
    81                 const ref_name = this.args[0];
    74                 const ref_name = this.args[0];
    82                 this.active = ((ref_name == undefined || ref_name == page_name) && index == ref_index);
    75                 this.activity_state = ((ref_name == undefined || ref_name == page_name) && index == ref_index);
    83                 this.update_state();
    76                 // Since called from animate, update activity directly
       
    77                 if(this.enable_displayed_state && this.has_activity) {
       
    78                     this.animate_activity();
       
    79                 }
    84             }
    80             }
    85         }
       
    86 
       
    87         animate() {
       
    88             this.update_state();
       
    89         }
    81         }
    90 ||
    82 ||
    91 }
    83 }
    92 
    84 
    93 def "func:is_relative_jump" {
    85 def "func:is_relative_jump" {
   103     |     init: function() {
    95     |     init: function() {
   104     |         this.element.onclick = this.make_on_click();
    96     |         this.element.onclick = this.make_on_click();
   105     if "$has_activity" {
    97     if "$has_activity" {
   106     |         this.activable = true;
    98     |         this.activable = true;
   107     }
    99     }
   108     >         this.update_state = 
       
   109     choose {
       
   110         when "$jump_disability" {
       
   111             > this.update_disability
       
   112         }
       
   113         when "$has_activity" {
       
   114             > this.update_activity
       
   115         }
       
   116         otherwise > function(){}
       
   117     }
       
   118     > ;\n
       
   119 
   100 
   120     >         this.is_relative = 
   101     >         this.is_relative = 
   121     choose{
   102     choose{
   122         when "func:is_relative_jump(.)" > true
   103         when "func:is_relative_jump(.)" > true
   123         otherwise > false
   104         otherwise > false
   170 ||
   151 ||
   171 var jumps_need_update = false;
   152 var jumps_need_update = false;
   172 var jump_history = [[default_page, undefined]];
   153 var jump_history = [[default_page, undefined]];
   173 
   154 
   174 function update_jumps() {
   155 function update_jumps() {
       
   156     // called from animate()
   175     page_desc[current_visible_page].jumps.map(w=>w.notify_page_change(current_visible_page,current_page_index));
   157     page_desc[current_visible_page].jumps.map(w=>w.notify_page_change(current_visible_page,current_page_index));
   176     jumps_need_update = false;
   158     jumps_need_update = false;
   177 };
   159 };
   178 
   160 
   179 ||
   161 ||