/**
* @classdesc
* @class OSH.UI.Styler
* @abstract
*/
OSH.UI.Styler = Class.create({
initialize : function(jsonProperties) {
this.properties = jsonProperties;
this.id = "styler-" + OSH.Utils.randomUUID();
this.dataSourceToStylerMap = {};
this.initEvents();
},
/**
* @memberof OSH.UI.Styler
* @instance
*/
initEvents:function() {
OSH.EventManager.observe(OSH.EventManager.EVENT.DATASOURCE_UPDATE_TIME,function(event){
this.clear();
}.bind(this));
},
/**
* @memberof OSH.UI.Styler
* @instance
*/
clear: function() {
},
/**
* @param {string} dataSourceId the datasource id
* @param {Object} data the data
* @param {OSH.View} view the osh.view
* @memberof OSH.UI.Styler
* @instance
*/
setData : function(dataSourceId, data, view) {
},
/**
* Gets the styler id.
* @returns {string} the styler id
* @memberof OSH.UI.Styler
* @instance
*/
getId : function() {
return this.id;
},
/**
* Selects the datasource contained into the list
* @param {Array} dataSourceIds the list of datasources
* @memberof OSH.UI.Styler
* @instance
*/
select : function(dataSourceIds) {
},
/**
* Adds a function
* @param {Array} dataSourceIds the list of datasources
* @param {function} fn the function to apply
* @memberof OSH.UI.Styler
* @instance
*/
addFn : function(dataSourceIds, fn) {
for (var i = 0; i < dataSourceIds.length; i++) {
var dataSourceId = dataSourceIds[i];
if (typeof (this.dataSourceToStylerMap[dataSourceId]) == "undefined") {
this.dataSourceToStylerMap[dataSourceId] = [];
}
this.dataSourceToStylerMap[dataSourceId].push(fn);
}
},
/**
*
* @param dataSourceId
* @param rec
* @param view
* @param options
* @returns {boolean}
* @memberof OSH.UI.Styler
* @instance
*/
setData : function(dataSourceId, rec, view, options) {
if (dataSourceId in this.dataSourceToStylerMap) {
var fnArr = this.dataSourceToStylerMap[dataSourceId];
for (var i = 0; i < fnArr.length; i++) {
fnArr[i](rec.data, rec.timeStamp, options);
}
return true;
} else {
return false;
}
},
/**
*
* @returns {Array}
* @memberof OSH.UI.Styler
* @instance
*/
getDataSourcesIds : function() {
var res = [];
for ( var i in this.dataSourceToStylerMap) {
res.push(i);
}
return res;
},
/**
* @memberof OSH.UI.Styler
* @instance
*/
init: function() {}
});