ds/DisplayPrice.js

/**
 * @fileoverview Exposed data type for use outside of DsClient.
 *               All properties should be exposed to allow use from uncompiled
 *               code.
 *
 * @author kim.simmons@spark-vision.com (Kim Simmons)
 */

goog.provide('spv.ds.DisplayPrice');




/**
 * The data contained in this class is generated by DsClient and should not be
 * explicitly constructed by the user.
 *
 * This struct holds information on how to present a price.
 * It includes the currency and the price value and where the currency symbol
 * should be placed (pre/postfix).
 * If use_text is true then it's expected to display the 'text' property instead
 * of the price.
 *
 * Legacy: Only a text with a pre-formatted price was used before the addition of
 * this datastructure.
 * Please inquire about backend-plugin support if this struct is used to replace
 * the deprecated string properties in an established client. Existing plugins
 * may not properly populate it.
 *
 * @struct
 * @constructor
 */
spv.ds.DisplayPrice = function()
{
	/**
	 * @type {boolean}
	 * @nocollapse
	 */
	this.use_text = false;

	/**
	 * @type {string}
	 * @nocollapse
	 */
	this.text = "UNDEFINED";

	/**
	 * @type {number}
	 * @nocollapse
	 */
	this.price_value = 0;

	/**
	 * @type {number}
	 * @nocollapse
	 */
	this.decimals = 0;

	/**
	 * @type {string}
	 * @nocollapse
	 */
	this.currency_symbol = "UNDEFINED";

	/**
	 * @type {boolean}
	 * @nocollapse
	 */
	this.currency_is_prefixed = false;
};



/**
 * Generates a string with a suggested formatting of the price.
 * @export
 * @return {string}
 */
spv.ds.DisplayPrice.prototype.defualtPriceString = function()
{
	if( this.use_text )
	{
		return this.text;
	}
	else
	{
		var price_str = this.price_value.toFixed(this.decimals);
		if( this.currency_is_prefixed )
			return this.currency_symbol + " " + price_str;
		else
			return price_str + " " + this.currency_symbol;
	}
};