Index: main/plugin-link-directory/pages/services/directory/utils/config_utils.xsl
===================================================================
--- main/plugin-link-directory/pages/services/directory/utils/config_utils.xsl	(revision 0)
+++ main/plugin-link-directory/pages/services/directory/utils/config_utils.xsl	(revision 0)
@@ -0,0 +1,246 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Copyright 2015 Anyware Services
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+   -->
+<xsl:stylesheet version="1.0" 
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:ametys="org.ametys.web.transformation.xslt.AmetysXSLTHelper"
+                xmlns:math="java.lang.Math"
+                xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
+    
+    <!-- Display the configure links button if the service is configurable -->
+    <xsl:template name="display-configure-links-btn-service">    
+        <xsl:param name="height"/>
+        <xsl:param name="width"/>
+        <xsl:param name="maxCheckedLinks"/>
+        
+        
+        <xsl:if test="ametys:serviceParameter('configurable') = 'true'">
+	        <xsl:call-template name="configure-links-btn-and-dialog">
+	            <xsl:with-param name="links" select="/links/link"/>
+	            <xsl:with-param name="height" select="$height"/>
+	            <xsl:with-param name="width" select="$width"/>
+	            <xsl:with-param name="maxCheckedLinks" select="$maxCheckedLinks"/>
+	        </xsl:call-template>                                     
+        </xsl:if>
+    </xsl:template>
+    
+    <!-- Configure links button for a service or an input data -->
+    <xsl:template name="configure-links-btn-and-dialog">
+        <xsl:param name="links"/>
+        <xsl:param name="height" select="32"/>
+        <xsl:param name="width" select="32"/>
+        <xsl:param name="maxCheckedLinks"/>
+        
+        <xsl:variable name="buttonId" select="substring-after(math:random(), '.')"/>
+
+        <script type="text/javascript">
+            
+            <!-- Rendering of the button -->    
+            <xsl:call-template name="configure-links-btn">
+                <xsl:with-param name="height" select="$height"/>
+                <xsl:with-param name="width" select="$width"/>
+                <xsl:with-param name="buttonId" select="$buttonId"/>
+            </xsl:call-template>
+            
+            <!-- Set up the dialog's form -->
+            <xsl:call-template name="configure-links-dialog-and-form">
+                <xsl:with-param name="maxCheckedLinks" select="$maxCheckedLinks"/>
+                <xsl:with-param name="links" select="$links"/>
+                <xsl:with-param name="buttonId" select="$buttonId"/>
+            </xsl:call-template> 
+             
+             <!-- Logic of the button and its dialog -->
+             <xsl:call-template name="configure-links-btn-script">
+                 <xsl:with-param name="maxCheckedLinks" select="$maxCheckedLinks"/>
+                 <xsl:with-param name="buttonId" select="$buttonId"/>
+             </xsl:call-template>
+        
+        </script>
+    </xsl:template>
+    
+    <!-- Default rendering for a service -->
+    <xsl:template name="configure-links-btn">
+        <xsl:param name="height"/>
+        <xsl:param name="width"/>
+        <xsl:param name="buttonId"/>
+        
+        
+        <xsl:choose>
+            <xsl:when test="$rendering-context = 'front' and not(ametys:user())">
+                <!-- The user is not connected: the button is not displayed -->
+            </xsl:when>
+            <xsl:when test="$rendering-context != 'front'">
+                document.writeln("&lt;a id=\"configure-links-hyperlink-<xsl:value-of select="$buttonId"/>-disabled\" class=\"configure-links-service-button\" title=\"<i18n:text i18n:key="PLUGINS_LINKDIRECTORY_CONFIGURE_THUMBNAILS_TITLE_BO" i18n:catalogue="plugin.link-directory"/>\"&gt;<i18n:text i18n:key="PLUGINS_LINKDIRECTORY_CONFIGURE_THUMBNAILS" i18n:catalogue="plugin.link-directory"/>&lt;/a&gt;");
+            </xsl:when>
+            <xsl:otherwise>
+                document.writeln("&lt;a id=\"configure-links-hyperlink-<xsl:value-of select="$buttonId"/>\" class=\"configure-links-service-button\" href=\"javascript:void(0)\" title=\"<i18n:text i18n:key="PLUGINS_LINKDIRECTORY_CONFIGURE_THUMBNAILS_TITLE" i18n:catalogue="plugin.link-directory"/>\" i18n:attr=\"title\"&gt;<i18n:text i18n:key="PLUGINS_LINKDIRECTORY_CONFIGURE_THUMBNAILS" i18n:catalogue="plugin.link-directory"/>&lt;/a&gt;");
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+    
+    <!-- The dialog and the form when clicking the button -->
+    <xsl:template name="configure-links-dialog-and-form"> 
+        <xsl:param name="maxCheckedLinks"/>
+        <xsl:param name="links"/>
+        <xsl:param name="buttonId"/>
+        
+        document.writeln("&lt;div id=\"configure-links-dialog-<xsl:value-of select="$buttonId"/>\" title=\"<i18n:text i18n:key="PLUGINS_LINKDIRECTORY_CONFIGURE_THUMBNAILS_TITLE" i18n:catalogue="plugin.link-directory"/>\" style=\"display:none;\" i18n:attr=\"title\"&gt;");
+           document.writeln("&lt;form id=\"configure-links-form-<xsl:value-of select="$buttonId"/>\"&gt;");
+               document.writeln("&lt;p class=\"configure-links-dialog-text\"&gt;<i18n:translate><i18n:text i18n:key="PLUGINS_LINKDIRECTORY_CONFIGURE_DIALOG_TITLE" i18n:catalogue="plugin.link-directory"/><i18n:param name="maxCheckedLinks"><xsl:value-of select="$maxCheckedLinks"/></i18n:param></i18n:translate>&lt;/p&gt;")               
+               document.writeln("&lt;input type=\"hidden\" id=\"zone-item-id-<xsl:value-of select="$buttonId"/>\" name=\"zone-item-id\" value=\"<xsl:value-of select="@zoneItemId"/>\"&gt;");
+
+               <xsl:for-each select="$links">
+                    <xsl:apply-templates select="." mode="configure-field"/>
+               </xsl:for-each>
+               
+           document.writeln("&lt;/form&gt;");
+        document.writeln("&lt;/div&gt;");
+    </xsl:template>
+    
+    <!-- Configure the checkboxes of the form -->    
+    <xsl:template match="link" mode="configure-field">
+        <xsl:variable name="label">
+            <xsl:choose>
+                <xsl:when test="normalize-space(@title) != ''">
+                    <xsl:value-of select="@title"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="@url"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+        
+        <!-- Is the box checked or not ? -->
+        <xsl:variable name="checked">
+            <xsl:choose>
+	            <xsl:when test="@user-selected = 'true'">
+	                <xsl:text>checked</xsl:text>
+	            </xsl:when>
+	            <xsl:otherwise>
+	            
+	            </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+        
+        document.writeln("&lt;div class=\"field\"&gt;");
+            document.writeln("&lt;input type=\"checkbox\" <xsl:value-of select="$checked"/> data-serverid=\"<xsl:value-of select="@id"/>\"/&gt;");
+            document.writeln("&lt;label for=\"label-<xsl:value-of select="$label"/>\"&gt;");
+                document.writeln("&lt;span&gt;<xsl:value-of select="$label"/>&lt;/span&gt;");
+            document.writeln("&lt;/label&gt;");
+            document.writeln("&lt;div class=\"clearfix\"&gt;&lt;/div&gt;");
+        document.writeln("&lt;/div&gt;");
+    </xsl:template>
+    
+    <!--  Script associated to the configure links button -->
+    <xsl:template name="configure-links-btn-script">
+        <xsl:param name="maxCheckedLinks"/>
+        <xsl:param name="buttonId"/>
+        
+        function saveUserPrefs<xsl:value-of select="$buttonId"/>()
+        {   
+            if ($j('#configure-links-form-<xsl:value-of select="$buttonId"/> input[type="checkbox"]:checked').length &gt; <xsl:value-of select="$maxCheckedLinks"/>)
+            {
+                alert("<i18n:translate>
+                        <i18n:text i18n:key='PLUGINS_LINKDIRECTORY_MAX_LINKS_SELECTED_ALERT' i18n:catalogue='plugin.link-directory'/>
+                        <i18n:param name="maxCheckedLinks"><xsl:value-of select="$maxCheckedLinks"/></i18n:param>
+                    </i18n:translate>");
+                return;
+            }
+        
+            // Generate form data
+            var data = {
+                'zone-item-id': $j('#zone-item-id-<xsl:value-of select="$buttonId"/>').val()
+            };
+            
+            $j('#configure-links-form-<xsl:value-of select="$buttonId"/> input[type="checkbox"]').each(function() {
+                var box = $j(this);
+                data['checkbox-' + encodeURIComponent(box.attr('data-serverid'))] = box.is(':checked');
+            });
+            
+            $j.ajax({
+                url: '<xsl:value-of select="$site-uri-prefix"/>/_plugins/link-directory/set-user-preferences?language=<xsl:value-of select="ametys:lang()"/>',
+                data: data,
+                success: function(data) { window.location.reload(); },
+                error: function(data) {alert("<i18n:text i18n:key="PLUGINS_LINKDIRECTORY_CONFIGURE_DIALOG_ERROR" i18n:catalogue="plugin.link-directory"/>");}
+            });
+        }
+        
+        $j('#configure-links-hyperlink-<xsl:value-of select="$buttonId"/>').on('click', function() {
+            $j('#configure-links-dialog-<xsl:value-of select="$buttonId"/>').dialog('open');
+        });
+        
+        $j('#configure-links-dialog-<xsl:value-of select="$buttonId"/>').dialog({
+            autoOpen: false,
+            resizable: false,
+            maxHeight: 435,
+            width: 400,
+            modal: true,
+            buttons: {
+                "<i18n:text i18n:key="PLUGINS_LINKDIRECTORY_CONFIGURE_DIALOG_CONFIRM" i18n:catalogue="plugin.link-directory"/>": function() {
+                    saveUserPrefs<xsl:value-of select="$buttonId"/>();
+                    $j(this).dialog('close');
+                },
+                "<i18n:text i18n:key="PLUGINS_LINKDIRECTORY_CONFIGURE_DIALOG_CANCEL" i18n:catalogue="plugin.link-directory"/>": function() {
+                    $j(this).dialog('close');
+                }
+            }
+        });
+    </xsl:template>
+    
+     <!--  Rendering of the errors -->
+    <xsl:template name="wrong-or-deleted-themes">
+        <xsl:call-template name="wrong-or-deleted-themes-impl">
+            <xsl:with-param name="data" select="/links/deleted-themes"/>
+        </xsl:call-template>
+    </xsl:template>
+    
+         <!--  Rendering of the errors -->
+    <xsl:template name="wrong-or-deleted-themes-impl">
+        <xsl:param name="data"/>
+        
+        <xsl:if test="$data">
+            <xsl:if test="$rendering-context = 'back'">
+                <div class="ametys-cms-zone-error">
+                   <div class="ametys-cms-zone-item-error">
+                       <div class="ametys-cms-content-inline-error">
+                           <table cellspacing="0" cellpadding="0">
+                                <tbody>
+                                    <tr>
+                                        <td style="vertical-align: top; width: 36px;">
+                                            <img alt="" src="{$uri-prefix}/plugins/web/resources/img/skin/zoneitem_error_32.png"/>
+                                        </td>
+                                        <td>
+                                            <strong><i18n:text i18n:key="PLUGINS_LINKDIRECTORY_DELETED_THEME_TITLE" i18n:catalogue="plugin.link-directory"/></strong>
+                                            <br/>
+                                            <em>
+                                                <i18n:translate>
+                                                    <i18n:text i18n:key="PLUGINS_LINKDIRECTORY_DELETED_THEME_TEXT" i18n:catalogue="plugin.link-directory"/>
+                                                    <i18n:param name="amount"><xsl:value-of select="$data"/></i18n:param>
+                                                </i18n:translate>
+                                            </em>
+                                        </td>
+                                    </tr>
+                                </tbody>
+                            </table>
+                        </div>
+                    </div>
+                </div>
+            </xsl:if>
+        </xsl:if>
+    </xsl:template>
+    
+</xsl:stylesheet>
+    
\ No newline at end of file
