Implemented a javascript code style

This commit is contained in:
Stefan Zermatten
2015-04-22 12:44:25 +02:00
parent dce20375b5
commit fada0f5136
113 changed files with 1614 additions and 1650 deletions

View File

@@ -2,13 +2,17 @@
Containers = new Mongo.Collection("containers");
Schemas.Container = new SimpleSchema({
name: { type: String, trim: false },
charId: { type: String, regEx: SimpleSchema.RegEx.Id},
isCarried: { type: Boolean },
name: {type: String, trim: false},
charId: {type: String, regEx: SimpleSchema.RegEx.Id},
isCarried: {type: Boolean},
weight: {type: Number, min: 0, defaultValue: 0, decimal: true},
value: {type: Number, min: 0, defaultValue: 0, decimal: true},
description:{type: String, optional: true, trim: false},
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
color: {
type: String,
allowedValues: _.pluck(colorOptions, "key"),
defaultValue: "q",
},
});
Containers.attachSchema(Schemas.Container);
@@ -16,7 +20,10 @@ Containers.attachSchema(Schemas.Container);
Containers.helpers({
contentsValue: function(){
var value = 0;
Items.find({"parent.id": this._id}, {fields: {quantity: 1, value: 1}}).forEach(function(item){
Items.find(
{"parent.id": this._id},
{fields: {quantity: 1, value: 1}}
).forEach(function(item){
value += item.totalValue();
});
return value;
@@ -26,7 +33,10 @@ Containers.helpers({
},
contentsWeight: function(){
var weight = 0;
Items.find({"parent.id": this._id}, {fields: {quantity: 1, weight: 1}}).forEach(function(item){
Items.find(
{"parent.id": this._id},
{fields: {quantity: 1, weight: 1}}
).forEach(function(item){
weight += item.totalWeight();
});
return weight;
@@ -35,12 +45,12 @@ Containers.helpers({
return this.contentsWeight() + this.weight;
},
moveToCharacter: function(characterId){
if(this.charId === characterId) return;
if (this.charId === characterId) return;
Items.update(this._id, {$set: {charId: characterId}});
}
},
});
Containers.attachBehaviour('softRemovable');
Containers.attachBehaviour("softRemovable");
makeParent(Containers); //parents of items
Containers.allow(CHARACTER_SUBSCHEMA_ALLOW);