svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 3025 48e7e336c052
parent 3024 0a9f6f29b7dd
child 3026 d454ed480c0f
equal deleted inserted replaced
3024:0a9f6f29b7dd 3025:48e7e336c052
   873                   <xsl:text>" in HMI tree</xsl:text>
   873                   <xsl:text>" in HMI tree</xsl:text>
   874                 </xsl:message>
   874                 </xsl:message>
   875               </xsl:when>
   875               </xsl:when>
   876               <xsl:when test="@type = 'PAGE_LOCAL'">
   876               <xsl:when test="@type = 'PAGE_LOCAL'">
   877                 <xsl:text>"</xsl:text>
   877                 <xsl:text>"</xsl:text>
   878                 <xsl:value-of select="substring(@value, 1)"/>
   878                 <xsl:value-of select="@value"/>
   879                 <xsl:text>"</xsl:text>
   879                 <xsl:text>"</xsl:text>
   880                 <xsl:if test="position()!=last()">
   880                 <xsl:if test="position()!=last()">
   881                   <xsl:text>,</xsl:text>
   881                   <xsl:text>,</xsl:text>
   882                 </xsl:if>
   882                 </xsl:if>
   883               </xsl:when>
   883               </xsl:when>
   974           <xsl:text>VarInit </xsl:text>
   974           <xsl:text>VarInit </xsl:text>
   975           <xsl:value-of select="@id"/>
   975           <xsl:value-of select="@id"/>
   976           <xsl:text> only applies to HMI variable.</xsl:text>
   976           <xsl:text> only applies to HMI variable.</xsl:text>
   977         </xsl:message>
   977         </xsl:message>
   978       </xsl:if>
   978       </xsl:if>
   979       <xsl:value-of select="arg[0]"/>
   979       <xsl:text>"</xsl:text>
   980       <xsl:text>:</xsl:text>
       
   981       <xsl:value-of select="path/@value"/>
   980       <xsl:value-of select="path/@value"/>
       
   981       <xsl:text>":</xsl:text>
       
   982       <xsl:value-of select="arg[1]/@value"/>
   982       <xsl:if test="position()!=last()">
   983       <xsl:if test="position()!=last()">
   983         <xsl:text>,</xsl:text>
   984         <xsl:text>,</xsl:text>
   984       </xsl:if>
   985       </xsl:if>
   985       <xsl:text>
   986       <xsl:text>
   986 </xsl:text>
   987 </xsl:text>
  1019 </xsl:text>
  1020 </xsl:text>
  1020     <xsl:text>        pagevars[varname] = new_index;
  1021     <xsl:text>        pagevars[varname] = new_index;
  1021 </xsl:text>
  1022 </xsl:text>
  1022     <xsl:text>    }
  1023     <xsl:text>    }
  1023 </xsl:text>
  1024 </xsl:text>
       
  1025     <xsl:text>    let defaultval = local_defaults[varname];
       
  1026 </xsl:text>
       
  1027     <xsl:text>    console.log("page_local_index creat local", varname, pagename, new_index, defaultval);
       
  1028 </xsl:text>
       
  1029     <xsl:text>    if(defaultval != undefined) 
       
  1030 </xsl:text>
       
  1031     <xsl:text>        cache[new_index] = defaultval; 
       
  1032 </xsl:text>
  1024     <xsl:text>    return new_index;
  1033     <xsl:text>    return new_index;
  1025 </xsl:text>
  1034 </xsl:text>
  1026     <xsl:text>}
  1035     <xsl:text>}
  1027 </xsl:text>
  1036 </xsl:text>
  1028     <xsl:text>
  1037     <xsl:text>
  1130 </xsl:text>
  1139 </xsl:text>
  1131     <xsl:text>
  1140     <xsl:text>
  1132 </xsl:text>
  1141 </xsl:text>
  1133     <xsl:text>    apply_cache() {
  1142     <xsl:text>    apply_cache() {
  1134 </xsl:text>
  1143 </xsl:text>
  1135     <xsl:text>        if(!this.unsubscribable) for(let index of this.indexes){
  1144     <xsl:text>        let dispatch = this.dispatch;
       
  1145 </xsl:text>
       
  1146     <xsl:text>        if(dispatch == undefined) return;
       
  1147 </xsl:text>
       
  1148     <xsl:text>        if(!this.unsubscribable) for(let index in this.indexes){
  1136 </xsl:text>
  1149 </xsl:text>
  1137     <xsl:text>            /* dispatch current cache in newly opened page widgets */
  1150     <xsl:text>            /* dispatch current cache in newly opened page widgets */
  1138 </xsl:text>
  1151 </xsl:text>
  1139     <xsl:text>            let realindex = this.get_variable_index(index);
  1152     <xsl:text>            let realindex = this.get_variable_index(index);
  1140 </xsl:text>
  1153 </xsl:text>
  1141     <xsl:text>            let cached_val = cache[realindex];
  1154     <xsl:text>            let cached_val = cache[realindex];
  1142 </xsl:text>
  1155 </xsl:text>
  1143     <xsl:text>            if(cached_val != undefined)
  1156     <xsl:text>            if(cached_val != undefined)
  1144 </xsl:text>
  1157 </xsl:text>
  1145     <xsl:text>                this.new_hmi_value(realindex, cached_val, cached_val);
  1158     <xsl:text>                try {
       
  1159 </xsl:text>
       
  1160     <xsl:text>                    dispatch.call(this, cached_val, cached_val, index);
       
  1161 </xsl:text>
       
  1162     <xsl:text>                } catch(err) {
       
  1163 </xsl:text>
       
  1164     <xsl:text>                    console.log(err);
       
  1165 </xsl:text>
       
  1166     <xsl:text>                }
  1146 </xsl:text>
  1167 </xsl:text>
  1147     <xsl:text>        }
  1168     <xsl:text>        }
  1148 </xsl:text>
  1169 </xsl:text>
  1149     <xsl:text>    }
  1170     <xsl:text>    }
  1150 </xsl:text>
  1171 </xsl:text>
  1188 </xsl:text>
  1209 </xsl:text>
  1189     <xsl:text>
  1210     <xsl:text>
  1190 </xsl:text>
  1211 </xsl:text>
  1191     <xsl:text>    new_hmi_value(index, value, oldval) {
  1212     <xsl:text>    new_hmi_value(index, value, oldval) {
  1192 </xsl:text>
  1213 </xsl:text>
  1193     <xsl:text>        try {
  1214     <xsl:text>        // TODO avoid searching, store index at sub()
  1194 </xsl:text>
  1215 </xsl:text>
  1195     <xsl:text>            // TODO avoid searching, store index at sub()
  1216     <xsl:text>        let dispatch = this.dispatch;
  1196 </xsl:text>
  1217 </xsl:text>
  1197     <xsl:text>            for(let i = 0; i &lt; this.indexes.length; i++) {
  1218     <xsl:text>        if(dispatch == undefined) return;
  1198 </xsl:text>
  1219 </xsl:text>
  1199     <xsl:text>                let refindex = this.get_variable_index(i);
  1220     <xsl:text>        for(let i = 0; i &lt; this.indexes.length; i++) {
  1200 </xsl:text>
  1221 </xsl:text>
  1201     <xsl:text>
  1222     <xsl:text>            let refindex = this.get_variable_index(i);
  1202 </xsl:text>
  1223 </xsl:text>
  1203     <xsl:text>                if(index == refindex) {
  1224     <xsl:text>
  1204 </xsl:text>
  1225 </xsl:text>
  1205     <xsl:text>                    let d = this.dispatch;
  1226     <xsl:text>            if(index == refindex) {
  1206 </xsl:text>
  1227 </xsl:text>
  1207     <xsl:text>                    if(typeof(d) == "function"){
  1228     <xsl:text>                try {
  1208 </xsl:text>
  1229 </xsl:text>
  1209     <xsl:text>                        d.call(this, value, oldval, i);
  1230     <xsl:text>                    dispatch.call(this, value, oldval, i);
  1210 </xsl:text>
  1231 </xsl:text>
  1211     <xsl:text>                    }
  1232     <xsl:text>                } catch(err) {
  1212 </xsl:text>
  1233 </xsl:text>
  1213     <xsl:text>                    else if(typeof(d) == "object"){
  1234     <xsl:text>                    console.log(err);
  1214 </xsl:text>
       
  1215     <xsl:text>                        d[i].call(this, value, oldval);
       
  1216 </xsl:text>
       
  1217     <xsl:text>                    }
       
  1218 </xsl:text>
       
  1219     <xsl:text>                    /* else dispatch_0, ..., dispatch_n ? */
       
  1220 </xsl:text>
       
  1221     <xsl:text>                    /*else {
       
  1222 </xsl:text>
       
  1223     <xsl:text>                        throw new Error("Dunno how to dispatch to widget at index = " + index);
       
  1224 </xsl:text>
       
  1225     <xsl:text>                    }*/
       
  1226 </xsl:text>
       
  1227     <xsl:text>                    break;
       
  1228 </xsl:text>
  1235 </xsl:text>
  1229     <xsl:text>                }
  1236     <xsl:text>                }
  1230 </xsl:text>
  1237 </xsl:text>
       
  1238     <xsl:text>                break;
       
  1239 </xsl:text>
  1231     <xsl:text>            }
  1240     <xsl:text>            }
  1232 </xsl:text>
       
  1233     <xsl:text>        } catch(err) {
       
  1234 </xsl:text>
       
  1235     <xsl:text>            console.log(err);
       
  1236 </xsl:text>
  1241 </xsl:text>
  1237     <xsl:text>        }
  1242     <xsl:text>        }
  1238 </xsl:text>
  1243 </xsl:text>
  1239     <xsl:text>    }
  1244     <xsl:text>    }
  1240 </xsl:text>
  1245 </xsl:text>