/* $Id: module-img-viewer-class-imageversion.js 13818 2009-03-06 11:43:59Z mpichot $ */
/**
Copyright (C) 2003-2008 AJLSM, Anaphore
Voir le fichier LICENCE
**/
/* Ce fichier de configuration fait partie de la distribution standard
de Pleade. Vous pouvez le modifier à votre guise. */
/**
	Classe PivImageVersion.

	Cette classe représente les informations sur une version d'une image.
*/

// Création de la classe
var PivImageVersion = Class.create();		// Utilitaire de la librairie Prototype
PivImageVersion.prototype = {

	initialize: function(baseUrl, config) {
		this.baseUrl = baseUrl;
		if ( config ) {
			this.role = config.role;
			this.info = config;
		}
	},

	getUrl: function() {
		return this.baseUrl + "/" + this.info.src;
	},

	getNameWithoutQueryString: function() {
		var name = this.getName();
		if ( name.indexOf("?") < 0 ) return name;
		else return name.substring(0, name.indexOf("?"));
	},

	getRole: function() {
		return this.role;
	},

	getWidth: function() {
		if (this.info) return this.info.width;
		else return 0;
	},

	getHeight: function() {
		if (this.info) return this.info.height;
		else return 0;
	},

	getName: function() {
		/*if (this.info) return this.info.src;*/
		if (this.info){
			return (this.info.name) ? this.info.name : this.info.src;
		}
		else return "";
	},

	getLabel: function() {
		if (this.info) return this.info.label;
		else return "";
	},

	/**
	*	Retourne un résumé de la version (étiquette + taille).
	*/
	getSummary: function() {
		var ret = this.getLabel() + " (" + this.info.width + "x" + this.info.height + "px";
		if ( this.fileSize ) {
			var size = "" + (this.fileSize / (1024*1024)).toFixed(2) + "Mo"	// TODO i18n
			ret += ", " + size.gsub(/\./, ',');
		}
		ret += ")";
		return ret;
	},

	getMimeType: function() {
		return this.info.mimetype;
	},

	getTile: function() {
		// Retourne la tuile, ou undefined s'il n'y en a pas
		return this.info.tile;
	},

	/**
	*	Indique la taille (poids) de l'image (sous IE seulement, sinon reçoit undefined)
	*/
	setFileSize: function(s) {
		this.fileSize = s;
	},

	identify: function() {
		return "Classe PivImageVersion";
	}
}
