/* $Id: module-img-viewer-class-imageversion.js 12373 2008-10-15 14:41:34Z jcwiklinski $ */
/* 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;
		}
		this.rotationInfos = 0; // l'angle de rotation ( 0 < angle => 360  )
	},

	getRotationInfos: function() {
		return this.rotationInfos;
	},

	reInitRotationInfos: function() {
		this.rotationInfos = 0;
	},

	setRotationInfos: function(angle) {
		if ( angle && angle > 0 && angle <= 360 ) {
			this.rotationInfos += angle;
			if( this.rotationInfos > 360 ) {
				this.rotationInfos -= 360;
			}
		}
	},

	getUrl: function() {
		var _url = this.baseUrl + "/" + this.info.src;
		if ( this.rotationInfos > 0 && this.rotationInfos < 360 ) {
			_url += "?r=" + this.rotationInfos
		}
		return _url;
	},

	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;
		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";
	}
}

