svghmi/widgets_common.ysl2
changeset 3522 f3a14422d56e
parent 3520 b27e50143083
child 3556 5d73bed497de
equal deleted inserted replaced
3521:4345b3c9b9de 3522:f3a14422d56e
    12         with "mandatory","'no'";
    12         with "mandatory","'no'";
    13         content;
    13         content;
    14     }
    14     }
    15 };
    15 };
    16 
    16 
       
    17 decl warning_labels(*ptr) alias - {
       
    18     labels(*ptr){
       
    19         with "mandatory","'warn'";
       
    20         content;
       
    21     }
       
    22 };
       
    23 
    17 decl activable() alias - {
    24 decl activable() alias - {
    18     |     activable_sub:{
    25     |     activable_sub:{
    19     labels("/active /inactive") {
    26     warning_labels("/active /inactive") {
    20         content;
    27         content;
    21     }
    28     }
    22     |     }
    29     |     }
    23 };
    30 };
    24 decl activable_labels(*ptr) alias - {
    31 decl activable_labels(*ptr) alias - {
   179     function _show(elt, placeholder){
   186     function _show(elt, placeholder){
   180         placeholder.parentNode.insertBefore(elt, placeholder);
   187         placeholder.parentNode.insertBefore(elt, placeholder);
   181     }
   188     }
   182 
   189 
   183     function set_activation_state(eltsub, state){
   190     function set_activation_state(eltsub, state){
   184         if(eltsub.active_elt_placeholder == undefined){
   191         if(eltsub.active_elt != undefined){
   185             eltsub.active_elt_placeholder = document.createComment("");
   192             if(eltsub.active_elt_placeholder == undefined){
   186             eltsub.active_elt.parentNode.insertBefore(eltsub.active_elt_placeholder, eltsub.active_elt);
   193                 eltsub.active_elt_placeholder = document.createComment("");
   187             eltsub.inactive_elt_placeholder = document.createComment("");
   194                 eltsub.active_elt.parentNode.insertBefore(eltsub.active_elt_placeholder, eltsub.active_elt);
   188             eltsub.inactive_elt.parentNode.insertBefore(eltsub.inactive_elt_placeholder, eltsub.inactive_elt);
   195             }
   189         }
   196             (state?_show:_hide)(eltsub.active_elt, eltsub.active_elt_placeholder);
   190         (state?_show:_hide)(eltsub.active_elt, eltsub.active_elt_placeholder);
   197         }
   191         ((state || state==undefined)?_hide:_show)(eltsub.inactive_elt, eltsub.inactive_elt_placeholder);
   198         if(eltsub.inactive_elt != undefined){
       
   199             if(eltsub.inactive_elt_placeholder == undefined){
       
   200                 eltsub.inactive_elt_placeholder = document.createComment("");
       
   201                 eltsub.inactive_elt.parentNode.insertBefore(eltsub.inactive_elt_placeholder, eltsub.inactive_elt);
       
   202             }
       
   203             ((state || state==undefined)?_hide:_show)(eltsub.inactive_elt, eltsub.inactive_elt_placeholder);
       
   204         }
   192     }
   205     }
   193 
   206 
   194     function activate_activable(eltsub) {
   207     function activate_activable(eltsub) {
   195         set_activation_state(eltsub, true);
   208         set_activation_state(eltsub, true);
   196     }
   209     }
   487     param "labels","''";
   500     param "labels","''";
   488     param "mandatory","'yes'";
   501     param "mandatory","'yes'";
   489     param "subelements","/..";
   502     param "subelements","/..";
   490     param "hmi_element";
   503     param "hmi_element";
   491     const "widget_type","@type";
   504     const "widget_type","@type";
       
   505     const "widget_id","@id";
   492     foreach "str:split($labels)" {
   506     foreach "str:split($labels)" {
   493         const "absolute", "starts-with(., '/')";
   507         const "absolute", "starts-with(., '/')";
   494         const "name","substring(.,number($absolute)+1)";
   508         const "name","substring(.,number($absolute)+1)";
   495         const "widget","$result_widgets[@id = $hmi_element/@id]";
   509         const "widget","$result_widgets[@id = $hmi_element/@id]";
   496         const "elt","($widget//*[not($absolute) and @inkscape:label=$name] | $widget/*[$absolute and @inkscape:label=$name])[1]";
   510         const "elt","($widget//*[not($absolute) and @inkscape:label=$name] | $widget/*[$absolute and @inkscape:label=$name])[1]";
   497         choose {
   511         choose {
   498             when "not($elt/@id)" {
   512             when "not($elt/@id)" {
   499                 if "$mandatory='yes'" {
   513                 if "$mandatory!='no'" {
   500                     error > «$widget_type» widget must have a «$name» element
   514                     const "errmsg" > «$widget_type» widget (id=«$widget_id») must have a «$name» element
       
   515                     choose { 
       
   516                         when "$mandatory='yes'" {
       
   517                             error > «$errmsg»
       
   518                         }
       
   519                         otherwise {
       
   520                             warning > «$errmsg»
       
   521                         }
       
   522                     }
   501                 }
   523                 }
   502                 // otherwise produce nothing
   524                 // otherwise produce nothing
   503             }
   525             }
   504             otherwise {
   526             otherwise {
   505                 |     «$name»_elt: id("«$elt/@id»"),
   527                 |     «$name»_elt: id("«$elt/@id»"),
   508                     foreach "str:split($subelements)" {
   530                     foreach "str:split($subelements)" {
   509                         const "subname",".";
   531                         const "subname",".";
   510                         const "subelt","$elt/*[@inkscape:label=$subname][1]";
   532                         const "subelt","$elt/*[@inkscape:label=$subname][1]";
   511                         choose {
   533                         choose {
   512                             when "not($subelt/@id)" {
   534                             when "not($subelt/@id)" {
   513                                 if "$mandatory='yes'" {
   535                                 if "$mandatory!='no'" {
   514                                     error > «$widget_type» widget must have a «$name»/«$subname» element
   536                                     const "errmsg" > «$widget_type» widget (id=«$widget_id») must have a «$name»/«$subname» element
       
   537                                     choose { 
       
   538                                         when "$mandatory='yes'" {
       
   539                                             error > «$errmsg»
       
   540                                         }
       
   541                                         otherwise {
       
   542                                             warning > «$errmsg»
       
   543                                         }
       
   544                                     }
   515                                 }
   545                                 }
   516                 |         /* missing «$name»/«$subname» element */
   546                 |         /* missing «$name»/«$subname» element */
   517                             }
   547                             }
   518                             otherwise {
   548                             otherwise {
   519                 |         "«$subname»_elt": id("«$subelt/@id»")`if "position()!=last()" > ,`
   549                 |         "«$subname»_elt": id("«$subelt/@id»")`if "position()!=last()" > ,`