mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:42:45 +08:00
FEATURE: Add membership request to groups page.
This commit is contained in:
parent
50aa9ba396
commit
7888a16374
|
@ -0,0 +1,45 @@
|
|||
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
@computed("model.public")
|
||||
canJoinGroup(publicGroup) {
|
||||
return !!(this.currentUser) && publicGroup;
|
||||
},
|
||||
|
||||
@computed('model.allow_membership_requests', 'model.alias_level')
|
||||
canRequestMembership(allowMembershipRequests, aliasLevel) {
|
||||
return !!(this.currentUser) && allowMembershipRequests && aliasLevel === 99;
|
||||
},
|
||||
|
||||
actions: {
|
||||
joinGroup() {
|
||||
this.set('updatingMembership', true);
|
||||
const model = this.get('model');
|
||||
|
||||
model.addMembers(this.currentUser.get('username')).then(() => {
|
||||
model.set('is_group_user', true);
|
||||
}).catch(popupAjaxError).finally(() => {
|
||||
this.set('updatingMembership', false);
|
||||
});
|
||||
},
|
||||
|
||||
leaveGroup() {
|
||||
this.set('updatingMembership', true);
|
||||
const model = this.get('model');
|
||||
|
||||
model.removeMember(this.currentUser).then(() => {
|
||||
model.set('is_group_user', false);
|
||||
}).catch(popupAjaxError).finally(() => {
|
||||
this.set('updatingMembership', false);
|
||||
});
|
||||
},
|
||||
|
||||
requestMembership() {
|
||||
const groupName = this.get('model.name');
|
||||
const title = I18n.t('groups.request_membership_pm.title');
|
||||
const body = I18n.t('groups.request_membership_pm.body', { groupName });
|
||||
this.transitionToRoute(`/new-message?groupname=${groupName}&title=${title}&body=${body}`);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -18,16 +18,6 @@ export default Ember.Controller.extend({
|
|||
this.get('model').findMembers({ order: this.get('order'), desc: this.get('desc') });
|
||||
},
|
||||
|
||||
@computed("model.public")
|
||||
canJoinGroup(publicGroup) {
|
||||
return !!(this.currentUser) && publicGroup;
|
||||
},
|
||||
|
||||
@computed('model.allow_membership_requests', 'model.alias_level')
|
||||
canRequestMembership(allowMembershipRequests, aliasLevel) {
|
||||
return !!(this.currentUser) && allowMembershipRequests && aliasLevel === 99;
|
||||
},
|
||||
|
||||
actions: {
|
||||
toggleActions() {
|
||||
this.toggleProperty("showActions");
|
||||
|
@ -44,35 +34,6 @@ export default Ember.Controller.extend({
|
|||
}
|
||||
},
|
||||
|
||||
requestMembership() {
|
||||
const groupName = this.get('model.name');
|
||||
const title = I18n.t('groups.request_membership_pm.title');
|
||||
const body = I18n.t('groups.request_membership_pm.body', { groupName });
|
||||
this.transitionToRoute(`/new-message?groupname=${groupName}&title=${title}&body=${body}`);
|
||||
},
|
||||
|
||||
joinGroup() {
|
||||
this.set('updatingMembership', true);
|
||||
const model = this.get('model');
|
||||
|
||||
model.addMembers(this.currentUser.get('username')).then(() => {
|
||||
model.set('is_group_user', true);
|
||||
}).catch(popupAjaxError).finally(() => {
|
||||
this.set('updatingMembership', false);
|
||||
});
|
||||
},
|
||||
|
||||
leaveGroup() {
|
||||
this.set('updatingMembership', true);
|
||||
const model = this.get('model');
|
||||
|
||||
model.removeMember(this.currentUser).then(() => {
|
||||
model.set('is_group_user', false);
|
||||
}).catch(popupAjaxError).finally(() => {
|
||||
this.set('updatingMembership', false);
|
||||
});
|
||||
},
|
||||
|
||||
loadMore() {
|
||||
if (this.get("loading")) { return; }
|
||||
if (this.get("model.members.length") >= this.get("model.user_count")) { return; }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { observes } from 'ember-addons/ember-computed-decorators';
|
||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
application: Ember.inject.controller(),
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
{{#if canJoinGroup}}
|
||||
{{#if model.is_group_user}}
|
||||
{{d-button action="leaveGroup"
|
||||
class="btn-danger group-index-leave"
|
||||
icon="minus"
|
||||
label="groups.leave"
|
||||
disabled=updatingMembership}}
|
||||
{{else}}
|
||||
{{d-button action="joinGroup"
|
||||
class="group-index-join"
|
||||
icon="plus"
|
||||
label="groups.join"
|
||||
disabled=updatingMembership}}
|
||||
{{/if}}
|
||||
{{else if canRequestMembership}}
|
||||
{{d-button action="requestMembership"
|
||||
class="group-index-request"
|
||||
icon="envelope"
|
||||
label="groups.request"}}
|
||||
{{else}}
|
||||
{{yield}}
|
||||
{{/if}}
|
|
@ -1,24 +1,5 @@
|
|||
{{#if model.members}}
|
||||
{{#if canJoinGroup}}
|
||||
{{#if model.is_group_user}}
|
||||
{{d-button action="leaveGroup"
|
||||
class="btn-danger group-index-leave"
|
||||
icon="minus"
|
||||
label="groups.leave"
|
||||
disabled=updatingMembership}}
|
||||
{{else}}
|
||||
{{d-button action="joinGroup"
|
||||
class="group-index-join"
|
||||
icon="plus"
|
||||
label="groups.join"
|
||||
disabled=updatingMembership}}
|
||||
{{/if}}
|
||||
{{else if canRequestMembership}}
|
||||
{{d-button action="requestMembership"
|
||||
class="group-index-request"
|
||||
icon="envelope"
|
||||
label="groups.request"}}
|
||||
{{/if}}
|
||||
{{group-membership-button model=model}}
|
||||
|
||||
{{#load-more selector=".group-members tr" action="loadMore"}}
|
||||
<table class='group-members'>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<div class="container group">
|
||||
{{#link-to "groups" class='group-breadcrumb'}}{{fa-icon 'arrow-left'}} {{i18n 'groups.index'}}{{/link-to}}
|
||||
|
||||
<div class='group-details-container'>
|
||||
<div class='group-info'>
|
||||
{{#if model.flair_url}}
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
<div class='container'>
|
||||
<table class="groups-table">
|
||||
<thead>
|
||||
<th>{{i18n "groups.name"}}</th>
|
||||
<th></th>
|
||||
<th>{{i18n "groups.user_count"}}</th>
|
||||
<th>{{i18n "groups.membership"}}</th>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
@ -41,6 +42,14 @@
|
|||
</td>
|
||||
|
||||
<td class="groups-user-count">{{group.user_count}}</td>
|
||||
|
||||
<td>
|
||||
{{#group-membership-button model=group}}
|
||||
{{d-button icon="ban"
|
||||
label=(if group.automatic 'groups.automatic_group' 'groups.closed_group')
|
||||
disabled=true}}
|
||||
{{/group-membership-button}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.group-breadcrumb {
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.group-info {
|
||||
width: 100%;
|
||||
|
||||
|
@ -44,10 +49,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
.group-index-request, .group-index-join, .group-index-leave {
|
||||
float: right;
|
||||
}
|
||||
|
||||
table.group-logs {
|
||||
width: 100%;
|
||||
|
||||
|
|
|
@ -8,10 +8,8 @@
|
|||
width: 100%;
|
||||
|
||||
th {
|
||||
border-bottom: 3px solid dark-light-diff($primary, $secondary, 90%, -60%);
|
||||
border-bottom: 1px solid dark-light-diff($primary, $secondary, 90%, -60%);
|
||||
padding: 5px 0px;
|
||||
color: dark-light-choose(scale-color($primary, $lightness: 50%), scale-color($secondary, $lightness: 50%));
|
||||
font-weight: normal;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
|
@ -32,6 +30,7 @@
|
|||
.groups-info-name {
|
||||
font-weight: bold;
|
||||
color: $primary;
|
||||
color: dark-light-choose(scale-color($primary, $lightness: 30%), scale-color($secondary, $lightness: 70%));
|
||||
}
|
||||
|
||||
.groups-info-full-name {
|
||||
|
|
|
@ -415,7 +415,10 @@ en:
|
|||
join: "Join Group"
|
||||
leave: "Leave Group"
|
||||
request: "Request to Join Group"
|
||||
automatic_group: Automatic Group
|
||||
closed_group: Closed Group
|
||||
allow_membership_requests: "Allow users to send membership requests to group owners (Requires everyone to be able to mention the group)"
|
||||
membership: "Membership"
|
||||
name: "Name"
|
||||
user_count: "Number of Members"
|
||||
bio: "About Group"
|
||||
|
|
Loading…
Reference in New Issue
Block a user