BUGFIX: groups page wasn't working

This commit is contained in:
Régis Hanol 2014-01-14 19:18:04 +01:00
parent b9bda77abd
commit 92cb52e76e
5 changed files with 57 additions and 65 deletions

View file

@ -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);
}); });

View file

@ -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>

View file

@ -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); }
}
if (options.single){
// dump what we have in single mode, just in case // dump what we have in single mode, just in case
inputSelectedItems = []; if (options.single) { inputSelectedItems = []; }
} if (!_.isArray(transformed)) { transformed = [transformed || item]; }
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();

View file

@ -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,6 +10,7 @@ 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')) {
@ -23,6 +23,7 @@ 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;
@ -59,14 +60,13 @@ Handlebars.registerHelper("showMax", function(context, block){
} 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(
"<div class='autocomplete'>" +
"<ul>" + "<ul>" +
"{{#each options.users}}" + "{{#each options.users}}" +
"<li>" + "<li>" +
@ -81,7 +81,8 @@ Discourse.UserSelector.reopenClass({
"<li>" + "<li>" +
"<a href=''><i class='icon-group'></i>" + "<a href=''><i class='icon-group'></i>" +
"<span class='username'>{{this.name}}</span> " + "<span class='username'>{{this.name}}</span> " +
"<span class='name'>{{showMax this.usernames max=3}}</span></a>" + "<span class='name'>{{showMax this.usernames max=3}}</span>" +
"</a>" +
"</li>" + "</li>" +
"{{/each}}" + "{{/each}}" +
"{{/if}}" + "{{/if}}" +

View file

@ -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,7 +123,7 @@ 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)" +