From bf032bcdf3cf864a0863bac05e64a388ea30e8e9 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Tue, 12 May 2015 11:34:37 +0200 Subject: [PATCH] Now only show edit and add buttons to writers, not readers --- rpg-docs/Model/Character/Effects.js | 8 ++--- rpg-docs/Routes/Routes.js | 2 +- .../client/globalHelpers/canEditCharacter.js | 6 ++++ .../views/character/characterSheet.html | 30 +++++++++++-------- .../client/views/character/characterSheet.js | 2 +- .../views/character/features/features.html | 18 ++++++----- .../views/character/inventory/inventory.html | 10 ++++--- .../views/character/journal/journal.html | 2 ++ .../client/views/character/spells/spells.html | 10 ++++--- .../paperTemplates/baseDialog/baseDialog.html | 4 +-- .../paperTemplates/baseDialog/baseDialog.js | 12 ++++++++ 11 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 rpg-docs/client/globalHelpers/canEditCharacter.js diff --git a/rpg-docs/Model/Character/Effects.js b/rpg-docs/Model/Character/Effects.js index 9ce256c5..2c8b5367 100644 --- a/rpg-docs/Model/Character/Effects.js +++ b/rpg-docs/Model/Character/Effects.js @@ -61,7 +61,6 @@ Effects.attachSchema(Schemas.Effect); if (Meteor.isServer) Characters.after.insert(function(userId, char) { Effects.insert({ charId: char._id, - type: "inate", name: "Constitution modifier for each level", stat: "hitPoints", operation: "add", @@ -69,11 +68,11 @@ if (Meteor.isServer) Characters.after.insert(function(userId, char) { parent: { id: char._id, collection: "Characters", + group: "Inate", }, }); Effects.insert({ charId: char._id, - type: "inate", name: "Proficiency bonus by level", stat: "proficiencyBonus", operation: "add", @@ -81,11 +80,11 @@ if (Meteor.isServer) Characters.after.insert(function(userId, char) { parent: { id: char._id, collection: "Characters", + group: "Inate", }, }); Effects.insert({ charId: char._id, - type: "inate", name: "Dexterity Armor Bonus", stat: "armor", operation: "add", @@ -93,11 +92,11 @@ if (Meteor.isServer) Characters.after.insert(function(userId, char) { parent: { id: char._id, collection: "Characters", + group: "Inate", }, }); Effects.insert({ charId: char._id, - type: "inate", name: "Natural Armor", stat: "armor", operation: "base", @@ -105,6 +104,7 @@ if (Meteor.isServer) Characters.after.insert(function(userId, char) { parent: { id: char._id, collection: "Characters", + group: "Inate", }, }); }); diff --git a/rpg-docs/Routes/Routes.js b/rpg-docs/Routes/Routes.js index 0c2a405d..6fc59ca2 100644 --- a/rpg-docs/Routes/Routes.js +++ b/rpg-docs/Routes/Routes.js @@ -53,7 +53,7 @@ Router.map(function() { data: function() { var data = Characters.findOne( {_id: this.params._id}, - {fields: {_id: 1, name: 1, color: 1}} + {fields: {_id: 1, name: 1, color: 1, writers: 1, readers: 1}} ); return data; }, diff --git a/rpg-docs/client/globalHelpers/canEditCharacter.js b/rpg-docs/client/globalHelpers/canEditCharacter.js new file mode 100644 index 00000000..95ba2ec6 --- /dev/null +++ b/rpg-docs/client/globalHelpers/canEditCharacter.js @@ -0,0 +1,6 @@ +Template.registerHelper("canEditCharacter", function(charId) { + var char = Characters.findOne(charId) + var userId = Meteor.userId(); + return char.owner === userId || + _.contains(char.writers, userId); +}); diff --git a/rpg-docs/client/views/character/characterSheet.html b/rpg-docs/client/views/character/characterSheet.html index 9ccb8270..9c4867e3 100644 --- a/rpg-docs/client/views/character/characterSheet.html +++ b/rpg-docs/client/views/character/characterSheet.html @@ -5,18 +5,24 @@
{{name}}
-
- {{> colorDropdown}} -
- - - - - Delete - Share - - - + {{#if canEditCharacter _id}} +
+ {{> colorDropdown}} +
+ + + + + + Delete + + + Share + + + + + {{/if}}
Stats diff --git a/rpg-docs/client/views/character/characterSheet.js b/rpg-docs/client/views/character/characterSheet.js index 03590890..a0192af7 100644 --- a/rpg-docs/client/views/character/characterSheet.js +++ b/rpg-docs/client/views/character/characterSheet.js @@ -13,7 +13,7 @@ var getTab = function(charId){ Template.characterSheet.helpers({ selectedTab: function(){ return getTab(this._id); - } + }, }); Template.characterSheet.events({ diff --git a/rpg-docs/client/views/character/features/features.html b/rpg-docs/client/views/character/features/features.html index a18b5184..86a9928c 100644 --- a/rpg-docs/client/views/character/features/features.html +++ b/rpg-docs/client/views/character/features/features.html @@ -104,14 +104,16 @@
- + {{#if canEditCharacter _id}} + + {{/if}} diff --git a/rpg-docs/client/views/character/inventory/inventory.html b/rpg-docs/client/views/character/inventory/inventory.html index 2ffc2ab1..fddbfcb6 100644 --- a/rpg-docs/client/views/character/inventory/inventory.html +++ b/rpg-docs/client/views/character/inventory/inventory.html @@ -77,10 +77,12 @@
- - - - + {{#if canEditCharacter _id}} + + + + + {{/if}} diff --git a/rpg-docs/client/views/character/journal/journal.html b/rpg-docs/client/views/character/journal/journal.html index 384a7bc1..d283493c 100644 --- a/rpg-docs/client/views/character/journal/journal.html +++ b/rpg-docs/client/views/character/journal/journal.html @@ -68,6 +68,7 @@
+ {{#if canEditCharacter _id}} + {{/if}} \ No newline at end of file diff --git a/rpg-docs/client/views/character/spells/spells.html b/rpg-docs/client/views/character/spells/spells.html index 58661059..9da79085 100644 --- a/rpg-docs/client/views/character/spells/spells.html +++ b/rpg-docs/client/views/character/spells/spells.html @@ -91,8 +91,10 @@
- - - - + {{#if canEditCharacter _id}} + + + + + {{/if}} \ No newline at end of file diff --git a/rpg-docs/client/views/paperTemplates/baseDialog/baseDialog.html b/rpg-docs/client/views/paperTemplates/baseDialog/baseDialog.html index ad40f9a7..04de2d63 100644 --- a/rpg-docs/client/views/paperTemplates/baseDialog/baseDialog.html +++ b/rpg-docs/client/views/paperTemplates/baseDialog/baseDialog.html @@ -20,12 +20,12 @@ aria-label="Delete Feature" noink> {{else}} - {{#unless hideEdit}} + {{#if showEdit}} - {{/unless}} + {{/if}} {{/if}}
diff --git a/rpg-docs/client/views/paperTemplates/baseDialog/baseDialog.js b/rpg-docs/client/views/paperTemplates/baseDialog/baseDialog.js index 8d12bc0d..fb30542d 100644 --- a/rpg-docs/client/views/paperTemplates/baseDialog/baseDialog.js +++ b/rpg-docs/client/views/paperTemplates/baseDialog/baseDialog.js @@ -11,6 +11,18 @@ Template.baseDialog.helpers({ editing: function(){ return Template.instance().editing.get(); }, + showEdit: function() { + if (this.hideEdit) return false; + var charId = Template.parentData().charId; + if (charId){ + var char = Characters.findOne(charId); + var userId = Meteor.userId(); + if (char && userId) + return char.owner === userId || + _.contains(char.writers, userId); + } + return true; + }, }); Template.baseDialog.events({