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

/**
 * This tool simply displays a iframe
 * @private
 */
Ext.define('Ametys.plugins.cms.iframe.IframeTool', {
	extend: "Ametys.tool.Tool",
	
	/**
	 * @cfg {String} url (required) The url of the iframe
	 */
	/**
	 * @property _url {String} The url of the iframe. See #cfg-url.
	 */
	
	/**
	 * @private
	 * @property {Ext.ux.IFrame} _iframe The iframe object
	 */
	
	constructor: function(config)
	{
		this.callParent(arguments);
		this._url = this.getInitialConfig('url');
	},
	
	createPanel: function ()
	{
		this._iframe = Ext.create("Ext.ux.IFrame", {}); 
		
		return this._iframe;
	},
	
	getMBSelectionInteraction: function() 
	{
		return Ametys.tool.Tool.MB_TYPE_NOSELECTION;
	},
	
	setParams: function (params)
	{
		this.callParent(arguments);
		
		this._url = params['url'];
		
		this.refresh();
	},
	
	refresh: function (manual)
	{
		this.showRefreshing();
		
		// Defer load to center the load mask message
		Ext.defer(this._deferredLoad, 1, this);
		
		// Set title, description and icons.
		this.setTitle(this._params['title']);
		this.setDescription(this._params['description']);
		this.setSmallIcon(this._params['icon-small']);
		this.setMediumIcon(this._params['icon-medium']);
		this.setLargeIcon(this._params['icon-large']);
		
		this.showRefreshed();
	},
	
	/**
	 * Load iframe
	 */
	_deferredLoad: function ()
	{
		this._iframe.load(this._url);
	}
	
});