Skip to content

Commit

Permalink
#1048 ExtJs editor - suggestions in multilingual fields only work wit…
Browse files Browse the repository at this point in the history
…h the main language field
  • Loading branch information
josegar74 committed Jun 29, 2015
1 parent 39eac2c commit f0547db
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 11 deletions.
1 change: 1 addition & 0 deletions web-client/pom.xml
Expand Up @@ -366,6 +366,7 @@
<include>${project.build.directory}/classes/apps/js/GeoNetwork/lib/GeoNetwork/util/SearchFormTools.js</include>
<include>${project.build.directory}/classes/apps/js/GeoNetwork/lib/GeoNetwork/util/LinkTools.js</include>
<include>${project.build.directory}/classes/apps/js/GeoNetwork/lib/GeoNetwork/util/CSWSearchTools.js</include>
<include>${project.build.directory}/classes/apps/js/GeoNetwork/lib/GeoNetwork/util/SuggestionTools.js</include>

<include>${project.build.directory}/classes/apps/js/GeoNetwork/lib/GeoNetwork/data/CatalogueSourceStore.js</include>
<include>${project.build.directory}/classes/apps/js/GeoNetwork/lib/GeoNetwork/data/CategoryStore.js</include>
Expand Down
Expand Up @@ -96,6 +96,7 @@
"GeoNetwork/data/SubTemplateTypeStore.js",
"GeoNetwork/util/HelpTools.js",
"GeoNetwork/util/LinkTools.js",
"GeoNetwork/util/SuggestionTools.js",
"GeoNetwork/data/GroupStore.js",
"GeoNetwork/data/UserStore.js",
"GeoNetwork/data/StatusStore.js",
Expand Down
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2001-2011 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
* Rome - Italy. email: geonetwork@osgeo.org
*/
Ext.namespace("GeoNetwork.util");

/** api: (define)
* module = GeoNetwork.util
* class = SuggestionTools
*/
/** api: example
* SuggestionTools updates the suggestion value in a form field, managing multilingual fields.
*
*
* .. code-block:: javascript
*
* GeoNetwork.util.SuggestionTools.updateSuggestion(suggestion, refId, multilingualRefIds);
*
* ...
*
*/

GeoNetwork.util.SuggestionTools = {
/** api: method[updateSuggestion]
* Updates the visible form field for a metadata element with the suggestion provided. Manages multilingual elements.
*
* :param value: Suggestion value.
* :param refId: Identifier of the field to update.
* :param multilingualRefIds: Comma separated list of identifier of the multilingual
* field for a metadata element to update.
*/
updateSuggestion: function (value, refId, multilingualRefIds) {
var isVisible = (Ext.getDom("_" + refId).style.display != "none");

if (isVisible) {
Ext.getDom("_" + refId).value=value;
if (Ext.getDom("_" + refId).onkeyup) Ext.getDom("_" + refId).onkeyup();
} else {
var relatedIdsList = multilingualRefIds.split(",");
for (var i = 0; i < relatedIdsList.length; i++) {
if (relatedIdsList[i] == '') continue;
var refId = "_" + relatedIdsList[i];
var isVisible = (Ext.getDom(refId).style.display != "none");

if (isVisible) {
Ext.getDom(refId).value=value;
if (Ext.getDom(refId).onkeyup) Ext.getDom(refId).onkeyup();
}

}

}
}
};
50 changes: 39 additions & 11 deletions web/src/main/webapp/xsl/metadata/layout.xsl
Expand Up @@ -1090,9 +1090,22 @@
else parent::node()"></xsl:variable>
<!-- Look for the helper -->
<xsl:variable name="helper" select="if (empty(/root/gui)) then '' else geonet:getHelper($schema, $node, /root/gui)"/>




<!-- For multilingual -->
<xsl:variable name="tmpFreeText">
<xsl:for-each select="$node">
<xsl:call-template name="PT_FreeText_Tree" />
</xsl:for-each>
</xsl:variable>

<xsl:variable name="ptFreeTextTree" select="exslt:node-set($tmpFreeText)" />

