svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 3080 e5fa1f49f0b9
parent 3079 1021c6c74dde
child 3084 1ae4a871b6f9
equal deleted inserted replaced
3079:1021c6c74dde 3080:e5fa1f49f0b9
  3828 </xsl:text>
  3828 </xsl:text>
  3829     <xsl:text>    // arbitrary defaults to avoid missing entries in query
  3829     <xsl:text>    // arbitrary defaults to avoid missing entries in query
  3830 </xsl:text>
  3830 </xsl:text>
  3831     <xsl:text>    cache = [0,100,50];
  3831     <xsl:text>    cache = [0,100,50];
  3832 </xsl:text>
  3832 </xsl:text>
       
  3833     <xsl:text>    init() {
       
  3834 </xsl:text>
       
  3835     <xsl:text>        this.spread_json_data_bound = this.spread_json_data.bind(this);
       
  3836 </xsl:text>
       
  3837     <xsl:text>    }
       
  3838 </xsl:text>
       
  3839     <xsl:text>
       
  3840 </xsl:text>
       
  3841     <xsl:text>    handle_http_response(response) {
       
  3842 </xsl:text>
       
  3843     <xsl:text>        if (!response.ok) {
       
  3844 </xsl:text>
       
  3845     <xsl:text>          console.log("HTTP error, status = " + response.status);
       
  3846 </xsl:text>
       
  3847     <xsl:text>        }
       
  3848 </xsl:text>
       
  3849     <xsl:text>        return response.json();
       
  3850 </xsl:text>
       
  3851     <xsl:text>    }
       
  3852 </xsl:text>
       
  3853     <xsl:text>
       
  3854 </xsl:text>
  3833     <xsl:text>    do_http_request(...opt) {
  3855     <xsl:text>    do_http_request(...opt) {
  3834 </xsl:text>
  3856 </xsl:text>
  3835     <xsl:text>        const query = {
  3857     <xsl:text>        const query = {
  3836 </xsl:text>
  3858 </xsl:text>
  3837     <xsl:text>            args: this.args,
  3859     <xsl:text>            args: this.args,
  3862 </xsl:text>
  3884 </xsl:text>
  3863     <xsl:text>
  3885     <xsl:text>
  3864 </xsl:text>
  3886 </xsl:text>
  3865     <xsl:text>        fetch(this.args[0], options)
  3887     <xsl:text>        fetch(this.args[0], options)
  3866 </xsl:text>
  3888 </xsl:text>
  3867     <xsl:text>            .then(res =&gt; res.json())
  3889     <xsl:text>            .then(this.handle_http_response)
  3868 </xsl:text>
  3890 </xsl:text>
  3869     <xsl:text>            .then(this.spread_json_data.bind(this));
  3891     <xsl:text>            .then(this.spread_json_data_bound);
  3870 </xsl:text>
  3892 </xsl:text>
  3871     <xsl:text>
  3893     <xsl:text>
  3872 </xsl:text>
  3894 </xsl:text>
  3873     <xsl:text>    }
  3895     <xsl:text>    }
  3874 </xsl:text>
  3896 </xsl:text>
  3878 </xsl:text>
  3900 </xsl:text>
  3879     <xsl:text>        this.do_http_request();
  3901     <xsl:text>        this.do_http_request();
  3880 </xsl:text>
  3902 </xsl:text>
  3881     <xsl:text>    }
  3903     <xsl:text>    }
  3882 </xsl:text>
  3904 </xsl:text>
  3883     <xsl:text>    on_click(evt, ...options) {
  3905     <xsl:text>    make_on_click(...options){
  3884 </xsl:text>
  3906 </xsl:text>
  3885     <xsl:text>        this.do_http_request(...options);
  3907     <xsl:text>        return function(evt){
  3886 </xsl:text>
  3908 </xsl:text>
  3887     <xsl:text>    }
  3909     <xsl:text>            this.do_http_request(...options);
       
  3910 </xsl:text>
       
  3911     <xsl:text>        }
       
  3912 </xsl:text>
       
  3913     <xsl:text>    }
       
  3914 </xsl:text>
       
  3915     <xsl:text>    // on_click(evt, ...options) {
       
  3916 </xsl:text>
       
  3917     <xsl:text>    //     this.do_http_request(...options);
       
  3918 </xsl:text>
       
  3919     <xsl:text>    // }
  3888 </xsl:text>
  3920 </xsl:text>
  3889     <xsl:text>}
  3921     <xsl:text>}
  3890 </xsl:text>
  3922 </xsl:text>
  3891   </xsl:template>
  3923   </xsl:template>
  3892   <xsl:template mode="json_table_elt_render" match="svg:*">
  3924   <xsl:template mode="json_table_elt_render" match="svg:*">
  4071     <xsl:variable name="new_expressions" select="func:json_expressions($expressions, $label)"/>
  4103     <xsl:variable name="new_expressions" select="func:json_expressions($expressions, $label)"/>
  4072     <xsl:variable name="elt" select="."/>
  4104     <xsl:variable name="elt" select="."/>
  4073     <xsl:for-each select="$new_expressions/expression[position() &gt; 1][starts-with(@name,'onClick')]">
  4105     <xsl:for-each select="$new_expressions/expression[position() &gt; 1][starts-with(@name,'onClick')]">
  4074       <xsl:text>        id("</xsl:text>
  4106       <xsl:text>        id("</xsl:text>
  4075       <xsl:value-of select="$elt/@id"/>
  4107       <xsl:value-of select="$elt/@id"/>
  4076       <xsl:text>").setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt, '</xsl:text>
  4108       <xsl:text>").onclick = this.make_on_click('</xsl:text>
  4077       <xsl:value-of select="@name"/>
  4109       <xsl:value-of select="@name"/>
  4078       <xsl:text>', '"+</xsl:text>
  4110       <xsl:text>', '"+</xsl:text>
  4079       <xsl:value-of select="@content"/>
  4111       <xsl:value-of select="@content"/>
  4080       <xsl:text>+"')");
  4112       <xsl:text>+"');
  4081 </xsl:text>
  4113 </xsl:text>
  4082     </xsl:for-each>
  4114     </xsl:for-each>
  4083     <xsl:apply-templates mode="json_table_elt_render" select=".">
  4115     <xsl:apply-templates mode="json_table_elt_render" select=".">
  4084       <xsl:with-param name="expressions" select="$new_expressions"/>
  4116       <xsl:with-param name="expressions" select="$new_expressions"/>
  4085     </xsl:apply-templates>
  4117     </xsl:apply-templates>
  4132         </xsl:copy>
  4164         </xsl:copy>
  4133       </xsl:for-each>
  4165       </xsl:for-each>
  4134     </xsl:variable>
  4166     </xsl:variable>
  4135     <xsl:text>          id("</xsl:text>
  4167     <xsl:text>          id("</xsl:text>
  4136     <xsl:value-of select="@id"/>
  4168     <xsl:value-of select="@id"/>
  4137     <xsl:text>").setAttribute("style", "</xsl:text>
  4169     <xsl:text>").style = "</xsl:text>
  4138     <xsl:value-of select="@style"/>
  4170     <xsl:value-of select="@style"/>
  4139     <xsl:text>");
  4171     <xsl:text>";
  4140 </xsl:text>
  4172 </xsl:text>
  4141     <xsl:apply-templates mode="json_table_render_except_comments" select="*">
  4173     <xsl:apply-templates mode="json_table_render_except_comments" select="*">
  4142       <xsl:with-param name="expressions" select="func:json_expressions(exsl:node-set($new_expressions), $label)"/>
  4174       <xsl:with-param name="expressions" select="func:json_expressions(exsl:node-set($new_expressions), $label)"/>
  4143       <xsl:with-param name="widget_elts" select="$widget_elts"/>
  4175       <xsl:with-param name="widget_elts" select="$widget_elts"/>
  4144     </xsl:apply-templates>
  4176     </xsl:apply-templates>
  4145     <xsl:text>        } catch(err) {
  4177     <xsl:text>        } catch(err) {
  4146 </xsl:text>
  4178 </xsl:text>
  4147     <xsl:text>          id("</xsl:text>
  4179     <xsl:text>          id("</xsl:text>
  4148     <xsl:value-of select="$gid"/>
  4180     <xsl:value-of select="$gid"/>
  4149     <xsl:text>").setAttribute("style", "display:none");
  4181     <xsl:text>").style = "display:none";
  4150 </xsl:text>
  4182 </xsl:text>
  4151     <xsl:text>        }
  4183     <xsl:text>        }
  4152 </xsl:text>
  4184 </xsl:text>
  4153   </xsl:template>
  4185   </xsl:template>
  4154   <xsl:template mode="widget_defs" match="widget[@type='JsonTable']">
  4186   <xsl:template mode="widget_defs" match="widget[@type='JsonTable']">
  5983 </xsl:text>
  6015 </xsl:text>
  5984           <xsl:text>
  6016           <xsl:text>
  5985 </xsl:text>
  6017 </xsl:text>
  5986           <xsl:text>var updates = {};
  6018           <xsl:text>var updates = {};
  5987 </xsl:text>
  6019 </xsl:text>
  5988           <xsl:text>var need_cache_apply = []; 
  6020           <xsl:text>var need_cache_apply = [];
  5989 </xsl:text>
  6021 </xsl:text>
  5990           <xsl:text>
  6022           <xsl:text>
  5991 </xsl:text>
  6023 </xsl:text>
  5992           <xsl:text>
  6024           <xsl:text>
  5993 </xsl:text>
  6025 </xsl:text>
  6063 </xsl:text>
  6095 </xsl:text>
  6064           <xsl:text>    REAL: (dv,offset) =&gt; [dv.getFloat32(offset, true), 4],
  6096           <xsl:text>    REAL: (dv,offset) =&gt; [dv.getFloat32(offset, true), 4],
  6065 </xsl:text>
  6097 </xsl:text>
  6066           <xsl:text>    STRING: (dv, offset) =&gt; {
  6098           <xsl:text>    STRING: (dv, offset) =&gt; {
  6067 </xsl:text>
  6099 </xsl:text>
  6068           <xsl:text>        size = dv.getInt8(offset);
  6100           <xsl:text>        const size = dv.getInt8(offset);
  6069 </xsl:text>
  6101 </xsl:text>
  6070           <xsl:text>        return [
  6102           <xsl:text>        return [
  6071 </xsl:text>
  6103 </xsl:text>
  6072           <xsl:text>            String.fromCharCode.apply(null, new Uint8Array(
  6104           <xsl:text>            String.fromCharCode.apply(null, new Uint8Array(
  6073 </xsl:text>
  6105 </xsl:text>
  6245 </xsl:text>
  6277 </xsl:text>
  6246           <xsl:text>};
  6278           <xsl:text>};
  6247 </xsl:text>
  6279 </xsl:text>
  6248           <xsl:text>
  6280           <xsl:text>
  6249 </xsl:text>
  6281 </xsl:text>
       
  6282           <xsl:text>hmi_hash_u8 = new Uint8Array(hmi_hash);
       
  6283 </xsl:text>
  6250           <xsl:text>
  6284           <xsl:text>
  6251 </xsl:text>
  6285 </xsl:text>
  6252           <xsl:text>function send_blob(data) {
  6286           <xsl:text>function send_blob(data) {
  6253 </xsl:text>
  6287 </xsl:text>
  6254           <xsl:text>    if(data.length &gt; 0) {
  6288           <xsl:text>    if(data.length &gt; 0) {
  6255 </xsl:text>
  6289 </xsl:text>
  6256           <xsl:text>        ws.send(new Blob([new Uint8Array(hmi_hash)].concat(data)));
  6290           <xsl:text>        ws.send(new Blob([hmi_hash_u8].concat(data)));
  6257 </xsl:text>
  6291 </xsl:text>
  6258           <xsl:text>    };
  6292           <xsl:text>    };
  6259 </xsl:text>
  6293 </xsl:text>
  6260           <xsl:text>};
  6294           <xsl:text>};
  6261 </xsl:text>
  6295 </xsl:text>
  6277 </xsl:text>
  6311 </xsl:text>
  6278           <xsl:text>        binary = new Uint8Array(str.length + 1);
  6312           <xsl:text>        binary = new Uint8Array(str.length + 1);
  6279 </xsl:text>
  6313 </xsl:text>
  6280           <xsl:text>        binary[0] = str.length;
  6314           <xsl:text>        binary[0] = str.length;
  6281 </xsl:text>
  6315 </xsl:text>
  6282           <xsl:text>        for(var i = 0; i &lt; str.length; i++){
  6316           <xsl:text>        for(let i = 0; i &lt; str.length; i++){
  6283 </xsl:text>
  6317 </xsl:text>
  6284           <xsl:text>            binary[i+1] = str.charCodeAt(i);
  6318           <xsl:text>            binary[i+1] = str.charCodeAt(i);
  6285 </xsl:text>
  6319 </xsl:text>
  6286           <xsl:text>        }
  6320           <xsl:text>        }
  6287 </xsl:text>
  6321 </xsl:text>
  6665 </xsl:text>
  6699 </xsl:text>
  6666           <xsl:text>        old_desc.widgets.map(([widget,relativeness])=&gt;widget.unsub());
  6700           <xsl:text>        old_desc.widgets.map(([widget,relativeness])=&gt;widget.unsub());
  6667 </xsl:text>
  6701 </xsl:text>
  6668           <xsl:text>    }
  6702           <xsl:text>    }
  6669 </xsl:text>
  6703 </xsl:text>
  6670           <xsl:text>    var new_offset = page_index == undefined ? 0 : page_index - new_desc.page_index;
  6704           <xsl:text>    const new_offset = page_index == undefined ? 0 : page_index - new_desc.page_index;
  6671 </xsl:text>
  6705 </xsl:text>
  6672           <xsl:text>
  6706           <xsl:text>
  6673 </xsl:text>
  6707 </xsl:text>
  6674           <xsl:text>    container_id = page_name + (page_index != undefined ? page_index : "");
  6708           <xsl:text>    const container_id = page_name + (page_index != undefined ? page_index : "");
  6675 </xsl:text>
  6709 </xsl:text>
  6676           <xsl:text>
  6710           <xsl:text>
  6677 </xsl:text>
  6711 </xsl:text>
  6678           <xsl:text>    new_desc.widgets.map(([widget,relativeness])=&gt;widget.sub(new_offset,relativeness,container_id));
  6712           <xsl:text>    new_desc.widgets.map(([widget,relativeness])=&gt;widget.sub(new_offset,relativeness,container_id));
  6679 </xsl:text>
  6713 </xsl:text>
  6803 </xsl:text>
  6837 </xsl:text>
  6804           <xsl:text>};
  6838           <xsl:text>};
  6805 </xsl:text>
  6839 </xsl:text>
  6806           <xsl:text>
  6840           <xsl:text>
  6807 </xsl:text>
  6841 </xsl:text>
  6808           <xsl:text>var xmlns = "http://www.w3.org/2000/svg";
  6842           <xsl:text>const xmlns = "http://www.w3.org/2000/svg";
  6809 </xsl:text>
  6843 </xsl:text>
  6810           <xsl:text>var edit_callback;
  6844           <xsl:text>var edit_callback;
  6811 </xsl:text>
  6845 </xsl:text>
  6812           <xsl:text>const localtypes = {"PAGE_LOCAL":null, "HMI_LOCAL":null}
  6846           <xsl:text>const localtypes = {"PAGE_LOCAL":null, "HMI_LOCAL":null}
  6813 </xsl:text>
  6847 </xsl:text>
  6826           <xsl:text>    let widget = hmi_widgets[keypadid];
  6860           <xsl:text>    let widget = hmi_widgets[keypadid];
  6827 </xsl:text>
  6861 </xsl:text>
  6828           <xsl:text>    widget.start_edit(path, valuetype, callback, initial, size);
  6862           <xsl:text>    widget.start_edit(path, valuetype, callback, initial, size);
  6829 </xsl:text>
  6863 </xsl:text>
  6830           <xsl:text>};
  6864           <xsl:text>};
  6831 </xsl:text>
       
  6832           <xsl:text>
       
  6833 </xsl:text>
       
  6834           <xsl:text>
       
  6835 </xsl:text>
  6865 </xsl:text>
  6836           <xsl:text>
  6866           <xsl:text>
  6837 </xsl:text>
  6867 </xsl:text>
  6838           <xsl:text>var current_modal; /* TODO stack ?*/
  6868           <xsl:text>var current_modal; /* TODO stack ?*/
  6839 </xsl:text>
  6869 </xsl:text>