/*
 *  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
 * The model for the {@link Ametys.plugins.web.site.SitesTool} tree tool. 
 */
Ext.define('Ametys.web.site.SitesTree.Site', { 
    extend: 'Ext.data.TreeModel', 
    fields: [ 
        { name: 'id', type: 'string' }, 
        { name: 'name', type: 'string' }, 
        { name: 'valid', type: 'boolean' }, 
        { name: 'current', type: 'boolean' }, 
        { name: 'level', type: 'int' },
        { name: 'depth', type: 'int' },
        { name: 'sharedContentsCount', type: 'int' },
        { 
        	name: 'text', 
        	type: 'string', 
        	calculate: function (data) {
        		if (Ext.isEmpty(data.title))
        		{
        			return data.name;
        		}
        		else if (data.name == 'ametys:sites')
                {
                    return data.title;
                }
                else
        		{
        			return data.title + ' (' + data.name + ')';
        		}
        	},
        	depends: ['name', 'title']
        },
        { name: 'url', type: 'string' },
        { name: 'title', type: 'string' },
        { name: 'type', type: 'string' },
        { name: 'color', type: 'string' },
        { name: 'colorIndex', type: 'string'  },
        { name: 'typeLabel', type: 'string' },
        { name: 'description', type: 'string' },
        { name: 'iconGlyph', type: 'string' },
        {
           name: 'iconCls',
           depends: ['iconGlyph', 'valid', 'colorIndex'],
           calculate: function (data)
           {
               if (!Ext.isEmpty(data.iconGlyph))
               {
                   return 'a-tree-glyph ' + data.iconGlyph + (data.valid ? '' :  ' decorator-ametysicon-caution9 site-warning') + (data.name != 'ametys:sites' ? ' a-sitescolors-' + data.colorIndex : '');
               }
               
               return data.iconCls + (data.valid ? '' :  ' decorator-ametysicon-caution9 site-warning');
           }
        },
        { name: 'iconSmall', type: 'string' },
        { name: 'iconLarge', type: 'string' },
        { 
        	name: 'icon', 
        	type: 'string',
        	depends: ['iconSmall', 'iconGlyph'],
        	calculate: function (data) {
        		if (Ext.isEmpty(data.iconGlyph))
                {
        			return Ametys.CONTEXT_PATH + data.iconSmall;
                }
        		return null;
        	}
        },
        { name: 'populations' },
        { name: 'groups' },
        { name: 'populationsFO' },
        { name: 'groupsFO' }
    ]
});