CTRL-dragging now copies spells
This commit is contained in:
@@ -87,16 +87,20 @@ Spells.deny(CHARACTER_SUBSCHEMA_DENY);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
var checkMovePermission = function(spellId, parent) {
|
var checkMovePermission = function(spellId, parent, destinationOnly) {
|
||||||
var spell = Spells.findOne(spellId);
|
var spell = Spells.findOne(spellId);
|
||||||
if (!spell)
|
if (!spell)
|
||||||
throw new Meteor.Error("No such spell",
|
throw new Meteor.Error("No such spell",
|
||||||
"An spell could not be found to move");
|
"An spell could not be found to move");
|
||||||
//handle permissions
|
//handle permissions
|
||||||
var permission = Meteor.call("canWriteCharacter", spell.charId);
|
var permission;
|
||||||
if (!permission){
|
|
||||||
throw new Meteor.Error("Access denied",
|
if (!destinationOnly) { //if we're not modifying the origin, only the destination
|
||||||
"Not permitted to move spells from this character");
|
permission = Meteor.call("canWriteCharacter", spell.charId);
|
||||||
|
if (!permission){
|
||||||
|
throw new Meteor.Error("Access denied",
|
||||||
|
"Not permitted to move spells from this character");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (parent.collection === "Characters"){
|
if (parent.collection === "Characters"){
|
||||||
permission = Meteor.call("canWriteCharacter", parent.id);
|
permission = Meteor.call("canWriteCharacter", parent.id);
|
||||||
@@ -126,33 +130,55 @@ var checkMovePermission = function(spellId, parent) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var moveSpell = function(spellId, parentCollection, parentId) {
|
var moveSpell = function(spellId, parentCollection, parentId) { //moving spells between characters is NOT YET SUPPORTED :O
|
||||||
var spell = Spells.findOne(spellId);
|
var spell = Spells.findOne(spellId);
|
||||||
if (!spell) return;
|
if (!spell) return;
|
||||||
parentCollection = parentCollection || spell.parent.collection;
|
parentCollection = parentCollection || spell.parent.collection;
|
||||||
parentId = parentId || spell.parent.id;
|
parentId = parentId || spell.parent.id;
|
||||||
|
|
||||||
if (Meteor.isServer) {
|
if (Meteor.isServer) {
|
||||||
checkMovePermission(spellId, {collection: parentCollection, id: parentId});
|
checkMovePermission(spellId, {collection: parentCollection, id: parentId}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the spell provided the update will actually change something
|
||||||
|
if (
|
||||||
|
spell.parent.collection !== parentCollection ||
|
||||||
|
spell.parent.id !== parentId
|
||||||
|
){
|
||||||
|
Spells.update(
|
||||||
|
spellId,
|
||||||
|
{$set: {
|
||||||
|
"parent.collection": parentCollection,
|
||||||
|
"parent.id": parentId,
|
||||||
|
}}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var copySpell = function(spellId, parentCollection, parentId) {
|
||||||
|
var spell = Spells.findOne(spellId);
|
||||||
|
if (!spell) return;
|
||||||
|
parentCollection = parentCollection || spell.parent.collection;
|
||||||
|
parentId = parentId || spell.parent.id;
|
||||||
|
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
checkMovePermission(spellId, {collection: parentCollection, id: parentId}, true); //we're only reading from the source character
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (spell.parentCollection == "Characters") { //then we are moving the spell to a different character.
|
if (spell.parentCollection == "Characters") { //then we are copying the spell to a different character.
|
||||||
|
//TODO: handle this
|
||||||
} else { //else we are moving the spell within the same character
|
} else { //else we are copying the spell within the same character
|
||||||
//update the spell provided the update will actually change something
|
newSpell = _.clone(spell);
|
||||||
if (
|
delete newSpell._id;
|
||||||
spell.parent.collection !== parentCollection ||
|
newSpellId = Spells.insert(newSpell); //add a new copy of the spell
|
||||||
spell.parent.id !== parentId
|
Spells.update(
|
||||||
){
|
newSpellId,
|
||||||
Spells.update(
|
{$set: {
|
||||||
spellId,
|
"parent.collection": parentCollection,
|
||||||
{$set: {
|
"parent.id": parentId,
|
||||||
"parent.collection": parentCollection,
|
}}
|
||||||
"parent.id": parentId,
|
);
|
||||||
}}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -163,4 +189,9 @@ Meteor.methods({
|
|||||||
check(spellListId, String);
|
check(spellListId, String);
|
||||||
moveSpell(spellId, "SpellLists", spellListId);
|
moveSpell(spellId, "SpellLists", spellListId);
|
||||||
},
|
},
|
||||||
|
copySpellToList: function(spellId, spellListId) {
|
||||||
|
check(spellId, String);
|
||||||
|
check(spellListId, String);
|
||||||
|
copySpell(spellId, "SpellLists", spellListId);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
@@ -352,7 +352,11 @@ Template.layout.events({
|
|||||||
"drop .spellList": function(event, instance){
|
"drop .spellList": function(event, instance){
|
||||||
var spellId = event.originalEvent.dataTransfer.getData("dicecloud-id/spells");
|
var spellId = event.originalEvent.dataTransfer.getData("dicecloud-id/spells");
|
||||||
//move spell to new list
|
//move spell to new list
|
||||||
Meteor.call("moveSpellToList", spellId, this._id);
|
if (event.ctrlKey){
|
||||||
|
Meteor.call("copySpellToList", spellId, this._id);
|
||||||
|
} else {
|
||||||
|
Meteor.call("moveSpellToList", spellId, this._id);
|
||||||
|
}
|
||||||
Session.set("inventory.dragSpellId", null);
|
Session.set("inventory.dragSpellId", null);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user