Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 9442900

Browse files
committed
Updated moderator list is correctly fetched after adding or removing a moderator via the add/remove moderator button. The GetIsModerator function has been shortened, and some logic was moved to the template.
Based on a bunch of advice from jjeffryes. Thanks!
1 parent f38a5cd commit 9442900

File tree

2 files changed

+53
-47
lines changed

2 files changed

+53
-47
lines changed

js/templates/userPage.html

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,28 @@ <h1 class="page-userNameLarge floatLeft fancy-heading fontSize20 colorWhiteForce
137137
</span>
138138
</a>
139139
</div>
140-
<div class="ctrlGroup hide js-notOwnPageButtons js-userPageControls">
141-
<a class="btn btn-txt custCol-primary hide js-addmoderator">
142-
<span class="ion-person-add fontSize11 marginRight2 textOpacity1"></span>
143-
<%= polyglot.t('AddModerator') %>
144-
</a>
145-
<a class="btn btn-txt custCol-primary hide confirmable js-removemoderator">
146-
<span class="preSpacer">
147-
<span class="ion-eye-disabled fontSize11 marginRight2 textOpacity1"></span>
148-
<%= polyglot.t('RemoveModerator') %>
149-
</span>
150-
<span class="preConfirm">
151-
<span class="ion-trash-b fontSize11 marginRight2 textOpacity1"></span>
152-
<%= polyglot.t('RemoveModerator') %>
153-
</span>
154-
<span class="postConfirm">
155-
<span class="ion-trash-b fontSize11 marginRight2 textOpacity1"></span>
156-
<%= polyglot.t('ConfirmRemoveModerator') %>
157-
</span>
158-
</a>
159-
</div>
140+
<% if(ob.page.profile.moderator) { %>
141+
<div class="ctrlGroup hide js-notOwnPageButtons js-userPageControls">
142+
<a class="btn btn-txt custCol-primary hide js-addmoderator">
143+
<span class="ion-person-add fontSize11 marginRight2 textOpacity1"></span>
144+
<%= polyglot.t('AddModerator') %>
145+
</a>
146+
<a class="btn btn-txt custCol-primary hide confirmable js-removemoderator">
147+
<span class="preSpacer">
148+
<span class="ion-eye-disabled fontSize11 marginRight2 textOpacity1"></span>
149+
<%= polyglot.t('RemoveModerator') %>
150+
</span>
151+
<span class="preConfirm">
152+
<span class="ion-trash-b fontSize11 marginRight2 textOpacity1"></span>
153+
<%= polyglot.t('RemoveModerator') %>
154+
</span>
155+
<span class="postConfirm">
156+
<span class="ion-trash-b fontSize11 marginRight2 textOpacity1"></span>
157+
<%= polyglot.t('ConfirmRemoveModerator') %>
158+
</span>
159+
</a>
160+
</div>
161+
<% } %>
160162
<div class="ctrlGroup hide js-notOwnPageButtons js-userPageControls">
161163
<a class="btn btn-txt custCol-primary js-message">
162164
<span class="ion-email fontSize11 marginRight2 textOpacity1"></span>

js/views/userPageVw.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -708,20 +708,8 @@ module.exports = baseVw.extend({
708708
},
709709

710710
getIsModerator: function () {
711-
if(this.userProfile.get('profile').moderator == true && this.options.ownPage == false && this.model.get('user').vendor) {
712-
var pageGuid = this.userProfile.get('profile').guid;
713-
var mods = this.model.get('user').moderators;
714-
var found = false;
715-
var self = this;
716-
this.toggleModeratorButtons(false);
717-
__.each(mods, function(mod) {
718-
if(mod.guid == pageGuid || mod == pageGuid) {
719-
found = true;
720-
}
721-
});
722-
if(found == true) {
723-
this.toggleModeratorButtons(true);
724-
}
711+
if(this.options.ownPage == false && this.model.get('user').vendor) {
712+
this.toggleModeratorButtons(Boolean(__.findWhere(this.model.get('user').moderators, {guid: this.pageID})));
725713
}
726714
},
727715

@@ -1465,19 +1453,27 @@ module.exports = baseVw.extend({
14651453
user.moderators = modList.moderators;
14661454

14671455
saveToAPI('', user, user.serverUrl + "settings",
1468-
function(){
1469-
// confirmed
1470-
$targ.removeClass('loading');
1471-
},
1472-
function(){
1473-
// failed
1474-
}, modList,'',
1475-
function(){
1476-
// invalid
1477-
}).always(function(){
1478-
$targ.removeClass('loading');
1479-
self.getIsModerator();
1456+
function(){
1457+
// confirmed
1458+
$targ.removeClass('loading');
1459+
},
1460+
function(){
1461+
// failed
1462+
}, modList,'',
1463+
function(){
1464+
// invalid
1465+
}).always(function(){
1466+
$targ.removeClass('loading');
1467+
self.options.userModel.fetch({
1468+
success: function(model, response) {
1469+
if (self.isRemoved()) return;
1470+
var user = self.model.get('user');
1471+
user.moderators = model.get('moderators');
1472+
user.moderator_guids = model.get('moderator_guids');
1473+
self.getIsModerator();
1474+
}
14801475
});
1476+
});
14811477
},
14821478

14831479
removeModeratorClick: function(e){
@@ -1513,7 +1509,15 @@ module.exports = baseVw.extend({
15131509
// invalid
15141510
}).always(function(){
15151511
$targ.removeClass('loading');
1516-
self.getIsModerator();
1512+
self.options.userModel.fetch({
1513+
success: function(model, response) {
1514+
if (self.isRemoved()) return;
1515+
var user = self.model.get('user');
1516+
user.moderators = model.get('moderators');
1517+
user.moderator_guids = model.get('moderator_guids');
1518+
self.getIsModerator();
1519+
}
1520+
});
15171521
});
15181522
} else {
15191523
$targ.addClass('confirm');

0 commit comments

Comments
 (0)