Skip to content

Commit

Permalink
Editor / After adding an element with cardinality 0..1, add action is…
Browse files Browse the repository at this point in the history
… still available (see geonetwork/core-geonetwork#1636)
  • Loading branch information
fxprunayre authored and pmauduit committed Sep 8, 2016
1 parent e8b917c commit f52a90e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@
}
}
};
// When adding a new element and the cardinality is 0-1,
// then hide the add control.
// When an element is removed and the cardinality is 0-1,
// then display the add control
var checkAddControls = function(element, isRemoved) {
var addElement = $(element).next();
if (addElement !== undefined) {
var addBlock = addElement.get(0);
if ($(addBlock).hasClass('gn-add-field') &&
$(addBlock).attr('data-gn-cardinality') === '0-1') {
$(addBlock).toggleClass('hidden', isRemoved ? false : true);
}
}
};

// When adding a new element, the down control
// of the previous element must be enabled and
// the up control enabled only if the previous
Expand Down Expand Up @@ -316,7 +331,8 @@
target[position || 'after'](snippet); // Insert
snippet.slideDown(duration, function() {}); // Slide

// Adapt the move element
// Adapt the add & move element
checkAddControls(snippet);
checkMoveControls(snippet);
}
$compile(snippet)(gnCurrentEdit.formScope);
Expand Down Expand Up @@ -347,7 +363,7 @@
target[position || 'before'](snippet); // Insert
snippet.slideDown(duration, function() {}); // Slide

// Adapt the move element
checkAddControls(snippet);
checkMoveControls(snippet);

$compile(snippet)(gnCurrentEdit.formScope);
Expand Down Expand Up @@ -410,7 +426,7 @@
}
};

// Adapt the move element
checkAddControls(target.get(0), true);
checkMoveControls(target.get(0));

target.slideUp(duration, function() { $(this).remove();});
Expand Down
2 changes: 1 addition & 1 deletion web/src/main/webapp/xslt/ui-metadata/edit/edit.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
extension-element-prefixes="saxon" exclude-result-prefixes="#all">

<!-- The editor form.
The form is built from the processing of the metadocument. The metadocument
is composed of the source metadata record and the schema information.
Expand Down
25 changes: 23 additions & 2 deletions web/src/main/webapp/xslt/ui-metadata/form-builder.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@
</xsl:otherwise>
</xsl:choose>

<!-- When building the form with an element having cardinality 0..1,
add a hidden add action in case the element is removed. If removed,
the client app take care of displaying this control. -->
<xsl:if test="$service = 'md.edit' and $parentEditInfo/@min = 0 and $parentEditInfo/@max = 1">
<xsl:variable name="directive" select="gn-fn-metadata:getFieldAddDirective($editorConfig, name())"/>

<xsl:call-template name="render-element-to-add">
<xsl:with-param name="label"
select="gn-fn-metadata:getLabel($schema, name(.), $labels, name(..), '', '')/label"/>
<xsl:with-param name="directive" select="$directive"/>
<xsl:with-param name="childEditInfo" select="$parentEditInfo"/>
<xsl:with-param name="parentEditInfo" select="../gn:element"/>
<xsl:with-param name="isFirst" select="false()"/>
<xsl:with-param name="isHidden" select="true()"/>
<xsl:with-param name="name" select="name()"/>
</xsl:call-template>
</xsl:if>
</xsl:template>


Expand Down Expand Up @@ -624,6 +641,9 @@
<!-- Hide add element if child of an XLink section. -->
<xsl:param name="isDisabled" select="ancestor::node()[@xlink:href]"/>
<xsl:param name="isFirst" required="no" as="xs:boolean" select="true()"/>
<xsl:param name="isHidden" required="no" as="xs:boolean" select="false()"/>
<xsl:param name="name" required="no" as="xs:string" select="''"/>

<xsl:variable name="isCitedResponsiblePartySimpleView"
select="$currTab = 'default' and name() = 'geonet:child' and @name='citedResponsibleParty'"/>
<xsl:if test="not($isDisabled) and not($isCitedResponsiblePartySimpleView)">
Expand All @@ -633,8 +653,9 @@

<!-- This element is replaced by the content received when clicking add -->
<!-- GEOCAT -->
<div class="form-group gn-field {concat('gn-', substring-after($qualifiedName, ':'))} {if ($isRequired) then 'gn-required' else ''} gn-add-field"
<div class="form-group gn-field {concat('gn-', substring-after($qualifiedName, ':'))} {if ($isRequired) then 'gn-required' else ''} gn-add-field {if ($isHidden) then 'hidden' else ''}"
id="gn-el-{$id}"
data-gn-cardinality="{$childEditInfo/@min}-{$childEditInfo/@max}"
data-gn-field-highlight="">
<label class="col-sm-2 control-label"
data-gn-field-tooltip="{$schema}|{$qualifiedName}|{name(..)}|">
Expand Down Expand Up @@ -717,7 +738,7 @@
</xsl:when>
<xsl:otherwise>
<a class="btn btn-default"
data-gn-click-and-spin="add({$parentEditInfo/@ref}, '{concat(@prefix, ':', @name)}', '{$id}', 'before');">
data-gn-click-and-spin="add({$parentEditInfo/@ref}, '{if ($name != '') then $name else concat(@prefix, ':', @name)}', '{$id}', 'before');">
<i class="fa fa-plus gn-add"/>
</a>
</xsl:otherwise>
Expand Down

0 comments on commit f52a90e

Please sign in to comment.