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="IResultDecorator.ts" /> /// <reference path="../Request.ts" /> var econda; (function (econda) { var recengine; (function (recengine) { var decorator; (function (decorator) { /** * Base class for decorators that manipulate product field values * * @class econda.recengine.decorator.AbstractFieldDecorator */ var AbstractFieldDecorator = (function (_super) { __extends(AbstractFieldDecorator, _super); function AbstractFieldDecorator() { _super.apply(this, arguments); /** * Reference to request object * @cfg {econda.recengine.Request} request * @accessor */ this.request = null; /** * Fields to decorate * @cfg {String[]} fields * @accessor */ this.fields = {}; /** * Reference to response we're working on * @protected * @property {econda.recengine.response.Response} */ this.response = null; } AbstractFieldDecorator.prototype.getRequest = function () { return this.request; }; AbstractFieldDecorator.prototype.setRequest = function (request) { this.request = request; return this; }; AbstractFieldDecorator.prototype.getFields = function () { var fieldNames = []; for (var name in this.fields) { fieldNames.push(name); } return this.fields; }; AbstractFieldDecorator.prototype.setFields = function (fieldNames) { if (econda.util.ArrayUtils.isArray(fieldNames)) { this.fields = fieldNames; } else { this.fields = [fieldNames]; } return this; }; /** * Decorate it... */ AbstractFieldDecorator.prototype.decorate = function (response) { this.response = response; var products = response.getProducts(); for (var i = 0; i < products.length; i++) { var product = products[i]; this.decorateProduct(product); for (var n = 0; n < this.fields.length; n++) { if (typeof product[this.fields[n]] != 'undefined') { product[this.fields[n]] = this.decorateField(product[this.fields[n]], product, this.fields[n]); } } } }; /** * will be called once per product */ AbstractFieldDecorator.prototype.decorateProduct = function (product) { }; /** * will be called per field. */ AbstractFieldDecorator.prototype.decorateField = function (fieldValue, product, fieldName) { }; return AbstractFieldDecorator; }(econda.base.BaseClass)); decorator.AbstractFieldDecorator = AbstractFieldDecorator; // end of class })(decorator = recengine.decorator || (recengine.decorator = {})); })(recengine = econda.recengine || (econda.recengine = {})); })(econda || (econda = {})); // end of module