Finished implementing basic sharing
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
html /deep/ .red-button {
|
||||
html /deep/ .red-button:not([disabled]) {
|
||||
background: #d23f31;
|
||||
color: #fff;
|
||||
margin-top: 16px;
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
<template name="shareDialog">
|
||||
<div>
|
||||
<div>
|
||||
<div class="subhead">
|
||||
Can View
|
||||
</div>
|
||||
{{#each readers}}
|
||||
|
||||
{{this}}<br>
|
||||
{{/each}}
|
||||
<div class="subhead">
|
||||
Can Edit
|
||||
</div>
|
||||
{{#each writers}}
|
||||
|
||||
{{this}}<br>
|
||||
{{/each}}
|
||||
</div>
|
||||
<paper-input id="userNameOrEmailInput" label="Username or email" floatinglabel></paper-input>
|
||||
<paper-input id="userNameOrEmailInput" label="Username or email" floatinglabel></paper-input><br>
|
||||
{{#if userFindError}}<p style="color: red;">{{userFindError}}</p>{{/if}}
|
||||
<paper-radio-group id="accessLevelMenu" selected="read">
|
||||
<paper-radio-button name="read" label="View Only"></paper-radio-button>
|
||||
<paper-radio-button name="write" label="Can Edit"></paper-radio-button>
|
||||
</paper-radio-group>
|
||||
<br>
|
||||
<paper-dropdown-menu id="accessLevelDropdown" label="Access Level">
|
||||
<paper-dropdown layered class="dropdown">
|
||||
<core-menu id="accessLevelMenu" class="menu" selected="read" on-tap="onStatMenuTap">
|
||||
<paper-item name="read"> View Only </paper-item>
|
||||
<paper-item name="write"> Can Edit </paper-item>
|
||||
</core-menu>
|
||||
</paper-dropdown>
|
||||
</paper-dropdown-menu>
|
||||
<br>
|
||||
<paper-button id="shareButton" class="red-button" raised>Share</paper-button>
|
||||
<paper-button id="shareButton" class="red-button" raised disabled={{shareButtonDisabled}}>Share</paper-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,29 +1,55 @@
|
||||
Template.shareDialog.helpers({
|
||||
Template.shareDialog.onCreated(function(){
|
||||
this.userId = new ReactiveVar();
|
||||
});
|
||||
|
||||
Template.shareDialog.helpers({
|
||||
readers: function(){
|
||||
var char = Characters.findOne(this._id, {fields: {readers: 1}});
|
||||
return char && char.readers;
|
||||
},
|
||||
writers: function(){
|
||||
var char = Characters.findOne(this._id, {fields: {writers: 1}});
|
||||
return char && char.writers;
|
||||
},
|
||||
shareButtonDisabled: function(){
|
||||
return !Template.instance().userId.get();
|
||||
},
|
||||
userFindError: function(){
|
||||
if (!Template.instance().userId.get()){
|
||||
return "User not found";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Template.shareDialog.events({
|
||||
"tap #shareButton": function(event, instance){
|
||||
var self = this;
|
||||
"input #userNameOrEmailInput, change #userNameOrEmailInput": function(event, instance){
|
||||
var userName = instance.find("#userNameOrEmailInput").value;
|
||||
var permission = instance.find("#accessLevelMenu").value;
|
||||
Meteor.call("getUserId", userName, function (err, result) {
|
||||
if(err){
|
||||
this.userFindError = true;
|
||||
} else{
|
||||
if(permission === "write"){
|
||||
Characters.update(self._id, {
|
||||
$push: {writers: result},
|
||||
$pull: {readers: result}
|
||||
});
|
||||
} else {
|
||||
Characters.update(self._id, {
|
||||
$push: {readers: result},
|
||||
$pull: {writers: result}
|
||||
});
|
||||
}
|
||||
GlobalUI.closeDialog();
|
||||
}
|
||||
});
|
||||
instance.userId.set(undefined);
|
||||
Meteor.call("getUserId", userName, function (err, result) {
|
||||
if(err){
|
||||
console.error(err);
|
||||
} else{
|
||||
console.log(result);
|
||||
instance.userId.set(result);
|
||||
}
|
||||
});
|
||||
},
|
||||
"tap #shareButton": function(event, instance){
|
||||
var self = this;
|
||||
var permission = instance.find("#accessLevelMenu").selected;
|
||||
if(!permission) throw "no permission set";
|
||||
var userId = instance.userId.get();
|
||||
if(!userId) return;
|
||||
if(permission === "write"){
|
||||
Characters.update(self._id, {
|
||||
$addToSet: {writers: userId},
|
||||
$pull: {readers: userId}
|
||||
});
|
||||
} else {
|
||||
Characters.update(self._id, {
|
||||
$addToSet: {readers: userId},
|
||||
$pull: {writers: userId}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
<link rel="import" href="/components/paper-input/paper-input-decorator.html">
|
||||
<link rel="import" href="/components/paper-item/paper-item.html">
|
||||
<link rel="import" href="/components/paper-menu-button/paper-menu-button.html">
|
||||
<link rel="import" href="/components/paper-radio-button/paper-radio-button.html">
|
||||
<link rel="import" href="/components/paper-radio-group/paper-radio-group.html">
|
||||
<link rel="import" href="/components/paper-shadow/paper-shadow.html">
|
||||
<link rel="import" href="/components/paper-spinner/paper-spinner.html">
|
||||
<link rel="import" href="/components/paper-tabs/paper-tabs.html">
|
||||
|
||||
7
rpg-docs/lib/functions/shareCharacter.js
Normal file
7
rpg-docs/lib/functions/shareCharacter.js
Normal file
@@ -0,0 +1,7 @@
|
||||
Meteor.methods({
|
||||
"getUserId": function(username){
|
||||
if(!username) return;
|
||||
var user = Meteor.users.findOne({$or: [{username: username}, {"emails.address": username}]});
|
||||
return user && user._id;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user