<commit_before>

lizMap.events.on({

    'lizmappopupdisplayed': function(){

        if( !('qgisServerPlugins' in lizMap.config) )
            return;
        if( !('atlasprint' in lizMap.config.qgisServerPlugins) )
            return;
        if( !('printTemplates' in lizMap.config) || lizMap.config.printTemplates.length == 0)
            return;

        $('div.lizmapPopupDiv').each(function(){
            if($(this).find('a.lizmap-atlasprint-link').length == 0){
                var getLayerId = $(this).find('input.lizmap-popup-layer-feature-id:first').val().split('.');
                var layerId = getLayerId[0];
                var fid = getLayerId[1];
                var layerName=getLayerId[0].split(/[0-9]/)[0];

                for(var i in lizMap.config.printTemplates){
                    var t = lizMap.config.printTemplates[i];
                    if('atlas' in t){
                        if(layerId == t.atlas.coverageLayer){
                            // Build URL
                            var url = OpenLayers.Util.urlAppend(
                                lizUrls.wms,
                                OpenLayers.Util.getParameterString(lizUrls.params)
                            );
                            url += '&SERVICE=WMS';
                            url += '&VERSION=1.3.0&REQUEST=GetPrintAtlas';
                            url += '&FORMAT=pdf';
                            url += '&EXCEPTIONS=application/vnd.ogc.se_inimage&TRANSPARENT=true';
                            url += '&DPI=100';
                            url += '&TEMPLATE='+t.title;
                            url += '&LAYER='+layerName;
                            url += '&EXP_FILTER=$id IN ('+fid+')';

                            // Add button and div to set custom labels
                            let customLabels = '';

                            const protectedLabelsId = ["lizmap_user", "lizmap_user_groups"];
                            for(const label of t.labels){
                                if (protectedLabelsId.includes(label.id)){
                                    // These values mustn't be shown in the UI and will be overridden by LWC PHP and AtlasPrint anyway
                                    continue;
                                }
                                if (label.htmlState){
                                    customLabels += `<textarea class="atlasprint-custom-labels" cols="15" data-print-id="${label.id}" name="${label.id}" placeholder="${label.text}">${label.text}</textarea>`;
                                }else{
                                    customLabels += `<input type="text" class="atlasprint-custom-labels" size="15" data-print-id="${label.id}" name="${label.id}" placeholder="${label.text}" value="${label.text}">`;
                                }
                            }

                            // Create custom labels tool if any custom labels have been defined
                            const customLabelsTool = (customLabels === '') ? '' : `<div class="toggle-custom-labels-view"><button><i class="icon-cog" title="${lizDict['print.customLabels.tooltip']}"></i></button><div>${customLabels}</div></div>`;

                            $(this).append('<a class="lizmap-atlasprint-link" data-href="' + url + '" href="' + url + '" target="_blank" title="' + lizDict['attributeLayers.toolbar.btn.data.export.title'] + ' ' + t.title + '"><span class="icon"></span>' + t.title + '</a>' + customLabelsTool + '<br>');

                            // Activate toggle on custom labels button
                            $('.toggle-custom-labels-view > button').click(function () {
                                $(this).next().toggle();
                            });

                            // Activate URL rewrite when user modify custom labels value
                            $('.atlasprint-custom-labels').on('input', function(){
                                const atlasPrintLink = $(this).parents('.toggle-custom-labels-view').prev();

                                let customLabelsParams = '';

                                $('.atlasprint-custom-labels').each(function(){
                                    customLabelsParams += '&' + $(this).data('print-id') + '=' + encodeURIComponent($(this).val());
                                });

                                atlasPrintLink.attr('href', atlasPrintLink.data('href') + customLabelsParams);
                            });

                            // Add tooltips
                            $(this).find('a.lizmap-atlasprint-link, .toggle-custom-labels-view button i').tooltip();
                        }
                    }
                }
            }
        });
    }
});<commit_msg>Refactoring popupQgisAtlas.js when adding atlas link in the popup<commit_after>

