Added meta where and jquery observe field. Fixed members view.
This commit is contained in:
parent
6c98c7c755
commit
c87ead8da9
10 changed files with 102 additions and 51 deletions
1
Gemfile
1
Gemfile
|
@ -11,6 +11,7 @@ gem "will_paginate", "~> 3.0.pre2"
|
|||
gem 'jquery-rails'
|
||||
gem 'simple_form'
|
||||
gem 'rails3_acts_as_paranoid'
|
||||
gem 'meta_where'
|
||||
|
||||
group :development do
|
||||
gem 'annotate'
|
||||
|
|
|
@ -46,6 +46,10 @@ GEM
|
|||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
meta_where (1.0.4)
|
||||
activerecord (~> 3.0.0)
|
||||
activesupport (~> 3.0.0)
|
||||
arel (~> 2.0.7)
|
||||
mime-types (1.16)
|
||||
mysql (2.8.1)
|
||||
polyglot (0.3.1)
|
||||
|
@ -97,6 +101,7 @@ DEPENDENCIES
|
|||
haml
|
||||
hirb
|
||||
jquery-rails
|
||||
meta_where
|
||||
mysql
|
||||
prawn (<= 0.6.3)
|
||||
rails (= 3.0.7)
|
||||
|
|
|
@ -1,36 +1,30 @@
|
|||
class Foodcoop::UsersController < ApplicationController
|
||||
|
||||
def index
|
||||
@users = User.order(:nick.asc)
|
||||
|
||||
# if somebody uses the search field:
|
||||
unless params[:query].blank?
|
||||
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"}))
|
||||
end
|
||||
|
||||
# sort by ordergroups
|
||||
if params[:sort_by_ordergroups]
|
||||
@users = []
|
||||
Ordergroup.find(:all, :order => "name").each do |group|
|
||||
group.users.each do |user|
|
||||
@users << user
|
||||
end
|
||||
end
|
||||
@total = @users.size
|
||||
else
|
||||
# if params[:sort_by_ordergroups]
|
||||
# @users = @users.joins(:ordergroup).order(:ordergroup => :name.asc) # Retunr dubbled entries, why?
|
||||
# end
|
||||
|
||||
# sort by nick, thats default
|
||||
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
||||
@per_page = params[:per_page].to_i
|
||||
else
|
||||
@per_page = 20
|
||||
end
|
||||
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
||||
@per_page = params[:per_page].to_i
|
||||
else
|
||||
@per_page = 20
|
||||
end
|
||||
|
||||
# if somebody uses the search field:
|
||||
unless params[:query].blank?
|
||||
conditions = ["first_name LIKE ? OR last_name LIKE ? OR nick LIKE ?",
|
||||
"%#{params[:query]}%", "%#{params[:query]}%", "%#{params[:query]}%"]
|
||||
end
|
||||
@users = @users.paginate(:page => params[:page], :per_page => @per_page)
|
||||
|
||||
@total = User.count(:conditions => conditions)
|
||||
@users = User.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "nick", :include => :groups)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.js { render :partial => "users" }
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html # index.html.haml
|
||||
format.js { render :layout => false } # index.js.erb
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ class Group < ActiveRecord::Base
|
|||
validates_length_of :name, :in => 1..25
|
||||
validates_uniqueness_of :name
|
||||
validate :last_admin_on_earth, :on => :update
|
||||
|
||||
before_destroy :check_last_admin_group
|
||||
|
||||
# Returns true if the given user if is an member of this group.
|
||||
def member?(user)
|
||||
|
@ -17,16 +19,16 @@ class Group < ActiveRecord::Base
|
|||
def non_members
|
||||
User.all(:order => 'nick').reject { |u| users.include?(u) }
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
# Check before destroy a group, if this is the last group with admin role
|
||||
def before_destroy
|
||||
def check_last_admin_group
|
||||
if self.role_admin == true && Group.find_all_by_role_admin(true).size == 1
|
||||
raise "Die letzte Gruppe mit Admin-Rechten darf nicht gelöscht werden"
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
||||
# validates uniqueness of the Group.name. Checks groups and ordergroups
|
||||
def validate
|
||||
errors.add(:name, "ist schon vergeben") if (group = Group.find_by_name(name) || group = Ordergroup.find_by_name(name)) && self != group
|
||||
|
|
|
@ -2,12 +2,16 @@ class Membership < ActiveRecord::Base
|
|||
|
||||
belongs_to :user
|
||||
belongs_to :group
|
||||
|
||||
before_destroy :check_last_admin
|
||||
|
||||
# messages
|
||||
ERR_NO_ADMIN_MEMBER_DELETE = "Mitgliedschaft kann nicht beendet werden. Du bist die letzte Administratorin"
|
||||
|
||||
|
||||
protected
|
||||
|
||||
# check if this is the last admin-membership and deny
|
||||
def before_destroy
|
||||
def check_last_admin
|
||||
raise ERR_NO_ADMIN_MEMBER_DELETE if self.group.role_admin? && self.group.memberships.size == 1 && Group.find_all_by_role_admin(true).size == 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
%td
|
||||
= pagination_links_remote @users, :update => :users
|
||||
%td{:style => "text-align:right"}
|
||||
- if @total > 20
|
||||
- if @users.size > 20
|
||||
= items_per_page :update => :users
|
||||
%table.list
|
||||
%thead
|
||||
|
@ -17,7 +17,8 @@
|
|||
%th Bestellgruppe
|
||||
%th Arbeitsgruppe(n)
|
||||
%tbody
|
||||
- for user in @users
|
||||
- users = params[:sort_by_ordergroups] ? @users.sort { |a,b| a.ordergroup.name <=> b.ordergroup.name } : @users
|
||||
- for user in users
|
||||
%tr{:class => cycle('even','odd', :name => 'users')}
|
||||
%td= link_to user.nick, user_message_path(user), :title => _('Send user an email')
|
||||
%td=h user.name if @current_user.role_admin? || user.settings["profile.nameIsPublic"] == '1'
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
- content_for :head do
|
||||
:javascript
|
||||
$(function() {
|
||||
$('#query').observe_field(1, function() {
|
||||
$('#user_search').submit();
|
||||
});
|
||||
$('#sort_by_ordergroups').click(function() {
|
||||
$('#user_search').submit();
|
||||
});
|
||||
});
|
||||
|
||||
%h1 Mitglieder der Foodcoop
|
||||
%p
|
||||
%i
|
||||
|
@ -13,20 +24,11 @@
|
|||
.column_content
|
||||
- unless params[:sort_by_ordergroups]
|
||||
#user_filter{:style => "float:left; margin-right:2em;"}
|
||||
%form{:name=>"sform", :action=>"", :style=>"display:inline;"}
|
||||
= form_tag foodcoop_users_path, :method => :get, :style=>"display:inline;", :id => 'user_search', :remote => true do
|
||||
%label{:for => 'article_name'} Suche nach Name:
|
||||
= text_field_tag("query", params['query'], :size => 10 )
|
||||
|
||||
= observe_field 'query', :frequency => 2, |
|
||||
:before => "Element.show('loader')", |
|
||||
:success => "Element.hide('loader')", |
|
||||
:url => foodcoop_users_path, |
|
||||
:update => :users, |
|
||||
:with => 'query', |
|
||||
:method => :get |
|
||||
|
||||
=_ "Nach Bestellgruppen sortieren:"
|
||||
- form_tag(foodcoop_users_path, :method => "get", :style=>"display:inline;") do
|
||||
= check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups], :onclick => "submit();"
|
||||
= text_field_tag(:query, params[:query], :size => 10 )
|
||||
|
||||
Nach Bestellgruppen sortieren:
|
||||
= check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups]
|
||||
#users
|
||||
= render :partial => "users"
|
1
app/views/foodcoop/users/index.js.erb
Normal file
1
app/views/foodcoop/users/index.js.erb
Normal file
|
@ -0,0 +1 @@
|
|||
$('#users').html('<%= escape_javascript(render("users")) %>');
|
|
@ -8,14 +8,16 @@
|
|||
<!--[if lte IE 7]>
|
||||
= stylesheet_link_tag 'ie_hacks'
|
||||
<![endif]-->
|
||||
= javascript_include_tag 'jquery.min', 'jquery-ui.min', 'jquery_ujs', 'jquery.tokeninput', 'application', 'ordering', :cache => "all_cached"
|
||||
= javascript_include_tag 'jquery.min', 'jquery-ui.min', 'jquery_ujs', 'jquery.tokeninput', 'jquery.observe_field',
|
||||
'application', 'ordering', :cache => "all_cached"
|
||||
= csrf_meta_tag
|
||||
= yield(:head)
|
||||
%body
|
||||
#logininfo= render :partial => 'shared/loginInfo'
|
||||
|
||||
#header
|
||||
#logo
|
||||
- link_to root_path do
|
||||
= link_to root_path do
|
||||
<span>food</span>soft
|
||||
%span{:style => "color:white; font-size:45%; letter-spacing: -1px;"}= Foodsoft.config[:name]
|
||||
#nav= render :partial => 'layouts/main_tabnav'
|
||||
|
|
39
public/javascripts/jquery.observe_field.js
Normal file
39
public/javascripts/jquery.observe_field.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
// jquery.observe_field.js
|
||||
|
||||
|
||||
(function( $ ){
|
||||
|
||||
jQuery.fn.observe_field = function(frequency, callback) {
|
||||
|
||||
frequency = frequency * 1000; // translate to milliseconds
|
||||
|
||||
return this.each(function(){
|
||||
var $this = $(this);
|
||||
var prev = $this.val();
|
||||
|
||||
var check = function() {
|
||||
var val = $this.val();
|
||||
if(prev != val){
|
||||
prev = val;
|
||||
$this.map(callback); // invokes the callback on $this
|
||||
}
|
||||
};
|
||||
|
||||
var reset = function() {
|
||||
if(ti){
|
||||
clearInterval(ti);
|
||||
ti = setInterval(check, frequency);
|
||||
}
|
||||
};
|
||||
|
||||
check();
|
||||
var ti = setInterval(check, frequency); // invoke check periodically
|
||||
|
||||
// reset counter after user interaction
|
||||
$this.bind('keyup click mousemove', reset); //mousemove is for selects
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
})( jQuery );
|
||||
|
Loading…
Reference in a new issue