inventur/js/model/article.js
2018-01-10 10:06:05 +01:00

71 lines
1.5 KiB
JavaScript

function Article() {
this.name = "";
this.dimension = "";
this.content = {
size : 0,
price: 0
};
this.portion = {
size : 0,
price : 0,
type : ""
};
}
Article.prototype = {
get Name() {
return this.name;
},
set Name(value) {
this.name = value;
},
get ContentSize() {
return this.content.size;
},
set ContentSize(value) {
this.content.size = value;
},
get Dimension() {
return this.dimension;
},
set Dimension(value) {
this.dimension = value;
},
get PortionSize() {
return this.portion.size;
},
set PortionSize(value) {
this.portion.size = value;
},
get PortionType() {
return this.portion.type;
},
set PortionType(value) {
this.portion.type = value;
},
get PortionPrice() {
return this.portion.price;
},
set PortionPrice(value) {
this.portion.price = value;
},
get ContentPrice() {
return this.Portions * this.portion.price;
},
get Portions() {
return this.content.size / (this.portion.size || 1);
}
};
Article.thaw = function (json) {
var article = new Article();
article.id = json.id;
article.Name = json.name;
article.Dimension = json.dimension;
article.ContentSize = json.content.size;
article.PortionPrice = json.portion.price;
article.PortionSize = json.portion.size;
article.PortionType = json.portion.type;
return article;
};