1 | import { File } from '../files/index';
|
2 | import { CaseTransform } from './case-transform';
|
3 | var COLOR_CODES = [
|
4 | '#EF5350', '#42A5F5', '#66BB6A', '#FFA726', '#AB47BC', '#FFCA28', '#EC407A', '#26C6DA',
|
5 | '#FF7B57'
|
6 | ];
|
7 | var DEFAULT_COLOR = '#808080';
|
8 | var Product = (function () {
|
9 | function Product(data) {
|
10 | this.addons = [];
|
11 | data = data || {};
|
12 | this.productId = data.productId;
|
13 | this.name = data.name;
|
14 | this.description = data.description;
|
15 | this.tagline = data.tagline;
|
16 | this.iconUrl = data.iconUrl;
|
17 | this.entryUrl = data.entryUrl;
|
18 | this.screenshotUrls = data.screenshotUrls;
|
19 | this.pdfUploadUrls = data.pdfUploadUrls;
|
20 | this.lmiCategories = data.lmiCategories;
|
21 | this.keySellingPoints = data.keySellingPoints;
|
22 | this.faqs = data.faqs;
|
23 | this.wholesalePrice = data.wholesalePrice;
|
24 | this.currency = data.currency;
|
25 | this.billingFrequency = data.billingFrequency;
|
26 | this.isArchived = data.isArchived;
|
27 | this.addons = data.addons;
|
28 | this.restrictions = data.restrictions;
|
29 | if (data.hasOwnProperty('pdfUploadUrls')) {
|
30 | this.files = this.pdfUploadUrls ? this.pdfUploadUrls.map(function (url) { return new File(url); }) : null;
|
31 | }
|
32 | }
|
33 | Product.fromApi = function (data) {
|
34 | var newProduct = {};
|
35 | data = data || {};
|
36 | for (var key in data) {
|
37 | if (data.hasOwnProperty(key)) {
|
38 | var newKey = CaseTransform.snakeToCamelCase(key);
|
39 | newProduct[newKey] = data[key];
|
40 | }
|
41 | }
|
42 | return new Product(newProduct);
|
43 | };
|
44 | Object.defineProperty(Product.prototype, "iconStyle", {
|
45 | get: function () {
|
46 | return this.iconUrl ? "url(\"" + this.iconUrl + "\") no-repeat center / 100% 100%" : null;
|
47 | },
|
48 | enumerable: true,
|
49 | configurable: true
|
50 | });
|
51 | Object.defineProperty(Product.prototype, "iconColor", {
|
52 | get: function () {
|
53 |
|
54 | if (!this.name) {
|
55 | return DEFAULT_COLOR;
|
56 | }
|
57 | var nameSum = 0;
|
58 | for (var i = 0; i < this.name.length; i++) {
|
59 | nameSum += this.name[i].charCodeAt(0);
|
60 | }
|
61 | var index = nameSum % COLOR_CODES.length;
|
62 | return COLOR_CODES[index];
|
63 | },
|
64 | enumerable: true,
|
65 | configurable: true
|
66 | });
|
67 | Product.prototype.getLmiCategoryNames = function () {
|
68 | var lmiCategories = this.lmiCategories || [];
|
69 | return lmiCategories.map(function (lmiCategory) { return CaseTransform.lowerToTitleCase(lmiCategory.toLowerCase().replace(/_/g, ' ')); });
|
70 | };
|
71 | return Product;
|
72 | }());
|
73 | export { Product };
|