mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
BUGFIX: groups page wasn't working
This commit is contained in:
parent
b9bda77abd
commit
92cb52e76e
5 changed files with 57 additions and 65 deletions
|
@ -106,11 +106,10 @@ Discourse.Group = Discourse.Model.extend({
|
|||
alias_level: this.get('alias_level'),
|
||||
usernames: this.get('usernames')
|
||||
}
|
||||
},
|
||||
complete: function(){
|
||||
group.set('disableSave', false);
|
||||
}
|
||||
}).then(null, function(e){
|
||||
}).then(function(){
|
||||
group.set('disableSave', false);
|
||||
}, function(e){
|
||||
var message = $.parseJSON(e.responseText).errors;
|
||||
bootbox.alert(message);
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<ul>
|
||||
{{#each group in model}}
|
||||
<li>
|
||||
<a href="#" {{action "edit" group}} {{bindAttr class="group.active"}}>{{group.name}} <span class="count">{{group.userCountDisplay}}</span></a>
|
||||
<a href="#" {{action "edit" group}} {{bindAttr class="group.active"}}>{{group.name}} <span class="count">{{group.userCountDisplay}}</span></a>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
@ -25,8 +25,7 @@
|
|||
{{/if}}
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label">Group members
|
||||
</label>
|
||||
<label class="control-label">Group members</label>
|
||||
<div class="controls">
|
||||
{{userSelector usernames=usernames id="group-users" placeholderKey="admin.groups.selector_placeholder" tabindex="1" disabledBinding="automatic"}}
|
||||
</div>
|
||||
|
|
|
@ -47,7 +47,6 @@ function mapKeyPressToActualCharacter(isShiftKey, characterCode) {
|
|||
}
|
||||
|
||||
$.fn.autocomplete = function(options) {
|
||||
|
||||
var autocompletePlugin = this;
|
||||
|
||||
if (this.length === 0) return;
|
||||
|
@ -85,18 +84,14 @@ $.fn.autocomplete = function(options) {
|
|||
|
||||
var addInputSelectedItem = function(item) {
|
||||
var transformed;
|
||||
if (options.transformComplete) {
|
||||
transformed = options.transformComplete(item);
|
||||
}
|
||||
if (options.single){
|
||||
// dump what we have in single mode, just in case
|
||||
inputSelectedItems = [];
|
||||
}
|
||||
if (!_.isArray(transformed)) {
|
||||
transformed = [transformed || item];
|
||||
}
|
||||
|
||||
if (options.transformComplete) { transformed = options.transformComplete(item); }
|
||||
// dump what we have in single mode, just in case
|
||||
if (options.single) { inputSelectedItems = []; }
|
||||
if (!_.isArray(transformed)) { transformed = [transformed || item]; }
|
||||
|
||||
var divs = transformed.map(function(itm) {
|
||||
var d = $("<div class='item'><span>" + (itm) + "<a href='#'><i class='fa fa-times'></i></a></span></div>");
|
||||
var d = $("<div class='item'><span>" + itm + "<a href='#'><i class='fa fa-times'></i></a></span></div>");
|
||||
var prev = me.parent().find('.item:last');
|
||||
if (prev.length === 0) {
|
||||
me.parent().prepend(d);
|
||||
|
@ -104,12 +99,10 @@ $.fn.autocomplete = function(options) {
|
|||
prev.after(d);
|
||||
}
|
||||
inputSelectedItems.push(itm);
|
||||
return divs;
|
||||
return d[0];
|
||||
});
|
||||
|
||||
if (options.onChangeItems) {
|
||||
options.onChangeItems(inputSelectedItems);
|
||||
}
|
||||
|
||||
if (options.onChangeItems) { options.onChangeItems(inputSelectedItems); }
|
||||
|
||||
$(divs).find('a').click(function() {
|
||||
closeAutocomplete();
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
Discourse.UserSelector = Discourse.TextField.extend({
|
||||
|
||||
didInsertElement: function(){
|
||||
|
||||
var userSelectorView = this;
|
||||
var selected = [];
|
||||
didInsertElement: function() {
|
||||
var userSelectorView = this,
|
||||
selected = [];
|
||||
|
||||
$(this.get('element')).val(this.get('usernames')).autocomplete({
|
||||
template: Discourse.UserSelector.templateFunction(),
|
||||
|
@ -11,9 +10,10 @@ Discourse.UserSelector = Discourse.TextField.extend({
|
|||
disabled: this.get('disabled'),
|
||||
single: this.get('single'),
|
||||
allowAny: this.get('allowAny'),
|
||||
|
||||
dataSource: function(term) {
|
||||
var exclude = selected;
|
||||
if (userSelectorView.get('excludeCurrentUser')){
|
||||
if (userSelectorView.get('excludeCurrentUser')) {
|
||||
exclude = exclude.concat([Discourse.User.currentProp('username')]);
|
||||
}
|
||||
return Discourse.UserSearch.search({
|
||||
|
@ -23,13 +23,14 @@ Discourse.UserSelector = Discourse.TextField.extend({
|
|||
include_groups: userSelectorView.get('include_groups')
|
||||
});
|
||||
},
|
||||
|
||||
transformComplete: function(v) {
|
||||
if (v.username) {
|
||||
return v.username;
|
||||
} else {
|
||||
return v.usernames;
|
||||
}
|
||||
},
|
||||
if (v.username) {
|
||||
return v.username;
|
||||
} else {
|
||||
return v.usernames;
|
||||
}
|
||||
},
|
||||
|
||||
onChangeItems: function(items) {
|
||||
items = _.map(items, function(i) {
|
||||
|
@ -52,41 +53,41 @@ Discourse.UserSelector = Discourse.TextField.extend({
|
|||
|
||||
});
|
||||
|
||||
Handlebars.registerHelper("showMax", function(context, block){
|
||||
Handlebars.registerHelper("showMax", function(context, block) {
|
||||
var maxLength = parseInt(block.hash.max) || 3;
|
||||
if (context.length > maxLength){
|
||||
return context.slice(0, maxLength).join(", ") + ", +" + (context.length - maxLength);
|
||||
} else {
|
||||
return context.join(", ");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
Discourse.UserSelector.reopenClass({
|
||||
// I really want to move this into a template file, but I need a handlebars template here, not an ember one
|
||||
templateFunction: function(){
|
||||
this.compiled = this.compiled || Handlebars.compile("<div class='autocomplete'>" +
|
||||
"<ul>" +
|
||||
"{{#each options.users}}" +
|
||||
"<li>" +
|
||||
"<a href='#'>{{avatar this imageSize=\"tiny\"}} " +
|
||||
"<span class='username'>{{this.username}}</span> " +
|
||||
"<span class='name'>{{this.name}}</span></a>" +
|
||||
"</li>" +
|
||||
"{{/each}}" +
|
||||
"{{#if options.groups}}" +
|
||||
"{{#if options.users}}<hr>{{/if}}"+
|
||||
"{{#each options.groups}}" +
|
||||
"<li>" +
|
||||
"<a href=''><i class='icon-group'></i>" +
|
||||
"<span class='username'>{{this.name}}</span> " +
|
||||
"<span class='name'>{{showMax this.usernames max=3}}</span></a>" +
|
||||
"</li>" +
|
||||
"{{/each}}" +
|
||||
"{{/if}}" +
|
||||
"</ul>" +
|
||||
"</div>");
|
||||
templateFunction: function() {
|
||||
this.compiled = this.compiled || Handlebars.compile(
|
||||
"<div class='autocomplete'>" +
|
||||
"<ul>" +
|
||||
"{{#each options.users}}" +
|
||||
"<li>" +
|
||||
"<a href='#'>{{avatar this imageSize=\"tiny\"}} " +
|
||||
"<span class='username'>{{this.username}}</span> " +
|
||||
"<span class='name'>{{this.name}}</span></a>" +
|
||||
"</li>" +
|
||||
"{{/each}}" +
|
||||
"{{#if options.groups}}" +
|
||||
"{{#if options.users}}<hr>{{/if}}"+
|
||||
"{{#each options.groups}}" +
|
||||
"<li>" +
|
||||
"<a href=''><i class='icon-group'></i>" +
|
||||
"<span class='username'>{{this.name}}</span> " +
|
||||
"<span class='name'>{{showMax this.usernames max=3}}</span>" +
|
||||
"</a>" +
|
||||
"</li>" +
|
||||
"{{/each}}" +
|
||||
"{{/if}}" +
|
||||
"</ul>" +
|
||||
"</div>");
|
||||
return this.compiled;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -110,8 +110,8 @@ class Group < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.search_group(name, current_user)
|
||||
|
||||
levels = [ALIAS_LEVELS[:everyone]]
|
||||
|
||||
if current_user.admin?
|
||||
levels = [ALIAS_LEVELS[:everyone],
|
||||
ALIAS_LEVELS[:only_admins],
|
||||
|
@ -123,11 +123,11 @@ class Group < ActiveRecord::Base
|
|||
ALIAS_LEVELS[:members_mods_and_admins]]
|
||||
end
|
||||
|
||||
return Group.where("name LIKE :term_like AND (" +
|
||||
" alias_level in (:levels)" +
|
||||
" OR (alias_level = #{ALIAS_LEVELS[:everyone]} AND id in (" +
|
||||
Group.where("name LIKE :term_like AND (" +
|
||||
" alias_level in (:levels)" +
|
||||
" OR (alias_level = #{ALIAS_LEVELS[:everyone]} AND id in (" +
|
||||
"SELECT group_id FROM group_users WHERE user_id= :user_id)" +
|
||||
")" +
|
||||
")" +
|
||||
")", term_like: "#{name.downcase}%", levels: levels, user_id: current_user.id)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue