/*
 *  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.
 */

/**
 * @private
 * This tool displays the list of users
 */
Ext.define('Ametys.plugins.web.profiles.ProfilesTool', {
    extend: 'Ametys.plugins.coreui.profiles.ProfilesTool',
    
    _getGridFeatures: function()
    {
        if (Ametys.getAppParameters().siteName)
        {
            return [{
                    ftype: 'grouping',
                    groupHeaderTpl: Ext.create('Ext.XTemplate',
                        '<div>{[values.renderedGroupValue ? "{{i18n PLUGINS_WEB_PROFILES_GROUP_LOCAL}} (" + values.renderedGroupValue + ")" : "{{i18n PLUGINS_WEB_PROFILES_GROUP_SHARED}}"]}</div>'
                    )
            }];
        }
        else
        {
            return this.callParent(arguments);
        }
    },
    
    _getProfilesContext: function()
    {
        var siteName = Ametys.getAppParameter("siteName");
        if (siteName)
        {
            return siteName;
        }
        else
        {
            return "";
        }
    },
     
    createPanel: function()
    {
        var panel = this.callParent(arguments);
        
        this._rightsPanel.getComponent('card-edit').addDocked({
            xtype: 'component',
            ui: 'tool-hintmessage',
            itemId: 'shared-message',
            hidden: true,
            dock: 'top',
            html: "{{i18n PLUGINS_WEB_PROFILES_SHAREDHINT}}"
        });
        
        return panel;
    },
    
    _onSelectProfile: function(model, selection)
    {
        this.callParent(arguments);
        
        var sharedProfile = Ametys.WORKSPACE_NAME != "admin" && selection && selection.length ==1 && !selection[0].get('context'); 
        this._rightsPanel.getComponent('card-edit').getComponent('shared-message').setVisible(sharedProfile);
    }
});