implemented UI for new parenting
This commit is contained in:
@@ -60,7 +60,11 @@ Characters.after.insert(function (userId, char) {
|
||||
name: "Constitution modifier for each level",
|
||||
stat: "hitPoints",
|
||||
operation: "add",
|
||||
calculation: "level * constitutionMod"
|
||||
calculation: "level * constitutionMod",
|
||||
parent: {
|
||||
id: char._id,
|
||||
collection: "Characters"
|
||||
}
|
||||
});
|
||||
Effects.insert({
|
||||
charId: char._id,
|
||||
@@ -68,7 +72,11 @@ Characters.after.insert(function (userId, char) {
|
||||
name: "Proficiency bonus by level",
|
||||
stat: "proficiencyBonus",
|
||||
operation: "add",
|
||||
calculation: "floor(level / 4 + 1.75)"
|
||||
calculation: "floor(level / 4 + 1.75)",
|
||||
parent: {
|
||||
id: char._id,
|
||||
collection: "Characters"
|
||||
}
|
||||
});
|
||||
Effects.insert({
|
||||
charId: char._id,
|
||||
@@ -76,7 +84,11 @@ Characters.after.insert(function (userId, char) {
|
||||
name: "Dexterity Armor Bonus",
|
||||
stat: "armor",
|
||||
operation: "add",
|
||||
calculation: "dexterityArmor"
|
||||
calculation: "dexterityArmor",
|
||||
parent: {
|
||||
id: char._id,
|
||||
collection: "Characters"
|
||||
}
|
||||
});
|
||||
Effects.insert({
|
||||
charId: char._id,
|
||||
@@ -84,7 +96,11 @@ Characters.after.insert(function (userId, char) {
|
||||
name: "Natural Armor",
|
||||
stat: "armor",
|
||||
operation: "base",
|
||||
value: 10
|
||||
value: 10,
|
||||
parent: {
|
||||
id: char._id,
|
||||
collection: "Characters"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,14 +16,14 @@ Containers.attachSchema(Schemas.Container);
|
||||
Containers.helpers({
|
||||
totalValue: function(){
|
||||
var value = this.value;
|
||||
Items.find({container: this._id, equipped: false}, {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;
|
||||
},
|
||||
totalWeight: function(){
|
||||
var weight = this.weight;
|
||||
Items.find({container: this._id, equipped: false}, {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;
|
||||
|
||||
@@ -33,17 +33,24 @@ Items.helpers({
|
||||
return this.name;
|
||||
}
|
||||
},
|
||||
equip: function(){
|
||||
Items.update(this._id, {$set: {enabled: true}});
|
||||
equip: function(characterId){
|
||||
var charId = characterId || this.charId;
|
||||
if(!charId || ! Characters.findOne(charId)) throw "Invalid character";
|
||||
if(this.parent.collection === "Characters" && this.parent.id === charId && this.enabled) return;
|
||||
Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": charId, enabled: true}});
|
||||
},
|
||||
unequip: function(){
|
||||
if(!this.enabled) return;
|
||||
Items.update(this._id, {$set: {enabled: false}});
|
||||
},
|
||||
moveToContainer: function(containerId){
|
||||
if( !containerId || !Containers.findOne(containerId) ) throw "Invalid container";
|
||||
if(this.parent.collection === "Containers" && this.parent.id === containerId && !this.enabled) return;
|
||||
Items.update(this._id, {$set: {"parent.collection": "Containers", "parent.id": containerId, enabled: false}});
|
||||
},
|
||||
moveToCharacter: function(characterId){
|
||||
if(this.charId === characterId) return;
|
||||
if(!characterId || ! Characters.findOne(characterId)) throw "Invalid character";
|
||||
if(this.parent.collection === "Characters" && this.parent.id === characterId && !this.enabled) return;
|
||||
Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": characterId, charId: characterId, enabled: false}});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!--needs to be given charId, sourceId and type-->
|
||||
<!--needs to be given charId, parentId and type-->
|
||||
<template name="attackEditList">
|
||||
{{#if attacks.count}}
|
||||
<hr style="margin: 16px 0 16px 0;">
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
Template.attackEditList.helpers({
|
||||
attacks: function(){
|
||||
var cursor = Attacks.find({sourceId: this.sourceId, type: this.type});
|
||||
var cursor = Attacks.find({"parent.id": this.parentId, type: this.type, charId: this.charId});
|
||||
return cursor;
|
||||
}
|
||||
});
|
||||
|
||||
Template.attackEditList.events({
|
||||
"tap #addAttackButton": function(){
|
||||
if ( !_.isBoolean(this.enabled) ) {
|
||||
this.enabled = true;
|
||||
}
|
||||
Attacks.insert({
|
||||
name: this.name,
|
||||
charId: this.charId,
|
||||
sourceId: this.sourceId,
|
||||
parent: {
|
||||
id: this.parentId,
|
||||
collection: this.parentCollection
|
||||
},
|
||||
type: this.type,
|
||||
enabled: this.enabled
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<template name="effectView">
|
||||
<div class="effectView" layout horizontal center>
|
||||
{{#if sourceId}}
|
||||
<div>{{sourceName}}</div>
|
||||
{{else}}
|
||||
{{#with statName}}
|
||||
<div flex>{{statName}}</div>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<div flex>{{sourceName}}</div>
|
||||
{{/with}}
|
||||
<div>{{operationName}}</div>
|
||||
<div>{{statValue}}</div>
|
||||
<br>
|
||||
|
||||
@@ -86,20 +86,20 @@ var operations = {
|
||||
|
||||
Template.effectView.helpers({
|
||||
sourceName: function(){
|
||||
var id = this.sourceId;
|
||||
var id = this.parent.id;
|
||||
if(!id) return;
|
||||
switch(this.type){
|
||||
case "feature":
|
||||
switch(this.parent.collection){
|
||||
case "Features":
|
||||
return "Feature - " + Features.findOne(id, {fields: {name: 1}}).name;
|
||||
case "class":
|
||||
case "Classes":
|
||||
return Classes.findOne(id, {fields: {name: 1}}).name;
|
||||
case "buff":
|
||||
case "Buffs":
|
||||
return "Buff - " + Buffs.findOne(id, {fields: {name: 1}}).name;
|
||||
case "equipment":
|
||||
case "Items":
|
||||
return "Equipment - " + Items.findOne(id, {fields: {name: 1}}).name;
|
||||
case "racial":
|
||||
case "Characters":
|
||||
return Characters.findOne(this.charId, {fields: {race: 1}}).race;
|
||||
case "inate":
|
||||
default:
|
||||
return "Inate"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!--needs to be given charId, sourceId and type-->
|
||||
<!--needs to be given charId, parentId, parentCollection and type-->
|
||||
<template name="effectsEditList">
|
||||
{{#if effects.count}}
|
||||
<hr style="margin: 16px 0 16px 0;">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Template.effectsEditList.helpers({
|
||||
effects: function(){
|
||||
var cursor = Effects.find({sourceId: this.sourceId, type: this.type});
|
||||
var cursor = Effects.find({"parent.id": this.parentId, "parent.collection": this.parentCollection, type: this.type});
|
||||
return cursor;
|
||||
}
|
||||
});
|
||||
@@ -13,7 +13,10 @@ Template.effectsEditList.events({
|
||||
Effects.insert({
|
||||
name: this.name,
|
||||
charId: this.charId,
|
||||
sourceId: this.sourceId,
|
||||
parent: {
|
||||
id: this.parentId,
|
||||
collection: this.parentCollection
|
||||
},
|
||||
operation: "add",
|
||||
type: this.type,
|
||||
enabled: this.enabled
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!--needs to be given charId, sourceId and type-->
|
||||
<!--needs to be given charId, (parentId or stat) and type-->
|
||||
<template name="effectsViewList">
|
||||
{{#if effects}}
|
||||
<hr style="margin: 16px 0 16px 0;">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Template.effectsViewList.helpers({
|
||||
effects: function(){
|
||||
if(this.sourceId){
|
||||
return Effects.find({sourceId: this.sourceId, type: this.type, charId: this.charId}, {fields: {sourceId: 0}});
|
||||
if(this.parentId){
|
||||
return Effects.find({"parent.id": this.parentId, type: this.type, charId: this.charId}, {fields: {parent: 0}});
|
||||
} else if(this.stat){
|
||||
return Effects.find({charId: this.charId, stat: this.stat});
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</paper-dropdown>
|
||||
</paper-dropdown-menu>
|
||||
</div>
|
||||
{{> effectsEditList sourceId=_id charId=charId type="feature" name=name enabled=isEnabled}}
|
||||
{{> effectsEditList parentId=_id parentCollection="Features" charId=charId type="feature" name=name enabled=isEnabled}}
|
||||
{{/baseDialog}}
|
||||
{{/with}}
|
||||
</template>
|
||||
@@ -116,7 +116,7 @@ div#stats {
|
||||
.inventoryItem {
|
||||
background: white;
|
||||
transition: box-shadow 0.3s ease,
|
||||
opacity 0.3s ease;
|
||||
opacity 0.5s ease-in-out;
|
||||
height: 40px;
|
||||
margin: 1px 0 1px 0;
|
||||
font-size: 16px;
|
||||
|
||||
@@ -7,10 +7,10 @@ Template.inventory.helpers({
|
||||
return Containers.find({charId: this._id}, {sort: {color: 1, name: 1}})
|
||||
},
|
||||
items: function(charId, containerId){
|
||||
return Items.find({charId: charId, equipped: false, container: containerId }, {sort: {color: 1, name: 1}});
|
||||
return Items.find({charId: charId, "parent.id": containerId }, {sort: {color: 1, name: 1}});
|
||||
},
|
||||
equipment: function(){
|
||||
return Items.find({ charId: this._id, equipped: true }, {sort: {color: 1, name: 1}});
|
||||
return Items.find({ charId: this._id, enabled: true }, {sort: {color: 1, name: 1}});
|
||||
},
|
||||
showAddButtons: function(){
|
||||
return Template.instance().showAddButtons.get();
|
||||
@@ -30,21 +30,21 @@ Template.inventory.helpers({
|
||||
Containers.find({charId: this._id, isCarried: true}).forEach(function(container){
|
||||
weight += container.totalWeight();
|
||||
});
|
||||
Items.find({charId: this._id, equipped: true}, {fields: {weight : 1, quantity: 1}}).forEach(function(item){
|
||||
Items.find({charId: this._id, "parent.id": this._id}, {fields: {weight : 1, quantity: 1}}).forEach(function(item){
|
||||
weight += item.totalWeight();
|
||||
});
|
||||
return weight;
|
||||
},
|
||||
equipmentValue: function(){
|
||||
var value = 0;
|
||||
Items.find({charId: this._id, equipped: true}, {fields: {value : 1, quantity: 1}}).forEach(function(item){
|
||||
Items.find({charId: this._id, enabled: true}, {fields: {value : 1, quantity: 1}}).forEach(function(item){
|
||||
value += item.totalValue();
|
||||
});
|
||||
return value;
|
||||
},
|
||||
equipmentWeight: function(){
|
||||
var weight = 0;
|
||||
Items.find({charId: this._id, equipped: true}, {fields: {weight : 1, quantity: 1}}).forEach(function(item){
|
||||
Items.find({charId: this._id, enabled: true}, {fields: {weight : 1, quantity: 1}}).forEach(function(item){
|
||||
weight += item.totalWeight();
|
||||
});
|
||||
return weight;
|
||||
@@ -63,7 +63,13 @@ Template.inventory.events({
|
||||
containerId = Containers.insert({name: "New Container", isCarried: true, charId: this._id});
|
||||
}
|
||||
_.defer(function(){
|
||||
var itemId = Items.insert({charId: charId, container: containerId});
|
||||
var itemId = Items.insert({
|
||||
charId: charId,
|
||||
parent:{
|
||||
id: containerId,
|
||||
collection: "Containers"
|
||||
}
|
||||
});
|
||||
GlobalUI.setDetail({
|
||||
template: "itemDialog",
|
||||
data: {itemId: itemId, charId: charId},
|
||||
@@ -128,35 +134,18 @@ Template.layout.events({
|
||||
event.preventDefault();
|
||||
},
|
||||
"dragover .equipmentContainer": function(event, instance){
|
||||
var containerId = Session.get("inventory.dragItemOriginalContainer");
|
||||
var charId = Session.get("inventory.dragItemOriginalCharacter");
|
||||
|
||||
if (this._id !== charId) return; //we can't equip something we don't own
|
||||
|
||||
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
||||
if (item.equipmentSlot === "none") return; //we can't equip this
|
||||
|
||||
event.preventDefault(); //this is a valid drop zone
|
||||
},
|
||||
"drop .container": function(event, instacne){
|
||||
"drop .itemContainer": function(event, instacne){
|
||||
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
||||
if (!item) return; //the item doesn't exist
|
||||
if (item.container === this._id && !item.equipped) return; //the item is already here
|
||||
if(Containers.findOne(this._id)){//the container exists
|
||||
Items.update(item._id, {$set: {container: this._id, charId: this.charId, equipped: false}});
|
||||
}
|
||||
//move item to the container
|
||||
item.moveToContainer(this._id)
|
||||
resetInvetorySession();
|
||||
},
|
||||
"drop .equipmentContainer": function(event, instance){
|
||||
var containerId = Session.get("inventory.dragItemOriginalContainer");
|
||||
var charId = Session.get("inventory.dragItemOriginalCharacter");
|
||||
|
||||
if (this._id !== charId) return; //we can't equip something we don't own
|
||||
|
||||
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
||||
if (item.equipmentSlot === "none") return; //we can't equip this
|
||||
//equip the item if it's not equipped
|
||||
if(!item.equipped) Items.update(item._id, {$set: {equipped: true, container: containerId, charId: charId}});
|
||||
item.equip(charId);
|
||||
resetInvetorySession();
|
||||
}
|
||||
})
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
<!--Container dropdown-->
|
||||
<paper-dropdown-menu id="containerDropDown" label="Container">
|
||||
<paper-dropdown layered class="dropdown">
|
||||
<core-menu class="menu" selected={{containerIndex}}>
|
||||
<core-menu class="menu" selected={{parent.id}}>
|
||||
{{#each containers}}
|
||||
<paper-item containerId={{_id}} class="containerMenuItem">{{name}}</paper-item>
|
||||
<paper-item name={{_id}} class="containerMenuItem">{{name}}</paper-item>
|
||||
{{/each}}
|
||||
</core-menu>
|
||||
</paper-dropdown>
|
||||
@@ -57,9 +57,9 @@
|
||||
</paper-input-decorator>
|
||||
{{#if canEquip}}
|
||||
<!--Effects-->
|
||||
{{> effectsEditList sourceId=_id charId=charId type="equipment" enabled=equipped name=name}}
|
||||
{{> effectsEditList parentId=_id parentCollection="Items" charId=charId type="equipment" enabled=equipped name=name}}
|
||||
<!--Attacks-->
|
||||
{{> attackEditList sourceId=_id charId=charId type="equipment" enabled=equipped name=name}}
|
||||
{{> attackEditList parentId=_id parentCollection="Items" charId=charId type="equipment" enabled=equipped name=name}}
|
||||
{{/if}}
|
||||
{{/baseDialog}}
|
||||
{{/with}}
|
||||
|
||||
@@ -19,11 +19,6 @@ Template.itemDialog.helpers({
|
||||
containers: function(){
|
||||
return getContainers(this.charId);
|
||||
},
|
||||
containerIndex: function(){
|
||||
var containers = getContainers(this.charId);
|
||||
var containerIds = _.pluck(containers, "_id");
|
||||
return _.indexOf(containerIds, this.container);
|
||||
},
|
||||
equipmentSlots: function(){
|
||||
return equipmentSlots;
|
||||
},
|
||||
@@ -79,8 +74,9 @@ Template.itemDialog.events({
|
||||
"core-select #containerDropDown": function(event){
|
||||
var detail = event.originalEvent.detail;
|
||||
if(!detail.isSelected) return;
|
||||
var containerId = detail.item.getAttribute("containerId");
|
||||
Items.update(Template.currentData().itemId, {$set: {container: containerId}});
|
||||
var containerId = detail.item.getAttribute("name");
|
||||
var item = Items.findOne(Template.currentData().itemId);
|
||||
item.moveToContainer(containerId);
|
||||
},
|
||||
"core-select #slotDropDown": function(event){
|
||||
var detail = event.originalEvent.detail;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<!--Level-->
|
||||
<paper-input id="levelValueInput" label="Level" floatinglabel value={{level}}></paper-input>
|
||||
<!--Effects-->
|
||||
{{> effectsEditList sourceId=_id charId=charId type="class"}}
|
||||
{{> effectsEditList parentId=_id parentCollection="Classes" charId=charId type="class"}}
|
||||
{{/baseDialog}}
|
||||
{{/with}}
|
||||
</template>
|
||||
@@ -1,6 +1,6 @@
|
||||
<template name="raceDialog">
|
||||
{{#baseDialog title="Race" class=colorClass hideColor="true" hideDelete="true"}}
|
||||
<paper-input id="raceInput" label="Race" floatinglabel value={{race}}></paper-input>
|
||||
{{> effectsEditList sourceId=_id charId=charId type="racial"}}
|
||||
{{> effectsEditList parentId=_id parentCollection="Characters" charId=charId type="racial"}}
|
||||
{{/baseDialog}}
|
||||
</template>
|
||||
@@ -8,7 +8,7 @@
|
||||
<!--List dropdown-->
|
||||
<paper-dropdown-menu id="listDropdown" label="Spell List">
|
||||
<paper-dropdown layered class="dropdown">
|
||||
<core-menu class="menu" selected={{listId}}>
|
||||
<core-menu class="menu" selected={{parent.id}}>
|
||||
{{#each spellLists}}
|
||||
<paper-item name={{_id}} class="containerMenuItem">{{name}}</paper-item>
|
||||
{{/each}}
|
||||
|
||||
@@ -69,8 +69,8 @@ Template.spellDialog.events({
|
||||
var detail = event.originalEvent.detail;
|
||||
if(!detail.isSelected) return;
|
||||
var value = detail.item.getAttribute("name");
|
||||
if (value == this.listId) return;
|
||||
Spells.update(this._id, {$set: {listId: value}});
|
||||
if (value == this.parent.id) return;
|
||||
Spells.update(this._id, {$set: {"parent.id": value}});
|
||||
},
|
||||
"core-select #levelDropdown": function(event){
|
||||
var detail = event.originalEvent.detail;
|
||||
|
||||
@@ -16,22 +16,23 @@ Template.spells.helpers({
|
||||
return SpellLists.find({charId: this._id}, {sort: {color: 1, name: 1}});
|
||||
},
|
||||
spellCount: function(list, charId){
|
||||
if(!list || !list.settings) return;
|
||||
if(list.settings.showUnprepared){
|
||||
return Spells.find( {charId: charId, listId: list._id, level: this.level},
|
||||
return Spells.find( {charId: charId, "parent.id": list._id, level: this.level},
|
||||
{fields: {_id: 1, level: 1}} ).count() > 0;
|
||||
} else{
|
||||
return Spells.find( {charId: charId, listId: list._id, level: this.level, prepared: {$in: ["prepared", "always"]} },
|
||||
return Spells.find( {charId: charId, "parent.id": list._id, level: this.level, prepared: {$in: ["prepared", "always"]} },
|
||||
{fields: {_id: 1, level: 1}} ).count() > 0;
|
||||
}
|
||||
},
|
||||
spells: function(listId, charId){
|
||||
return Spells.find( {charId: charId, listId: listId, level: this.level}, {sort: {color: 1, name: 1}} );
|
||||
return Spells.find( {charId: charId, "parent.id": listId, level: this.level}, {sort: {color: 1, name: 1}} );
|
||||
},
|
||||
levels: function(){
|
||||
return spellLevels;
|
||||
},
|
||||
numPrepared: function(){
|
||||
return Spells.find({charId: Template.parentData()._id, listId: this._id, prepared: "prepared"}).count();
|
||||
return Spells.find({charId: Template.parentData()._id, "parent.id": this._id, prepared: "prepared"}).count();
|
||||
},
|
||||
order: function(){
|
||||
return _.indexOf(_.keys(colorOptions), this.color);
|
||||
@@ -168,17 +169,20 @@ Template.spells.events({
|
||||
},
|
||||
"tap #addSpell": function(event){
|
||||
var charId = this.charId;
|
||||
var listId = this.listId;
|
||||
var listId = SpellLists.findOne({charId: this._id})._id;
|
||||
Spells.insert({
|
||||
name: "New Spell",
|
||||
charId: this._id,
|
||||
listId: SpellLists.findOne({charId: this._id})._id,
|
||||
parent: {
|
||||
id: listId,
|
||||
collection: "SpellLists"
|
||||
},
|
||||
prepared: "prepared"
|
||||
}, function(error, id){
|
||||
if(!error){
|
||||
GlobalUI.setDetail({
|
||||
template: "spellDialog",
|
||||
data: {spellId: id, charId: charId, listId: listId},
|
||||
data: {spellId: id, charId: charId},
|
||||
heroId: id
|
||||
});
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ Template.skillDialog.helpers({
|
||||
return Characters.findOne(this.charId, {fields:{_id: 1}});
|
||||
},
|
||||
sourceName: function(){
|
||||
var id = this.sourceId;
|
||||
var id = this.parent.id;
|
||||
if(!id) return;
|
||||
switch(this.type){
|
||||
case "feature":
|
||||
|
||||
@@ -14,7 +14,7 @@ var joinWithDefaultKeys = function(keys){
|
||||
'restoredBy'
|
||||
];
|
||||
return _.union(keys, defaultKeys);
|
||||
}
|
||||
};
|
||||
|
||||
var limitModifierToKeys = function(modifier, keys){
|
||||
if(!modifier) return;
|
||||
@@ -24,7 +24,23 @@ var limitModifierToKeys = function(modifier, keys){
|
||||
if(_.isEmpty(modifier.$set)) delete modifier.$set;
|
||||
if(_.isEmpty(modifier.$unset)) delete modifier.$unset;
|
||||
return modifier;
|
||||
}
|
||||
};
|
||||
|
||||
var getParent = function(doc){
|
||||
if(!doc || !doc.parent) return;
|
||||
var parentCol = Meteor.isClient?
|
||||
window[doc.parent.collection] : global[doc.parent.collection];
|
||||
if (parentCol)
|
||||
return parentCol.findOne(doc.parent.id, {removed: true});
|
||||
};
|
||||
|
||||
var inheritParentProperties = function(doc, collection){
|
||||
var parent = getParent(doc);
|
||||
if(!parent) throw new Meteor.Error('Parenting Error',
|
||||
'Document\'s parent does not exist');
|
||||
var handMeDowns = _.pick(parent, collection.inheritedKeys);
|
||||
collection.update(doc._id, {$set: handMeDowns});
|
||||
};
|
||||
|
||||
var childCollections = [];
|
||||
|
||||
@@ -34,25 +50,23 @@ makeChild = function(collection, inheritedKeys){
|
||||
collection.helpers({
|
||||
//returns the parent even if it's removed
|
||||
getParent: function(){
|
||||
var parentCol = Meteor.isClient?
|
||||
window[this.parent.collection] : global[this.parent.collection];
|
||||
if (parentCol)
|
||||
return parentCol.findOne(this.parent.id, {removed: true});
|
||||
return getParent(this);
|
||||
},
|
||||
getParentCollection: function(){
|
||||
return Meteor.isClient?
|
||||
window[this.parent.collection] : global[this.parent.collection];
|
||||
}
|
||||
});
|
||||
|
||||
//when created, inherit parent properties
|
||||
collection.after.insert(function(userId, doc){
|
||||
inheritParentProperties(doc, collection);
|
||||
});
|
||||
|
||||
//when we change parents, inherit its properties
|
||||
collection.after.update(function (userId, doc, fieldNames, modifier, options) {
|
||||
if(modifier && modifier.$set && modifier.$set.parent){
|
||||
var parent = doc.getParent();
|
||||
if(!parent) throw new Meteor.Error('Parenting Error',
|
||||
'Document\'s parent does not exist');
|
||||
var handMeDowns = _.pick(parent, collection.inheritedKeys);
|
||||
collection.update(doc._id, {$set: handMeDowns});
|
||||
inheritParentProperties(doc, collection);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user