<xsl:variable name="relatedIds">
<xsl:for-each select="$ptFreeTextTree//gmd:LocalisedCharacterString[string(@locale)]">
<xsl:value-of select="geonet:element/@ref" /><xsl:if test="position() != last()">,</xsl:if>
</xsl:for-each>
</xsl:variable>

<!-- Display the helper list if found -->
<xsl:if test="normalize-space($helper)!=''">

Expand All @@ -1116,7 +1129,22 @@
select="../following-sibling::node()[name()=$relatedElementName]/gco:CharacterString/geonet:element/@ref"/>
<xsl:variable name="relatedElementIsEmpty" select="normalize-space($relatedElement)=''"/>
<!--<xsl:value-of select="concat('if (Ext.getDom(&quot;_', $relatedElementRef, '&quot;).value===&quot;&quot;) Ext.getDom(&quot;_', $relatedElementRef, '&quot;).value=this.options[this.selectedIndex].title;')"/>-->


<!-- For multilingual -->
<xsl:variable name="tmpFreeTextRelatedElement">
<xsl:for-each select="../following-sibling::node()[name()=$relatedElementName]">
<xsl:call-template name="PT_FreeText_Tree" />
</xsl:for-each>
</xsl:variable>

<xsl:variable name="ptFreeTextTreeRelatedElement" select="exslt:node-set($tmpFreeTextRelatedElement)" />

<xsl:variable name="relatedIdsRelatedElement">
<xsl:for-each select="$ptFreeTextTreeRelatedElement//gmd:LocalisedCharacterString[string(@locale)]">
<xsl:value-of select="geonet:element/@ref" /><xsl:if test="position() != last()">,</xsl:if>
</xsl:for-each>
</xsl:variable>

<xsl:choose>
<!-- Layout with radio button -->
<xsl:when test="contains($mode, 'radio')">
Expand All @@ -1126,7 +1154,7 @@
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="concat('if (Ext.getDom(&quot;_', $relatedElementRef, '&quot;)) Ext.getDom(&quot;_', $relatedElementRef, '&quot;).value=this.options[this.selectedIndex].title;')"
select="concat('GeoNetwork.util.SuggestionTools.updateSuggestion(this.options[this.selectedIndex].title,&quot;', $relatedElementRef, '&quot;,&quot;', $relatedIdsRelatedElement,'&quot;);')"
/>
</xsl:otherwise>
</xsl:choose>
Expand Down Expand Up @@ -1154,9 +1182,9 @@
</xsl:choose>
</xsl:if>
</xsl:variable>




<div class="helper helper-{$mode}">
<xsl:choose>
Expand Down Expand Up @@ -1224,7 +1252,7 @@
<xsl:otherwise>
<xsl:text> </xsl:text> (<xsl:value-of select="/root/gui/strings/helperList"/>
<select id="s_{$refId}" name="s_{$refId}" size="1"
onchange="Ext.getDom('_{$refId}').value=this.options[this.selectedIndex].value; if (Ext.getDom('_{$refId}').onkeyup) Ext.getDom('_{$refId}').onkeyup(); {$relatedElementAction} {$relatedAttributeAction} {$jsAction}"
onchange="GeoNetwork.util.SuggestionTools.updateSuggestion(this.value, '{$refId}', '{$relatedIds}'); {$relatedElementAction} {$relatedAttributeAction} {$jsAction}"
class="md" >
<option/>
<!-- This assume that helper list is already sort in alphabetical order in loc file. -->
Expand Down Expand Up @@ -2080,8 +2108,8 @@
If yes, hide the input text which will be updated when clicking the radio
or the other option. -->
<xsl:variable name="helper" select="if (empty(/root/gui)) then '' else geonet:getHelper($schema, parent::node(), /root/gui)"/>


<input class="md {$class}" type="{$input_type}" value="{text()}">
<xsl:if test="$isXLinked">
<xsl:attribute name="disabled">disabled</xsl:attribute>
Expand Down

0 comments on commit f0547db

Please sign in to comment.