Source: temp/jsdocinputdirs/cercalia.service.data.js

/**
 * @classdesc
 *
 * Class to get several information from Cercalia servers, like list of enabled categories into the API
 * and the client and countries list.
 *
 * @constructor
 */
cercalia.service.Data = function() {

	/**
	 * @private
	 * @type {string}
	 */
	this.cercaliaKey_ = cercaliaGlobals.key;	//Esta variable siempre se pasara al descargar la API

	/**
	 * @private
	 * @type {string}
	 */
	this.lang_ = cercaliaGlobals.lang ? cercaliaGlobals.lang : 'es';

	/**
	 * @private
	 * @type {string}
	 */
	this.server_ = servers.servlet;

	/**
	 * @private
	 * @type {Object}
	 */
	this.countries_ = null;

	/**
	 * @private
	 * @type {Object}
	 */
	this.categories_ = null;

	/**
	 * Nombre de la classe
	 * @private
	 * @type {string}
	 */
	this.CLASS_NAME_ = "cercalia.service.Data";
};

/**
 * Get an array with countries list
 * @param {Function} callbackFunction
 * @return {Array.<Object>}
 */
cercalia.service.Data.prototype.getCountries = function(callbackFunction) {

	if (!this.countries_ ){
		var countriesLocalStorageItem = 'countries_' + this.lang_;

		var localStorageOK = true;
		if (navigator.appName.indexOf("Internet Explorer")!=-1) {
		    var badBrowser = (
		        (navigator.appVersion.indexOf("MSIE 9") ==-1
		        		|| navigator.appVersion.indexOf("MSIE 8") ==-1)
		    );

		    if(badBrowser){
		    	localStorageOK = false;
		    }
		}

		if (localStorageOK) {
			if (localStorage.getItem(countriesLocalStorageItem) == null ) {
	//			this.countries_ = JSON.parse(
	//					cercalia.jQuery.ajax({
	//						url: servers.dataServlet,
	//						data : { data : 'countries', lang: this.lang_ },
	//						type: "GET",
	//						async: false
	//					})
	//					.responseText
	//			);
	//			localStorage.setItem(countriesLocalStorageItem, JSON.stringify(this.countries_));

				var jqxhr =  cercalia.jQuery.getJSON( servers.dataServlet + "?data=countries&lang="+this.lang_ );
				jqxhr.done(function( data, textStatus, jqXHR ) {
						this.countries_ = data;
						localStorage.setItem(countriesLocalStorageItem, JSON.stringify(this.countries_));
						callbackFunction(this.countries_);
				});

			} else {
				this.countries_ = JSON.parse(localStorage.getItem(countriesLocalStorageItem));
				callbackFunction(this.countries_);
			}
		} else {
			var jqxhr =  cercalia.jQuery.getJSON( servers.dataServlet + "?data=countries&lang="+this.lang_ );
			jqxhr.done(function( data, textStatus, jqXHR ) {
					this.countries_ = data;
					localStorage.setItem(countriesLocalStorageItem, JSON.stringify(this.countries_));
					callbackFunction(this.countries_);
			});
		}
	}
};

/**
 * Get an array with the categories and subcategories list. The images are specified in a CSS class rule.
 * @param {Function} callbackFunction
 * @return {Array.<Object>}
 */
cercalia.service.Data.prototype.getCategories = function(callbackFunction) {

	if (!this.categories_ ) {
		var categoriesLocalStorageItem = 'categories'+this.lang_;

		var localStorageOK = true;
		if (navigator.appName.indexOf("Internet Explorer")!=-1) {
		    var badBrowser=(
		        (navigator.appVersion.indexOf("MSIE 9") ==-1
		        		|| navigator.appVersion.indexOf("MSIE 8") ==-1)
		    );

		    if (badBrowser) {
		    	localStorageOK = false;
		    }
		}

		if (localStorageOK) {
			if (localStorage.getItem(categoriesLocalStorageItem) == null ) {
				var jqxhr = cercalia.jQuery.getJSON( servers.dataServlet + "?data=categories");

				jqxhr.complete(function( data, textStatus, jqXHR ) {
					this.categories_ = eval(data.responseText);
					localStorage.setItem(categoriesLocalStorageItem, JSON.stringify(this.categories_));
					callbackFunction(this.categories_);
				});


			} else {
				this.categories_ = JSON.parse(localStorage.getItem(categoriesLocalStorageItem));
				callbackFunction(this.categories_);
			}
		} else {
			var jqxhr = cercalia.jQuery.getJSON( servers.dataServlet + "?data=categories");

			jqxhr.complete(function( data, textStatus, jqXHR ) {
				this.categories_ = eval(data.responseText);
				localStorage.setItem(categoriesLocalStorageItem, JSON.stringify(this.categories_));
				callbackFunction(this.categories_);
			});

		}
	}

};

/**
 * @return {string} ClassName. `cercalia.service.Data`.
 */
cercalia.service.Data.prototype.getClass = function() {
	return this.CLASS_NAME_;
};