svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2895 89c02b452717
parent 2894 4cf9ad35e6d0
child 2896 99c5335ed59f
equal deleted inserted replaced
2894:4cf9ad35e6d0 2895:89c02b452717
   745 </xsl:text>
   745 </xsl:text>
   746     <xsl:text>        /* TODO elt.setAttribute("onclick", "hmi_widgets['</xsl:text>
   746     <xsl:text>        /* TODO elt.setAttribute("onclick", "hmi_widgets['</xsl:text>
   747     <xsl:value-of select="$hmi_element/@id"/>
   747     <xsl:value-of select="$hmi_element/@id"/>
   748     <xsl:text>'].on_click(evt)");*/
   748     <xsl:text>'].on_click(evt)");*/
   749 </xsl:text>
   749 </xsl:text>
   750     <xsl:text>    },
   750     <xsl:text>        this.items = [
   751 </xsl:text>
       
   752     <xsl:text>    items: [
       
   753 </xsl:text>
   751 </xsl:text>
   754     <xsl:variable name="items_regex" select="concat('^',$prefix,'[0-9]+')"/>
   752     <xsl:variable name="items_regex" select="concat('^',$prefix,'[0-9]+')"/>
   755     <xsl:variable name="unordered_items" select="$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]"/>
   753     <xsl:variable name="unordered_items" select="$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]"/>
   756     <xsl:for-each select="$unordered_items">
   754     <xsl:for-each select="$unordered_items">
   757       <xsl:variable name="elt_label" select="concat($prefix, string(position()))"/>
   755       <xsl:variable name="elt_label" select="concat($prefix, string(position()))"/>
   758       <xsl:variable name="elt" select="$unordered_items[@inkscape:label = $elt_label]"/>
   756       <xsl:variable name="elt" select="$unordered_items[@inkscape:label = $elt_label]"/>
   759       <xsl:variable name="pos" select="position()"/>
   757       <xsl:variable name="pos" select="position()"/>
   760       <xsl:variable name="item_path" select="$items_paths[$pos]"/>
   758       <xsl:variable name="item_path" select="$items_paths[$pos]"/>
   761       <xsl:text>      [ /* item="</xsl:text>
   759       <xsl:text>          [ /* item="</xsl:text>
   762       <xsl:value-of select="$elt_label"/>
   760       <xsl:value-of select="$elt_label"/>
   763       <xsl:text>" path="</xsl:text>
   761       <xsl:text>" path="</xsl:text>
   764       <xsl:value-of select="$item_path"/>
   762       <xsl:value-of select="$item_path"/>
   765       <xsl:text>" */
   763       <xsl:text>" */
   766 </xsl:text>
   764 </xsl:text>
   784             <xsl:text>", path should be descendant of </xsl:text>
   782             <xsl:text>", path should be descendant of </xsl:text>
   785             <xsl:value-of select="$item_path"/>
   783             <xsl:value-of select="$item_path"/>
   786             <xsl:text>.</xsl:text>
   784             <xsl:text>.</xsl:text>
   787           </xsl:message>
   785           </xsl:message>
   788         </xsl:if>
   786         </xsl:if>
   789         <xsl:text>        hmi_widgets["</xsl:text>
   787         <xsl:text>            hmi_widgets["</xsl:text>
   790         <xsl:value-of select="@id"/>
   788         <xsl:value-of select="@id"/>
   791         <xsl:text>"]</xsl:text>
   789         <xsl:text>"]</xsl:text>
   792         <xsl:if test="position()!=last()">
   790         <xsl:if test="position()!=last()">
   793           <xsl:text>,</xsl:text>
   791           <xsl:text>,</xsl:text>
   794         </xsl:if>
   792         </xsl:if>
   795         <xsl:text>
   793         <xsl:text>
   796 </xsl:text>
   794 </xsl:text>
   797       </xsl:for-each>
   795       </xsl:for-each>
   798       <xsl:text>      ]</xsl:text>
   796       <xsl:text>          ]</xsl:text>
   799       <xsl:if test="position()!=last()">
   797       <xsl:if test="position()!=last()">
   800         <xsl:text>,</xsl:text>
   798         <xsl:text>,</xsl:text>
   801       </xsl:if>
   799       </xsl:if>
   802       <xsl:text>
   800       <xsl:text>
   803 </xsl:text>
   801 </xsl:text>
   804     </xsl:for-each>
   802     </xsl:for-each>
   805     <xsl:text>    ],
   803     <xsl:text>        ]
       
   804 </xsl:text>
       
   805     <xsl:text>    },
       
   806 </xsl:text>
       
   807     <xsl:text>    item_offset: 0,
   806 </xsl:text>
   808 </xsl:text>
   807   </xsl:template>
   809   </xsl:template>
   808   <xsl:template mode="widget_subscribe" match="widget[@type='ForEach']">
   810   <xsl:template mode="widget_subscribe" match="widget[@type='ForEach']">
   809     <xsl:text>    sub: function(off){
   811     <xsl:text>    sub: function(off){
   810 </xsl:text>
   812 </xsl:text>
   811     <xsl:text>        /*subscribe.call(this,off);*/
   813     <xsl:text>        subscribe_foreach.call(this,off);
   812 </xsl:text>
   814 </xsl:text>
   813     <xsl:text>    },
   815     <xsl:text>    },
   814 </xsl:text>
   816 </xsl:text>
   815     <xsl:text>    unsub: function(){
   817     <xsl:text>    unsub: function(){
   816 </xsl:text>
   818 </xsl:text>
   817     <xsl:text>        /*unsubscribe.call(this);*/
   819     <xsl:text>        unsubscribe_foreach.call(this);
   818 </xsl:text>
   820 </xsl:text>
   819     <xsl:text>    },
   821     <xsl:text>    },
   820 </xsl:text>
   822 </xsl:text>
   821   </xsl:template>
   823   </xsl:template>
   822   <xsl:template mode="widget_defs" match="widget[@type='Input']">
   824   <xsl:template mode="widget_defs" match="widget[@type='Input']">
  1313 </xsl:text>
  1315 </xsl:text>
  1314     <xsl:text>        switch_visible_page(current_subscribed_page);
  1316     <xsl:text>        switch_visible_page(current_subscribed_page);
  1315 </xsl:text>
  1317 </xsl:text>
  1316     <xsl:text>    }
  1318     <xsl:text>    }
  1317 </xsl:text>
  1319 </xsl:text>
       
  1320     <xsl:text>
       
  1321 </xsl:text>
       
  1322     <xsl:text>    if(current_subscribed_page_index != current_visible_page_index){
       
  1323 </xsl:text>
       
  1324     <xsl:text>        apply_cache();
       
  1325 </xsl:text>
       
  1326     <xsl:text>    }
       
  1327 </xsl:text>
  1318     <xsl:text>    apply_updates();
  1328     <xsl:text>    apply_updates();
  1319 </xsl:text>
  1329 </xsl:text>
  1320     <xsl:text>    requestAnimationFrameID = null;
  1330     <xsl:text>    requestAnimationFrameID = null;
  1321 </xsl:text>
  1331 </xsl:text>
  1322     <xsl:text>}
  1332     <xsl:text>}
  1647 </xsl:text>
  1657 </xsl:text>
  1648     <xsl:text>var current_visible_page;
  1658     <xsl:text>var current_visible_page;
  1649 </xsl:text>
  1659 </xsl:text>
  1650     <xsl:text>var current_subscribed_page;
  1660     <xsl:text>var current_subscribed_page;
  1651 </xsl:text>
  1661 </xsl:text>
       
  1662     <xsl:text>var current_visible_page_index;
       
  1663 </xsl:text>
       
  1664     <xsl:text>var current_subscribed_page_index;
       
  1665 </xsl:text>
  1652     <xsl:text>
  1666     <xsl:text>
  1653 </xsl:text>
  1667 </xsl:text>
  1654     <xsl:text>function prepare_svg() {
  1668     <xsl:text>function prepare_svg() {
  1655 </xsl:text>
  1669 </xsl:text>
  1656     <xsl:text>    for(let eltid in detachable_elements){
  1670     <xsl:text>    for(let eltid in detachable_elements){
  1673 </xsl:text>
  1687 </xsl:text>
  1674     <xsl:text>        /* TODO LOG ERROR */
  1688     <xsl:text>        /* TODO LOG ERROR */
  1675 </xsl:text>
  1689 </xsl:text>
  1676     <xsl:text>        return;
  1690     <xsl:text>        return;
  1677 </xsl:text>
  1691 </xsl:text>
  1678     <xsl:text>    } else if(page_name == current_visible_page){
  1692     <xsl:text>    }
  1679 </xsl:text>
  1693 </xsl:text>
  1680     <xsl:text>        /* already in that page */
  1694     <xsl:text>
       
  1695 </xsl:text>
       
  1696     <xsl:text>    if(page_name == undefined)
       
  1697 </xsl:text>
       
  1698     <xsl:text>        page_name = current_subscribed_page;
       
  1699 </xsl:text>
       
  1700     <xsl:text>
       
  1701 </xsl:text>
       
  1702     <xsl:text>    switch_subscribed_page(page_name, page_index);
       
  1703 </xsl:text>
       
  1704     <xsl:text>};
       
  1705 </xsl:text>
       
  1706     <xsl:text>
       
  1707 </xsl:text>
       
  1708     <xsl:text>function* chain(a,b){
       
  1709 </xsl:text>
       
  1710     <xsl:text>    yield* a;
       
  1711 </xsl:text>
       
  1712     <xsl:text>    yield* b;
       
  1713 </xsl:text>
       
  1714     <xsl:text>};
       
  1715 </xsl:text>
       
  1716     <xsl:text>
       
  1717 </xsl:text>
       
  1718     <xsl:text>function unsubscribe(){
       
  1719 </xsl:text>
       
  1720     <xsl:text>    /* remove subsribers */
       
  1721 </xsl:text>
       
  1722     <xsl:text>    for(let index of this.indexes){
       
  1723 </xsl:text>
       
  1724     <xsl:text>        let idx = index + this.offset;
       
  1725 </xsl:text>
       
  1726     <xsl:text>        subscribers[idx].delete(this);
       
  1727 </xsl:text>
       
  1728     <xsl:text>    }
       
  1729 </xsl:text>
       
  1730     <xsl:text>    this.offset = 0;
       
  1731 </xsl:text>
       
  1732     <xsl:text>}
       
  1733 </xsl:text>
       
  1734     <xsl:text>
       
  1735 </xsl:text>
       
  1736     <xsl:text>function subscribe(new_offset=0){
       
  1737 </xsl:text>
       
  1738     <xsl:text>    /* set the offset because relative */
       
  1739 </xsl:text>
       
  1740     <xsl:text>    this.offset = new_offset;
       
  1741 </xsl:text>
       
  1742     <xsl:text>    /* add this's subsribers */
       
  1743 </xsl:text>
       
  1744     <xsl:text>    for(let index of this.indexes){
       
  1745 </xsl:text>
       
  1746     <xsl:text>        subscribers[index + new_offset].add(this);
       
  1747 </xsl:text>
       
  1748     <xsl:text>    }
       
  1749 </xsl:text>
       
  1750     <xsl:text>}
       
  1751 </xsl:text>
       
  1752     <xsl:text>
       
  1753 </xsl:text>
       
  1754     <xsl:text>function unsubscribe_foreach(){
       
  1755 </xsl:text>
       
  1756     <xsl:text>    for(let item of this.items){
       
  1757 </xsl:text>
       
  1758     <xsl:text>        for(let widget of item) {
       
  1759 </xsl:text>
       
  1760     <xsl:text>            unsubscribe.call(widget);
       
  1761 </xsl:text>
       
  1762     <xsl:text>        }
       
  1763 </xsl:text>
       
  1764     <xsl:text>    }
       
  1765 </xsl:text>
       
  1766     <xsl:text>}
       
  1767 </xsl:text>
       
  1768     <xsl:text>
       
  1769 </xsl:text>
       
  1770     <xsl:text>function subscribe_foreach(new_offset=0){
       
  1771 </xsl:text>
       
  1772     <xsl:text>    for(let i = 0; i &lt; this.items.length; i++) {
       
  1773 </xsl:text>
       
  1774     <xsl:text>        let item = this.items[i];
       
  1775 </xsl:text>
       
  1776     <xsl:text>        let orig_item_index = this.index_pool[i];
       
  1777 </xsl:text>
       
  1778     <xsl:text>        let item_index = this.index_pool[i+this.item_offset];
       
  1779 </xsl:text>
       
  1780     <xsl:text>        let item_index_offset = item_index - orig_item_index;
       
  1781 </xsl:text>
       
  1782     <xsl:text>        for(let widget of item) {
       
  1783 </xsl:text>
       
  1784     <xsl:text>            subscribe.call(widget,new_offset + item_index_offset);
       
  1785 </xsl:text>
       
  1786     <xsl:text>        }
       
  1787 </xsl:text>
       
  1788     <xsl:text>    }
       
  1789 </xsl:text>
       
  1790     <xsl:text>}
       
  1791 </xsl:text>
       
  1792     <xsl:text>
       
  1793 </xsl:text>
       
  1794     <xsl:text>function switch_subscribed_page(page_name, page_index) {
       
  1795 </xsl:text>
       
  1796     <xsl:text>    let old_desc = page_desc[current_subscribed_page];
       
  1797 </xsl:text>
       
  1798     <xsl:text>    let new_desc = page_desc[page_name];
       
  1799 </xsl:text>
       
  1800     <xsl:text>
       
  1801 </xsl:text>
       
  1802     <xsl:text>    if(new_desc == undefined){
  1681 </xsl:text>
  1803 </xsl:text>
  1682     <xsl:text>        /* TODO LOG ERROR */
  1804     <xsl:text>        /* TODO LOG ERROR */
  1683 </xsl:text>
  1805 </xsl:text>
  1684     <xsl:text>        return;
  1806     <xsl:text>        return;
  1685 </xsl:text>
  1807 </xsl:text>
  1686     <xsl:text>    }
  1808     <xsl:text>    }
  1687 </xsl:text>
  1809 </xsl:text>
  1688     <xsl:text>    switch_subscribed_page(page_name, page_index);
  1810     <xsl:text>
       
  1811 </xsl:text>
       
  1812     <xsl:text>    if(page_index == undefined){
       
  1813 </xsl:text>
       
  1814     <xsl:text>        page_index = new_desc.page_index;
       
  1815 </xsl:text>
       
  1816     <xsl:text>    }
       
  1817 </xsl:text>
       
  1818     <xsl:text>
       
  1819 </xsl:text>
       
  1820     <xsl:text>    if(old_desc){
       
  1821 </xsl:text>
       
  1822     <xsl:text>        old_desc.absolute_widgets.map(w=&gt;w.unsub());
       
  1823 </xsl:text>
       
  1824     <xsl:text>        old_desc.relative_widgets.map(w=&gt;w.unsub());
       
  1825 </xsl:text>
       
  1826     <xsl:text>    }
       
  1827 </xsl:text>
       
  1828     <xsl:text>    new_desc.absolute_widgets.map(w=&gt;w.sub());
       
  1829 </xsl:text>
       
  1830     <xsl:text>    var new_offset = page_index == undefined ? 0 : page_index - new_desc.page_index;
       
  1831 </xsl:text>
       
  1832     <xsl:text>    new_desc.relative_widgets.map(w=&gt;w.sub(new_offset));
       
  1833 </xsl:text>
       
  1834     <xsl:text>
       
  1835 </xsl:text>
       
  1836     <xsl:text>    update_subscriptions();
       
  1837 </xsl:text>
       
  1838     <xsl:text>
       
  1839 </xsl:text>
       
  1840     <xsl:text>    current_subscribed_page = page_name;
       
  1841 </xsl:text>
       
  1842     <xsl:text>    current_subscribed_page_index = page_index;
       
  1843 </xsl:text>
       
  1844     <xsl:text>
       
  1845 </xsl:text>
       
  1846     <xsl:text>    requestHMIAnimation();
       
  1847 </xsl:text>
       
  1848     <xsl:text>}
       
  1849 </xsl:text>
       
  1850     <xsl:text>
       
  1851 </xsl:text>
       
  1852     <xsl:text>function switch_visible_page(page_name) {
       
  1853 </xsl:text>
       
  1854     <xsl:text>
       
  1855 </xsl:text>
       
  1856     <xsl:text>    let old_desc = page_desc[current_visible_page];
       
  1857 </xsl:text>
       
  1858     <xsl:text>    let new_desc = page_desc[page_name];
       
  1859 </xsl:text>
       
  1860     <xsl:text>
       
  1861 </xsl:text>
       
  1862     <xsl:text>    if(old_desc){
       
  1863 </xsl:text>
       
  1864     <xsl:text>        for(let eltid in old_desc.required_detachables){
       
  1865 </xsl:text>
       
  1866     <xsl:text>            if(!(eltid in new_desc.required_detachables)){
       
  1867 </xsl:text>
       
  1868     <xsl:text>                let [element, parent] = old_desc.required_detachables[eltid];
       
  1869 </xsl:text>
       
  1870     <xsl:text>                parent.removeChild(element);
       
  1871 </xsl:text>
       
  1872     <xsl:text>            }
       
  1873 </xsl:text>
       
  1874     <xsl:text>        }
       
  1875 </xsl:text>
       
  1876     <xsl:text>        for(let eltid in new_desc.required_detachables){
       
  1877 </xsl:text>
       
  1878     <xsl:text>            if(!(eltid in old_desc.required_detachables)){
       
  1879 </xsl:text>
       
  1880     <xsl:text>                let [element, parent] = new_desc.required_detachables[eltid];
       
  1881 </xsl:text>
       
  1882     <xsl:text>                parent.appendChild(element);
       
  1883 </xsl:text>
       
  1884     <xsl:text>            }
       
  1885 </xsl:text>
       
  1886     <xsl:text>        }
       
  1887 </xsl:text>
       
  1888     <xsl:text>    }else{
       
  1889 </xsl:text>
       
  1890     <xsl:text>        for(let eltid in new_desc.required_detachables){
       
  1891 </xsl:text>
       
  1892     <xsl:text>            let [element, parent] = new_desc.required_detachables[eltid];
       
  1893 </xsl:text>
       
  1894     <xsl:text>            parent.appendChild(element);
       
  1895 </xsl:text>
       
  1896     <xsl:text>        }
       
  1897 </xsl:text>
       
  1898     <xsl:text>    }
       
  1899 </xsl:text>
       
  1900     <xsl:text>
       
  1901 </xsl:text>
       
  1902     <xsl:text>    svg_root.setAttribute('viewBox',new_desc.bbox.join(" "));
       
  1903 </xsl:text>
       
  1904     <xsl:text>    current_visible_page = page_name;
  1689 </xsl:text>
  1905 </xsl:text>
  1690     <xsl:text>};
  1906     <xsl:text>};
  1691 </xsl:text>
  1907 </xsl:text>
  1692     <xsl:text>
  1908     <xsl:text>    
  1693 </xsl:text>
  1909 </xsl:text>
  1694     <xsl:text>function* chain(a,b){
  1910     <xsl:text>function apply_cache() {
  1695 </xsl:text>
  1911 </xsl:text>
  1696     <xsl:text>    yield* a;
  1912     <xsl:text>    let new_desc = page_desc[current_visible_page];
  1697 </xsl:text>
  1913 </xsl:text>
  1698     <xsl:text>    yield* b;
  1914     <xsl:text>    for(let widget of chain(new_desc.absolute_widgets,new_desc.relative_widgets)){
       
  1915 </xsl:text>
       
  1916     <xsl:text>        for(let index of widget.indexes){
       
  1917 </xsl:text>
       
  1918     <xsl:text>            /* dispatch current cache in newly opened page widgets */
       
  1919 </xsl:text>
       
  1920     <xsl:text>            let realindex = index+widget.offset;
       
  1921 </xsl:text>
       
  1922     <xsl:text>            let cached_val = cache[realindex];
       
  1923 </xsl:text>
       
  1924     <xsl:text>            if(cached_val != undefined)
       
  1925 </xsl:text>
       
  1926     <xsl:text>                dispatch_value_to_widget(widget, realindex, cached_val, cached_val);
       
  1927 </xsl:text>
       
  1928     <xsl:text>        }
       
  1929 </xsl:text>
       
  1930     <xsl:text>    }
       
  1931 </xsl:text>
       
  1932     <xsl:text>    current_visible_page_index = current_subscribed_page_index;
       
  1933 </xsl:text>
       
  1934     <xsl:text>}
       
  1935 </xsl:text>
       
  1936     <xsl:text>
       
  1937 </xsl:text>
       
  1938     <xsl:text>
       
  1939 </xsl:text>
       
  1940     <xsl:text>
       
  1941 </xsl:text>
       
  1942     <xsl:text>// Once connection established
       
  1943 </xsl:text>
       
  1944     <xsl:text>ws.onopen = function (evt) {
       
  1945 </xsl:text>
       
  1946     <xsl:text>    init_widgets();
       
  1947 </xsl:text>
       
  1948     <xsl:text>    send_reset();
       
  1949 </xsl:text>
       
  1950     <xsl:text>    // show main page
       
  1951 </xsl:text>
       
  1952     <xsl:text>    prepare_svg();
       
  1953 </xsl:text>
       
  1954     <xsl:text>    switch_page(default_page);
  1699 </xsl:text>
  1955 </xsl:text>
  1700     <xsl:text>};
  1956     <xsl:text>};
  1701 </xsl:text>
  1957 </xsl:text>
  1702     <xsl:text>
  1958     <xsl:text>
  1703 </xsl:text>
  1959 </xsl:text>
  1704     <xsl:text>function unsubscribe(){
  1960     <xsl:text>ws.onclose = function (evt) {
  1705 </xsl:text>
  1961 </xsl:text>
  1706     <xsl:text>    widget = this;
  1962     <xsl:text>    // TODO : add visible notification while waiting for reload
  1707 </xsl:text>
  1963 </xsl:text>
  1708     <xsl:text>    /* remove subsribers */
  1964     <xsl:text>    console.log("Connection closed. code:"+evt.code+" reason:"+evt.reason+" wasClean:"+evt.wasClean+" Reload in 10s.");
  1709 </xsl:text>
  1965 </xsl:text>
  1710     <xsl:text>    for(let index of widget.indexes){
  1966     <xsl:text>    // TODO : re-enable auto reload when not in debug
  1711 </xsl:text>
  1967 </xsl:text>
  1712     <xsl:text>        let idx = index + widget.offset;
  1968     <xsl:text>    //window.setTimeout(() =&gt; location.reload(true), 10000);
  1713 </xsl:text>
  1969 </xsl:text>
  1714     <xsl:text>        subscribers[idx].delete(widget);
  1970     <xsl:text>    alert("Connection closed. code:"+evt.code+" reason:"+evt.reason+" wasClean:"+evt.wasClean+".");
  1715 </xsl:text>
  1971 </xsl:text>
  1716     <xsl:text>    }
  1972     <xsl:text>
  1717 </xsl:text>
       
  1718     <xsl:text>    widget.offset = 0;
       
  1719 </xsl:text>
       
  1720     <xsl:text>}
       
  1721 </xsl:text>
       
  1722     <xsl:text>
       
  1723 </xsl:text>
       
  1724     <xsl:text>function subscribe(new_offset=0){
       
  1725 </xsl:text>
       
  1726     <xsl:text>    widget = this;
       
  1727 </xsl:text>
       
  1728     <xsl:text>    /* set the offset because relative */
       
  1729 </xsl:text>
       
  1730     <xsl:text>    widget.offset = new_offset;
       
  1731 </xsl:text>
       
  1732     <xsl:text>    /* add widget's subsribers */
       
  1733 </xsl:text>
       
  1734     <xsl:text>    for(let index of widget.indexes){
       
  1735 </xsl:text>
       
  1736     <xsl:text>        subscribers[index + new_offset].add(widget);
       
  1737 </xsl:text>
       
  1738     <xsl:text>    }
       
  1739 </xsl:text>
       
  1740     <xsl:text>}
       
  1741 </xsl:text>
       
  1742     <xsl:text>
       
  1743 </xsl:text>
       
  1744     <xsl:text>function switch_subscribed_page(page_name, page_index) {
       
  1745 </xsl:text>
       
  1746     <xsl:text>    let old_desc = page_desc[current_subscribed_page];
       
  1747 </xsl:text>
       
  1748     <xsl:text>    let new_desc = page_desc[page_name];
       
  1749 </xsl:text>
       
  1750     <xsl:text>
       
  1751 </xsl:text>
       
  1752     <xsl:text>    if(new_desc == undefined){
       
  1753 </xsl:text>
       
  1754     <xsl:text>        /* TODO LOG ERROR */
       
  1755 </xsl:text>
       
  1756     <xsl:text>        return;
       
  1757 </xsl:text>
       
  1758     <xsl:text>    }
       
  1759 </xsl:text>
       
  1760     <xsl:text>
       
  1761 </xsl:text>
       
  1762     <xsl:text>    if(page_index == undefined){
       
  1763 </xsl:text>
       
  1764     <xsl:text>        page_index = new_desc.page_index;
       
  1765 </xsl:text>
       
  1766     <xsl:text>    }
       
  1767 </xsl:text>
       
  1768     <xsl:text>
       
  1769 </xsl:text>
       
  1770     <xsl:text>    if(old_desc){
       
  1771 </xsl:text>
       
  1772     <xsl:text>        old_desc.absolute_widgets.map(w=&gt;w.unsub());
       
  1773 </xsl:text>
       
  1774     <xsl:text>        old_desc.relative_widgets.map(w=&gt;w.unsub());
       
  1775 </xsl:text>
       
  1776     <xsl:text>    }
       
  1777 </xsl:text>
       
  1778     <xsl:text>    new_desc.absolute_widgets.map(w=&gt;w.sub());
       
  1779 </xsl:text>
       
  1780     <xsl:text>    var new_offset = page_index == undefined ? 0 : page_index - new_desc.page_index;
       
  1781 </xsl:text>
       
  1782     <xsl:text>    new_desc.relative_widgets.map(w=&gt;w.sub(new_offset));
       
  1783 </xsl:text>
       
  1784     <xsl:text>
       
  1785 </xsl:text>
       
  1786     <xsl:text>    update_subscriptions();
       
  1787 </xsl:text>
       
  1788     <xsl:text>
       
  1789 </xsl:text>
       
  1790     <xsl:text>    current_subscribed_page = page_name;
       
  1791 </xsl:text>
       
  1792     <xsl:text>
       
  1793 </xsl:text>
       
  1794     <xsl:text>    requestHMIAnimation();
       
  1795 </xsl:text>
       
  1796     <xsl:text>}
       
  1797 </xsl:text>
       
  1798     <xsl:text>
       
  1799 </xsl:text>
       
  1800     <xsl:text>function switch_visible_page(page_name) {
       
  1801 </xsl:text>
       
  1802     <xsl:text>
       
  1803 </xsl:text>
       
  1804     <xsl:text>    let old_desc = page_desc[current_visible_page];
       
  1805 </xsl:text>
       
  1806     <xsl:text>    let new_desc = page_desc[page_name];
       
  1807 </xsl:text>
       
  1808     <xsl:text>
       
  1809 </xsl:text>
       
  1810     <xsl:text>    if(old_desc){
       
  1811 </xsl:text>
       
  1812     <xsl:text>        for(let eltid in old_desc.required_detachables){
       
  1813 </xsl:text>
       
  1814     <xsl:text>            if(!(eltid in new_desc.required_detachables)){
       
  1815 </xsl:text>
       
  1816     <xsl:text>                let [element, parent] = old_desc.required_detachables[eltid];
       
  1817 </xsl:text>
       
  1818     <xsl:text>                parent.removeChild(element);
       
  1819 </xsl:text>
       
  1820     <xsl:text>            }
       
  1821 </xsl:text>
       
  1822     <xsl:text>        }
       
  1823 </xsl:text>
       
  1824     <xsl:text>        for(let eltid in new_desc.required_detachables){
       
  1825 </xsl:text>
       
  1826     <xsl:text>            if(!(eltid in old_desc.required_detachables)){
       
  1827 </xsl:text>
       
  1828     <xsl:text>                let [element, parent] = new_desc.required_detachables[eltid];
       
  1829 </xsl:text>
       
  1830     <xsl:text>                parent.appendChild(element);
       
  1831 </xsl:text>
       
  1832     <xsl:text>            }
       
  1833 </xsl:text>
       
  1834     <xsl:text>        }
       
  1835 </xsl:text>
       
  1836     <xsl:text>    }else{
       
  1837 </xsl:text>
       
  1838     <xsl:text>        for(let eltid in new_desc.required_detachables){
       
  1839 </xsl:text>
       
  1840     <xsl:text>            let [element, parent] = new_desc.required_detachables[eltid];
       
  1841 </xsl:text>
       
  1842     <xsl:text>            parent.appendChild(element);
       
  1843 </xsl:text>
       
  1844     <xsl:text>        }
       
  1845 </xsl:text>
       
  1846     <xsl:text>    }
       
  1847 </xsl:text>
       
  1848     <xsl:text>
       
  1849 </xsl:text>
       
  1850     <xsl:text>    for(let widget of chain(new_desc.absolute_widgets,new_desc.relative_widgets)){
       
  1851 </xsl:text>
       
  1852     <xsl:text>        for(let index of widget.indexes){
       
  1853 </xsl:text>
       
  1854     <xsl:text>            /* dispatch current cache in newly opened page widgets */
       
  1855 </xsl:text>
       
  1856     <xsl:text>            let cached_val = cache[index];
       
  1857 </xsl:text>
       
  1858     <xsl:text>            if(cached_val != undefined)
       
  1859 </xsl:text>
       
  1860     <xsl:text>                dispatch_value_to_widget(widget, index, cached_val, cached_val);
       
  1861 </xsl:text>
       
  1862     <xsl:text>        }
       
  1863 </xsl:text>
       
  1864     <xsl:text>    }
       
  1865 </xsl:text>
       
  1866     <xsl:text>
       
  1867 </xsl:text>
       
  1868     <xsl:text>    svg_root.setAttribute('viewBox',new_desc.bbox.join(" "));
       
  1869 </xsl:text>
       
  1870     <xsl:text>    current_visible_page = page_name;
       
  1871 </xsl:text>
  1973 </xsl:text>
  1872     <xsl:text>};
  1974     <xsl:text>};
  1873 </xsl:text>
  1975 </xsl:text>
  1874     <xsl:text>
       
  1875 </xsl:text>
       
  1876     <xsl:text>
       
  1877 </xsl:text>
       
  1878     <xsl:text>// Once connection established
       
  1879 </xsl:text>
       
  1880     <xsl:text>ws.onopen = function (evt) {
       
  1881 </xsl:text>
       
  1882     <xsl:text>    init_widgets();
       
  1883 </xsl:text>
       
  1884     <xsl:text>    send_reset();
       
  1885 </xsl:text>
       
  1886     <xsl:text>    // show main page
       
  1887 </xsl:text>
       
  1888     <xsl:text>    prepare_svg();
       
  1889 </xsl:text>
       
  1890     <xsl:text>    switch_page(default_page);
       
  1891 </xsl:text>
       
  1892     <xsl:text>};
       
  1893 </xsl:text>
       
  1894     <xsl:text>
       
  1895 </xsl:text>
       
  1896     <xsl:text>ws.onclose = function (evt) {
       
  1897 </xsl:text>
       
  1898     <xsl:text>    // TODO : add visible notification while waiting for reload
       
  1899 </xsl:text>
       
  1900     <xsl:text>    console.log("Connection closed. code:"+evt.code+" reason:"+evt.reason+" wasClean:"+evt.wasClean+" Reload in 10s.");
       
  1901 </xsl:text>
       
  1902     <xsl:text>    // TODO : re-enable auto reload when not in debug
       
  1903 </xsl:text>
       
  1904     <xsl:text>    //window.setTimeout(() =&gt; location.reload(true), 10000);
       
  1905 </xsl:text>
       
  1906     <xsl:text>    alert("Connection closed. code:"+evt.code+" reason:"+evt.reason+" wasClean:"+evt.wasClean+".");
       
  1907 </xsl:text>
       
  1908     <xsl:text>
       
  1909 </xsl:text>
       
  1910     <xsl:text>};
       
  1911 </xsl:text>
       
  1912   </xsl:template>
  1976   </xsl:template>
  1913 </xsl:stylesheet>
  1977 </xsl:stylesheet>