Implemented enabling/disabling of features
This commit is contained in:
@@ -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});
|
||||
|
||||
Reference in New Issue
Block a user