lizMap.events.on({

    'lizmappopupdisplayed': function(){

        if( !('qgisServerPlugins' in lizMap.config) )
            return;
        if( !('atlasprint' in lizMap.config.qgisServerPlugins) )
            return;
        if( !('printTemplates' in lizMap.config) || lizMap.config.printTemplates.length == 0)
            return;

        $('div.lizmapPopupDiv').each(function(){
            if($(this).find('a.lizmap-atlasprint-link').length != 0) {
                // Atlas print link already exist
                return true;
            }

            var getLayerId = $(this).find('input.lizmap-popup-layer-feature-id:first').val().split('.');
            var layerId = getLayerId[0];
            var fid = getLayerId[1];
            var layerName=getLayerId[0].split(/[0-9]/)[0];

            for(var i in lizMap.config.printTemplates){
                var t = lizMap.config.printTemplates[i];
                if('atlas' in t){
                    if(layerId == t.atlas.coverageLayer){
                        // Build URL
                        var url = OpenLayers.Util.urlAppend(
                            lizUrls.wms,
                            OpenLayers.Util.getParameterString(lizUrls.params)
                        );
                        url += '&SERVICE=WMS';
                        url += '&VERSION=1.3.0&REQUEST=GetPrintAtlas';
                        url += '&FORMAT=pdf';
                        url += '&EXCEPTIONS=application/vnd.ogc.se_inimage&TRANSPARENT=true';
                        url += '&DPI=100';
                        url += '&TEMPLATE='+t.title;
                        url += '&LAYER='+layerName;
                        url += '&EXP_FILTER=$id IN ('+fid+')';

                        // Add button and div to set custom labels
                        let customLabels = '';

                        const protectedLabelsId = ["lizmap_user", "lizmap_user_groups"];
                        for(const label of t.labels){
                            if (protectedLabelsId.includes(label.id)){
                                // These values mustn't be shown in the UI and will be overridden by LWC PHP and AtlasPrint anyway
                                continue;
                            }
                            if (label.htmlState){
                                customLabels += `<textarea class="atlasprint-custom-labels" cols="15" data-print-id="${label.id}" name="${label.id}" placeholder="${label.text}">${label.text}</textarea>`;
                            }else{
                                customLabels += `<input type="text" class="atlasprint-custom-labels" size="15" data-print-id="${label.id}" name="${label.id}" placeholder="${label.text}" value="${label.text}">`;
                            }
                        }

                        // Create custom labels tool if any custom labels have been defined
                        const customLabelsTool = (customLabels === '') ? '' : `<div class="toggle-custom-labels-view"><button><i class="icon-cog" title="${lizDict['print.customLabels.tooltip']}"></i></button><div>${customLabels}</div></div>`;

                        $(this).append('<a class="lizmap-atlasprint-link" data-href="' + url + '" href="' + url + '" target="_blank" title="' + lizDict['attributeLayers.toolbar.btn.data.export.title'] + ' ' + t.title + '"><span class="icon"></span>' + t.title + '</a>' + customLabelsTool + '<br>');

                        // Activate toggle on custom labels button
                        $('.toggle-custom-labels-view > button').click(function () {
                            $(this).next().toggle();
                        });

                        // Activate URL rewrite when user modify custom labels value
                        $('.atlasprint-custom-labels').on('input', function(){
                            const atlasPrintLink = $(this).parents('.toggle-custom-labels-view').prev();

                            let customLabelsParams = '';

                            $('.atlasprint-custom-labels').each(function(){
                                customLabelsParams += '&' + $(this).data('print-id') + '=' + encodeURIComponent($(this).val());
                            });

                            atlasPrintLink.attr('href', atlasPrintLink.data('href') + customLabelsParams);
                        });

                        // Add tooltips
                        $(this).find('a.lizmap-atlasprint-link, .toggle-custom-labels-view button i').tooltip();
                    }
                }
            }
        });
    }
});
{'fraction_non_alphanumeric': 0.14217708663916218, 'fraction_numerical': 0.003808314820691844, 'mean_word_length': 1.3459057071960299, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7234166', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2359, 'n_words': 419}