Implemented enabling/disabling of features

This commit is contained in:
Thaum
2015-03-11 09:43:45 +00:00
parent 297e54cdc2
commit 2b9cbcf717
7 changed files with 92 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ Schemas.Feature = new SimpleSchema({
uses: {type: String, optional: true, trim: false},
used: {type: Number, defaultValue: 0},
reset: {type: String, allowedValues: ["manual", "longRest", "shortRest"], defaultValue: "manual"},
enabled: {type: String, allowedValues: ["enabled", "disabled", "alwaysEnabled"], defaultValue: "alwaysEnabled"},
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
});
@@ -21,8 +22,17 @@ Features.helpers({
}
});
//Delete effects where this the removed feature is source
Features.before.remove(function (userId, feature) {
Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){
Effects.remove(effect._id);
});
});
//keep the effects up to date with enabled state
Features.after.update(function (userId, feature, fieldNames, modifier, options) {
var enabled = feature.enabled !== "disabled";
Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){
Effects.update(effect._id, { $set: {charId: feature.charId, enabled: enabled, name: feature.name} });
});
}, {fetchPrevious: false});