From 9812bc852452b60e8f2c597443c2881fcb1cdd4d Mon Sep 17 00:00:00 2001 From: Francois Prunayre Date: Wed, 27 Jul 2016 17:08:26 +0200 Subject: [PATCH] Editor / After adding an element with cardinality 0..1, add action is still available (see https://github.com/geonetwork/core-geonetwork/issues/1636) --- .../metadatamanager/EditorService.js | 22 +++++++++++++--- .../webapp/xslt/ui-metadata/edit/edit.xsl | 2 +- .../webapp/xslt/ui-metadata/form-builder.xsl | 25 +++++++++++++++++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/web-ui/src/main/resources/catalog/components/metadatamanager/EditorService.js b/web-ui/src/main/resources/catalog/components/metadatamanager/EditorService.js index 0d8a163611..9156bf240d 100644 --- a/web-ui/src/main/resources/catalog/components/metadatamanager/EditorService.js +++ b/web-ui/src/main/resources/catalog/components/metadatamanager/EditorService.js @@ -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 @@ -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); @@ -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); @@ -410,7 +426,7 @@ } }; - // Adapt the move element + checkAddControls(target.get(0), true); checkMoveControls(target.get(0)); target.slideUp(duration, function() { $(this).remove();}); diff --git a/web/src/main/webapp/xslt/ui-metadata/edit/edit.xsl b/web/src/main/webapp/xslt/ui-metadata/edit/edit.xsl index d8cce343be..63885d7c59 100644 --- a/web/src/main/webapp/xslt/ui-metadata/edit/edit.xsl +++ b/web/src/main/webapp/xslt/ui-metadata/edit/edit.xsl @@ -10,7 +10,7 @@ extension-element-prefixes="saxon" exclude-result-prefixes="#all"> + + + + + + + + + + + + + @@ -624,6 +641,9 @@ + + + @@ -633,8 +653,9 @@ -