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'),
|
alias_level: this.get('alias_level'),
|
||||||
usernames: this.get('usernames')
|
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;
|
var message = $.parseJSON(e.responseText).errors;
|
||||||
bootbox.alert(message);
|
bootbox.alert(message);
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
{{#each group in model}}
|
{{#each group in model}}
|
||||||
<li>
|
<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>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -25,8 +25,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">Group members
|
<label class="control-label">Group members</label>
|
||||||
</label>
|
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{userSelector usernames=usernames id="group-users" placeholderKey="admin.groups.selector_placeholder" tabindex="1" disabledBinding="automatic"}}
|
{{userSelector usernames=usernames id="group-users" placeholderKey="admin.groups.selector_placeholder" tabindex="1" disabledBinding="automatic"}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -47,7 +47,6 @@ function mapKeyPressToActualCharacter(isShiftKey, characterCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$.fn.autocomplete = function(options) {
|
$.fn.autocomplete = function(options) {
|
||||||
|
|
||||||
var autocompletePlugin = this;
|
var autocompletePlugin = this;
|
||||||
|
|
||||||
if (this.length === 0) return;
|
if (this.length === 0) return;
|
||||||
|
@ -85,18 +84,14 @@ $.fn.autocomplete = function(options) {
|
||||||
|
|
||||||
var addInputSelectedItem = function(item) {
|
var addInputSelectedItem = function(item) {
|
||||||
var transformed;
|
var transformed;
|
||||||
if (options.transformComplete) {
|
|
||||||
transformed = options.transformComplete(item);
|
if (options.transformComplete) { transformed = options.transformComplete(item); }
|
||||||
}
|
// dump what we have in single mode, just in case
|
||||||
if (options.single){
|
if (options.single) { inputSelectedItems = []; }
|
||||||
// dump what we have in single mode, just in case
|
if (!_.isArray(transformed)) { transformed = [transformed || item]; }
|
||||||
inputSelectedItems = [];
|
|
||||||
}
|
|
||||||
if (!_.isArray(transformed)) {
|
|
||||||
transformed = [transformed || item];
|
|
||||||
}
|
|
||||||
var divs = transformed.map(function(itm) {
|
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');
|
var prev = me.parent().find('.item:last');
|
||||||
if (prev.length === 0) {
|
if (prev.length === 0) {
|
||||||
me.parent().prepend(d);
|
me.parent().prepend(d);
|
||||||
|
@ -104,12 +99,10 @@ $.fn.autocomplete = function(options) {
|
||||||
prev.after(d);
|
prev.after(d);
|
||||||
}
|
}
|
||||||
inputSelectedItems.push(itm);
|
inputSelectedItems.push(itm);
|
||||||
return divs;
|
return d[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (options.onChangeItems) {
|
if (options.onChangeItems) { options.onChangeItems(inputSelectedItems); }
|
||||||
options.onChangeItems(inputSelectedItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
$(divs).find('a').click(function() {
|
$(divs).find('a').click(function() {
|
||||||
closeAutocomplete();
|
closeAutocomplete();
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
Discourse.UserSelector = Discourse.TextField.extend({
|
Discourse.UserSelector = Discourse.TextField.extend({
|
||||||
|
|
||||||
didInsertElement: function(){
|
didInsertElement: function() {
|
||||||
|
var userSelectorView = this,
|
||||||
var userSelectorView = this;
|
selected = [];
|
||||||
var selected = [];
|
|
||||||
|
|
||||||
$(this.get('element')).val(this.get('usernames')).autocomplete({
|
$(this.get('element')).val(this.get('usernames')).autocomplete({
|
||||||
template: Discourse.UserSelector.templateFunction(),
|
template: Discourse.UserSelector.templateFunction(),
|
||||||
|
@ -11,9 +10,10 @@ Discourse.UserSelector = Discourse.TextField.extend({
|
||||||
disabled: this.get('disabled'),
|
disabled: this.get('disabled'),
|
||||||
single: this.get('single'),
|
single: this.get('single'),
|
||||||
allowAny: this.get('allowAny'),
|
allowAny: this.get('allowAny'),
|
||||||
|
|
||||||
dataSource: function(term) {
|
dataSource: function(term) {
|
||||||
var exclude = selected;
|
var exclude = selected;
|
||||||
if (userSelectorView.get('excludeCurrentUser')){
|
if (userSelectorView.get('excludeCurrentUser')) {
|
||||||
exclude = exclude.concat([Discourse.User.currentProp('username')]);
|
exclude = exclude.concat([Discourse.User.currentProp('username')]);
|
||||||
}
|
}
|
||||||
return Discourse.UserSearch.search({
|
return Discourse.UserSearch.search({
|
||||||
|
@ -23,13 +23,14 @@ Discourse.UserSelector = Discourse.TextField.extend({
|
||||||
include_groups: userSelectorView.get('include_groups')
|
include_groups: userSelectorView.get('include_groups')
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
transformComplete: function(v) {
|
transformComplete: function(v) {
|
||||||
if (v.username) {
|
if (v.username) {
|
||||||
return v.username;
|
return v.username;
|
||||||
} else {
|
} else {
|
||||||
return v.usernames;
|
return v.usernames;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onChangeItems: function(items) {
|
onChangeItems: function(items) {
|
||||||
items = _.map(items, function(i) {
|
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;
|
var maxLength = parseInt(block.hash.max) || 3;
|
||||||
if (context.length > maxLength){
|
if (context.length > maxLength){
|
||||||
return context.slice(0, maxLength).join(", ") + ", +" + (context.length - maxLength);
|
return context.slice(0, maxLength).join(", ") + ", +" + (context.length - maxLength);
|
||||||
} else {
|
} else {
|
||||||
return context.join(", ");
|
return context.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Discourse.UserSelector.reopenClass({
|
Discourse.UserSelector.reopenClass({
|
||||||
// I really want to move this into a template file, but I need a handlebars template here, not an ember one
|
// I really want to move this into a template file, but I need a handlebars template here, not an ember one
|
||||||
templateFunction: function(){
|
templateFunction: function() {
|
||||||
this.compiled = this.compiled || Handlebars.compile("<div class='autocomplete'>" +
|
this.compiled = this.compiled || Handlebars.compile(
|
||||||
"<ul>" +
|
"<div class='autocomplete'>" +
|
||||||
"{{#each options.users}}" +
|
"<ul>" +
|
||||||
"<li>" +
|
"{{#each options.users}}" +
|
||||||
"<a href='#'>{{avatar this imageSize=\"tiny\"}} " +
|
"<li>" +
|
||||||
"<span class='username'>{{this.username}}</span> " +
|
"<a href='#'>{{avatar this imageSize=\"tiny\"}} " +
|
||||||
"<span class='name'>{{this.name}}</span></a>" +
|
"<span class='username'>{{this.username}}</span> " +
|
||||||
"</li>" +
|
"<span class='name'>{{this.name}}</span></a>" +
|
||||||
"{{/each}}" +
|
"</li>" +
|
||||||
"{{#if options.groups}}" +
|
"{{/each}}" +
|
||||||
"{{#if options.users}}<hr>{{/if}}"+
|
"{{#if options.groups}}" +
|
||||||
"{{#each options.groups}}" +
|
"{{#if options.users}}<hr>{{/if}}"+
|
||||||
"<li>" +
|
"{{#each options.groups}}" +
|
||||||
"<a href=''><i class='icon-group'></i>" +
|
"<li>" +
|
||||||
"<span class='username'>{{this.name}}</span> " +
|
"<a href=''><i class='icon-group'></i>" +
|
||||||
"<span class='name'>{{showMax this.usernames max=3}}</span></a>" +
|
"<span class='username'>{{this.name}}</span> " +
|
||||||
"</li>" +
|
"<span class='name'>{{showMax this.usernames max=3}}</span>" +
|
||||||
"{{/each}}" +
|
"</a>" +
|
||||||
"{{/if}}" +
|
"</li>" +
|
||||||
"</ul>" +
|
"{{/each}}" +
|
||||||
"</div>");
|
"{{/if}}" +
|
||||||
|
"</ul>" +
|
||||||
|
"</div>");
|
||||||
return this.compiled;
|
return this.compiled;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -110,8 +110,8 @@ class Group < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search_group(name, current_user)
|
def self.search_group(name, current_user)
|
||||||
|
|
||||||
levels = [ALIAS_LEVELS[:everyone]]
|
levels = [ALIAS_LEVELS[:everyone]]
|
||||||
|
|
||||||
if current_user.admin?
|
if current_user.admin?
|
||||||
levels = [ALIAS_LEVELS[:everyone],
|
levels = [ALIAS_LEVELS[:everyone],
|
||||||
ALIAS_LEVELS[:only_admins],
|
ALIAS_LEVELS[:only_admins],
|
||||||
|
@ -123,11 +123,11 @@ class Group < ActiveRecord::Base
|
||||||
ALIAS_LEVELS[:members_mods_and_admins]]
|
ALIAS_LEVELS[:members_mods_and_admins]]
|
||||||
end
|
end
|
||||||
|
|
||||||
return Group.where("name LIKE :term_like AND (" +
|
Group.where("name LIKE :term_like AND (" +
|
||||||
" alias_level in (:levels)" +
|
" alias_level in (:levels)" +
|
||||||
" OR (alias_level = #{ALIAS_LEVELS[:everyone]} AND id in (" +
|
" OR (alias_level = #{ALIAS_LEVELS[:everyone]} AND id in (" +
|
||||||
"SELECT group_id FROM group_users WHERE user_id= :user_id)" +
|
"SELECT group_id FROM group_users WHERE user_id= :user_id)" +
|
||||||
")" +
|
")" +
|
||||||
")", term_like: "#{name.downcase}%", levels: levels, user_id: current_user.id)
|
")", term_like: "#{name.downcase}%", levels: levels, user_id: current_user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue