var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; ///<reference path="../../base/BaseClass.ts" /> ///<reference path="./IWidgetConfigOptions.ts" /> ///<reference path="../../templating/ITemplateOptions.ts" /> ///<reference path="../../net/Uri.ts" /> var econda; (function (econda) { var recengine; (function (recengine) { var widget; (function (widget) { /** * Defines a Fallback configuration for Widgets. Fallback will be used, if we could not Possible fallbacks are: * <ul> * <li>Image URL: Show this image instead of recommendations</li> * <li>Template URL: Show this html template</li> * <li>Template HRML: Shot this html template</li> * <li>widget object or config options: use this widget instead</li> * </ul> * @class econda.recengine.widget.FallbackConfig * @experimental */ var FallbackConfig = (function (_super) { __extends(FallbackConfig, _super); function FallbackConfig(cfg) { _super.call(this); /** * Config options for a fallback widget * @cfg {Object} widget * @accessor */ this._widget = null; /** * Config options for template to render as fallback. All of the following values are supported. Template URIs must end with .html or .htm. * * fallback.setTemplate("/path/to/template.html"); * fallback.setTemplate("<div>our top sellers are...</div>"); * fallback.setTemplate({uri: "/path/to/template.html"}); * * @cfg {Object} template * @accessor */ this._template = null; /** * Uri of image to display instead of widget * @cfg {String} image * @accessor */ this._image = null; if (cfg instanceof FallbackConfig) { return cfg; } if (cfg instanceof econda.net.Uri) { this._constructWithConfigString(cfg.toString()); return; } if (typeof cfg == 'string') { this._constructWithConfigString(cfg); return; } if (typeof cfg == 'object' && cfg !== null) { this._constructWithConfigObject(cfg); return; } } FallbackConfig.prototype.setWidget = function (widgetConfig) { this._widget = widgetConfig; }; FallbackConfig.prototype.getWidget = function () { return this._widget; }; FallbackConfig.prototype.getTemplate = function () { return this._template; }; FallbackConfig.prototype.setTemplate = function (template) { if (typeof template == 'string') { if (template.match(/\.html?/i)) { this._template = { uri: template }; } else { this._template = { template: template }; } } else { this._template = template; } return this; }; FallbackConfig.prototype.getImage = function () { return this._image; }; FallbackConfig.prototype.setImage = function (imageUri) { if (imageUri === null) { this._image = null; } else { this._image = new econda.net.Uri(imageUri); } return this; }; FallbackConfig.prototype._constructWithConfigObject = function (cfg) { if (cfg.id || cfg.widgetId) { // it must be a widget configuration this._widget = cfg; return; } if (cfg.uri || cfg.template) { this._template = cfg; return; } }; FallbackConfig.prototype._constructWithConfigString = function (cfg) { if (cfg.match(/\.html?/i)) { this._template = { uri: cfg }; return; } if (cfg.match(/\.(png|jpg|jpeg|gif)/i)) { this._image = new econda.net.Uri(cfg); return; } this._template = { template: cfg }; }; return FallbackConfig; }(econda.base.BaseClass)); widget.FallbackConfig = FallbackConfig; })(widget = recengine.widget || (recengine.widget = {})); })(recengine = econda.recengine || (econda.recengine = {})); })(econda || (econda = {}));