root/main/trunk/greenstone3/web/interfaces/default/transform/javascript-global-setup.xsl @ 26498

Revision 26498, 12.1 KB (checked in by sjm84, 8 years ago)

Document metadata in on the classifier page is now stored in the gs variable

  • Property svn:executable set to *
Line 
1<xsl:stylesheet version="1.0"
2    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3    xmlns:java="http://xml.apache.org/xslt/java"
4    xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
5    xmlns:gslib="http://www.greenstone.org/skinning"
6    extension-element-prefixes="java util"
7    exclude-result-prefixes="java util">
8   
9    <xsl:template name="setup-gs-variable">
10        <script type="text/javascript">
11            gs = new Array();
12            gs.cgiParams = new Array();
13            gs.xsltParams = new Array();
14            gs.siteMetadata = new Array();
15            gs.collectionMetadata = new Array();
16            gs.documentMetadata = new Array();
17            gs.imageURLs = new Array();
18            gs.variables = new Array();
19            gs.requestInformation = new Array();
20        </script>
21        <xsl:call-template name="populate-cgi-param-values"/>
22        <xsl:call-template name="populate-xslt-param-values"/>
23        <xsl:call-template name="populate-image-url-values"/>
24        <xsl:call-template name="populate-metadata-values"/>
25        <xsl:call-template name="populate-request-information-values"/>
26        <xsl:call-template name="include-global-javascript-functions"/>
27    </xsl:template>
28   
29    <xsl:template name="populate-cgi-param-values">
30        <script type="text/javascript">
31            var name;
32            var value;
33            <xsl:for-each select="/page/pageRequest/paramList/param">
34                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
35                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of select="util:escapeNewLinesAndQuotes(@value)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
36                <xsl:text disable-output-escaping="yes">name = name.replace(".", "_");</xsl:text>
37                gs.cgiParams[name] = value;
38            </xsl:for-each>
39        </script>
40    </xsl:template>
41   
42    <xsl:template name="populate-xslt-param-values">
43        <script type="text/javascript">
44            <xsl:text disable-output-escaping="yes">gs.xsltParams.library_name = "</xsl:text><xsl:value-of select="$library_name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
45            <xsl:text disable-output-escaping="yes">gs.xsltParams.interface_name = "</xsl:text><xsl:value-of select="$interface_name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
46            <xsl:text disable-output-escaping="yes">gs.xsltParams.site_name = "</xsl:text><xsl:value-of select="$site_name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
47        </script>
48    </xsl:template>
49   
50    <xsl:template name="populate-metadata-values">
51        <script type="text/javascript">
52            <xsl:text disable-output-escaping="yes">
53                function addMetadataToList(name, value, list, lang)
54                {
55                    name = name.replace(".", "_");
56                    if(lang == "" || lang == "en")
57                    {
58                        list[name] = value;
59                    }
60                    else
61                    {
62                        if (list[lang] == undefined)
63                        {
64                            list[lang] = new Array();
65                        }
66                        var langList = list[lang];
67                        langList[name] = value;
68                    }
69                }
70                var name;
71                var value;
72                var lang;
73            </xsl:text>
74            <xsl:for-each select="/page/pageResponse/metadataList/metadata">
75                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
76                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="util:escapeNewLinesAndQuotes(.)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
77                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
78                addMetadataToList(name, value, gs.siteMetadata, lang);
79            </xsl:for-each>
80       
81            <xsl:for-each select="/page/pageResponse/collection/metadataList/metadata">
82                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
83                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="util:escapeNewLinesAndQuotes(.)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
84                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
85                addMetadataToList(name, value, gs.collectionMetadata, lang);
86            </xsl:for-each>
87       
88            <xsl:for-each select="/page/pageResponse/document/metadataList/metadata">
89                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
90                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="util:escapeNewLinesAndQuotes(.)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
91                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
92                addMetadataToList(name, value, gs.documentMetadata, lang);
93            </xsl:for-each>
94           
95            <xsl:for-each select="/page/pageResponse/classifier/documentNode">
96                {
97                <xsl:text disable-output-escaping="yes">var nodeID = "</xsl:text><xsl:value-of select="@nodeID"/><xsl:text disable-output-escaping="yes">";</xsl:text>
98                <xsl:text disable-output-escaping="yes">var emptyLang = "";</xsl:text>
99                <xsl:text disable-output-escaping="yes">var metaList = new Array();</xsl:text>
100                <xsl:for-each select="metadataList/metadata">
101                    <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
102                    <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="util:escapeNewLinesAndQuotes(.)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
103                    <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
104                    addMetadataToList(name, value, metaList, lang);
105                </xsl:for-each>
106                addMetadataToList(nodeID, metaList, gs.documentMetadata, emptyLang);
107                }
108            </xsl:for-each>
109           
110            <xsl:text disable-output-escaping="yes">addMetadataToList("docType", "</xsl:text><xsl:value-of select="/page/pageResponse/document/@docType"/><xsl:text disable-output-escaping="yes">", gs.documentMetadata, "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">");</xsl:text>
111        </script>
112    </xsl:template>
113   
114    <xsl:template name="populate-image-url-values">
115        <script type="text/javascript">
116            <xsl:text disable-output-escaping="yes">gs.imageURLs.expand = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'expand_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
117            <xsl:text disable-output-escaping="yes">gs.imageURLs.collapse = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'collapse_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
118            <xsl:text disable-output-escaping="yes">gs.imageURLs.page = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
119            <xsl:text disable-output-escaping="yes">gs.imageURLs.chapter = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'chapter_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
120            <xsl:text disable-output-escaping="yes">gs.imageURLs.realisticBook = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'realistic_books_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
121            <xsl:text disable-output-escaping="yes">gs.imageURLs.highlight = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'highlight_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
122            <xsl:text disable-output-escaping="yes">gs.imageURLs.bookshelf = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
123            <xsl:text disable-output-escaping="yes">gs.imageURLs.book = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
124            <xsl:text disable-output-escaping="yes">gs.imageURLs.loading = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'loading_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
125            <xsl:text disable-output-escaping="yes">gs.imageURLs.pageIcon = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
126            <xsl:text disable-output-escaping="yes">gs.imageURLs.trashFull = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'trash_full_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
127            <xsl:text disable-output-escaping="yes">gs.imageURLs.blank = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'blank_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
128            <xsl:text disable-output-escaping="yes">gs.imageURLs.next = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'next_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
129            <xsl:text disable-output-escaping="yes">gs.imageURLs.prev = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'prev_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
130        </script>
131    </xsl:template>
132   
133    <xsl:template name="populate-request-information-values">
134        <script type="text/javascript">
135            <xsl:text disable-output-escaping="yes">
136                gs.requestInformation.fullURL = "</xsl:text><xsl:value-of select="/page/pageRequest/@fullURL"/><xsl:text disable-output-escaping="yes">";
137            </xsl:text>
138        </script>
139    </xsl:template>
140   
141    <xsl:template name="include-global-javascript-functions">
142        <script type="text/javascript" src="interfaces/default/js/javascript-global-functions.js"><xsl:text> </xsl:text></script>
143        <script type="text/javascript" src="interfaces/default/js/GSMetadata.js"><xsl:text> </xsl:text></script>
144    </xsl:template>
145</xsl:stylesheet>
146
147    <!-- CAN WE FIND SOME WAY TO MAKE THIS WORK?
148    <xsl:call-template name="populate-metadata-values">
149        <xsl:with-param name="path">/page/pageResponse/metadataList/metadata</xsl:with-param>
150        <xsl:with-param name="metadataListName">siteMetadata</xsl:with-param>
151    </xsl:call-template>
152   
153    <xsl:call-template name="populate-metadata-values">
154        <xsl:with-param name="path">/page/pageResponse/collection/metadataList/metadata</xsl:with-param>
155        <xsl:with-param name="metadataListName">collectionMetadata</xsl:with-param>
156    </xsl:call-template>
157   
158    <xsl:call-template name="populate-metadata-values">
159        <xsl:with-param name="path">/page/pageResponse/document/metadataList/metadata</xsl:with-param>
160        <xsl:with-param name="metadataListName">documentMetadata</xsl:with-param>
161    </xsl:call-template>
162    -->
163
164    <!-- NOT WORKING BUT IT WOULD BE TIDIER IF IT DID
165    <xsl:template name="populate-metadata-values">
166        <xsl:param name="path"/>
167        <xsl:param name="metadataListName"/>
168       
169        <xsl:for-each select="$path">
170            <script type="text/javascript">
171                <xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
172                <xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
173                <xsl:text disable-output-escaping="yes">var lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
174                <xsl:text disable-output-escaping="yes">var metadataListName = "</xsl:text><xsl:value-of select="$metadataListName"/><xsl:text disable-output-escaping="yes">";</xsl:text>
175                var list = gs[metadataListName];
176                if(lang == "")
177                {
178                    list[name] = value;
179                }
180                else
181                {
182                    if (list[lang] == undefined)
183                    {
184                        list[lang] = new Array();
185                    }
186                    var langList = list[lang];
187                    langList[name] = value;
188                }
189            </script>
190        </xsl:for-each>
191    </xsl:template>
192    -->
Note: See TracBrowser for help on using the browser.