diff --git a/assets/src/legacy/attributeTable.js b/assets/src/legacy/attributeTable.js
index 81b3374ea1..efa3a14adc 100644
--- a/assets/src/legacy/attributeTable.js
+++ b/assets/src/legacy/attributeTable.js
@@ -574,12 +574,15 @@ var lizAttributeTable = function() {
// Create button
var canCreate = false;
- if( 'editionLayers' in config && cleanName in config.editionLayers ) {
+ if ('editionLayers' in config
+ && cleanName in attributeLayersDic
+ && attributeLayersDic[cleanName] in config.editionLayers) {
var al = config.editionLayers[attributeLayersDic[cleanName]];
- if( al.capabilities.createFeature == "True" )
+ if (al.capabilities.createFeature == "True") {
canCreate = true;
+ }
}
- if( canCreate ){
+ if (canCreate) {
html+= ' ';
}
@@ -634,8 +637,9 @@ var lizAttributeTable = function() {
html+= ''; // attribute-layer-action-bar
- if( childHtml )
+ if( childHtml ) {
alc= ' showChildren';
+ }
html+= '
';
html+= '
';
html+= '
';
@@ -830,22 +834,34 @@ var lizAttributeTable = function() {
});
// Bind click on createFeature button
+ // BEWARE - This is used for creating a new line in the displayed attribute table
+ // and for creating a new child item
$('#attribute-layer-'+ cleanName + ' button.btn-createFeature-attributeTable')
.click(function(){
- if ( $('#attribute-layer-'+ cleanName + ' tr.active').length != 1) {
+ // Ask the user to click on a table line
+ // before trying to create a child feature
+ const creationContext = ($(this).hasClass('new-child')) ? 'child' : 'parent';
+ if (creationContext == 'child'
+ && $('#attribute-layer-'+ cleanName + ' tr.active').length != 1) {
$('#lizmap-edition-message').remove();
lizMap.addMessage( lizDict['attributeLayers.toolbar.btn.data.createChildFeature.no.actived'], 'info', true).attr('id','lizmap-edition-message');
return false;
}
- var parentFeatId = document.querySelector('#attribute-layer-'+ cleanName + ' tr.active lizmap-feature-toolbar').fid;
+ const parentFidElement = document.querySelector('#attribute-layer-'+ cleanName + ' tr.active lizmap-feature-toolbar');
+ var parentFeatId = (parentFidElement) ? parentFidElement.fid : null;
var parentLayerName = attributeLayersDic[ cleanName ];
var parentLayerId = config.layers[parentLayerName]['id'];
var aName = attributeLayersDic[ $(this).val() ];
var pivotId = $(this).attr("data-pivot");
- lizMap.getLayerFeature(parentLayerName, parentFeatId, function(parentFeat) {
- var lid = config.layers[aName]['id'];
- lizMap.launchEdition( lid, null, {layerId:parentLayerId, feature:parentFeat, pivotId:pivotId});
- });
+ var lid = config.layers[aName]['id'];
+ if (creationContext == 'parent') {
+ lizMap.launchEdition( lid, null, null);
+ } else {
+ lizMap.getLayerFeature(parentLayerName, parentFeatId, function(parentFeat) {
+ lizMap.launchEdition( lid, null, {layerId:parentLayerId, feature:parentFeat, pivotId:pivotId});
+ });
+ }
+
return false;
})
.hover(
@@ -1126,11 +1142,12 @@ var lizAttributeTable = function() {
// Add create child feature button
var canCreateChild = false;
- if( 'editionLayers' in config ){
- if( childLayerName in config.editionLayers ) {
+ if ('editionLayers' in config) {
+ if (childLayerName in config.editionLayers) {
var al = config.editionLayers[childLayerName];
- if( al.capabilities.createFeature == "True" )
+ if (al.capabilities.createFeature == "True") {
canCreateChild = true;
+ }
}
// if the m layer is displayed then check also the edition capabilities on pivot
if(canCreateChild && isNToM){
@@ -1141,7 +1158,7 @@ var lizAttributeTable = function() {
if( canCreateChild ){
// Add a button to create a new feature for this child layer
let childButtonItem = `
-