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 'jquery-rails'
|
||||||
gem 'simple_form'
|
gem 'simple_form'
|
||||||
gem 'rails3_acts_as_paranoid'
|
gem 'rails3_acts_as_paranoid'
|
||||||
|
gem 'meta_where'
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'annotate'
|
gem 'annotate'
|
||||||
|
|
|
@ -46,6 +46,10 @@ GEM
|
||||||
i18n (>= 0.4.0)
|
i18n (>= 0.4.0)
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
treetop (~> 1.4.8)
|
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)
|
mime-types (1.16)
|
||||||
mysql (2.8.1)
|
mysql (2.8.1)
|
||||||
polyglot (0.3.1)
|
polyglot (0.3.1)
|
||||||
|
@ -97,6 +101,7 @@ DEPENDENCIES
|
||||||
haml
|
haml
|
||||||
hirb
|
hirb
|
||||||
jquery-rails
|
jquery-rails
|
||||||
|
meta_where
|
||||||
mysql
|
mysql
|
||||||
prawn (<= 0.6.3)
|
prawn (<= 0.6.3)
|
||||||
rails (= 3.0.7)
|
rails (= 3.0.7)
|
||||||
|
|
|
@ -1,36 +1,30 @@
|
||||||
class Foodcoop::UsersController < ApplicationController
|
class Foodcoop::UsersController < ApplicationController
|
||||||
|
|
||||||
def index
|
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
|
# sort by ordergroups
|
||||||
if params[:sort_by_ordergroups]
|
# if params[:sort_by_ordergroups]
|
||||||
@users = []
|
# @users = @users.joins(:ordergroup).order(:ordergroup => :name.asc) # Retunr dubbled entries, why?
|
||||||
Ordergroup.find(:all, :order => "name").each do |group|
|
# end
|
||||||
group.users.each do |user|
|
|
||||||
@users << user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@total = @users.size
|
|
||||||
else
|
|
||||||
# sort by nick, thats default
|
# sort by nick, thats default
|
||||||
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
||||||
@per_page = params[:per_page].to_i
|
@per_page = params[:per_page].to_i
|
||||||
else
|
else
|
||||||
@per_page = 20
|
@per_page = 20
|
||||||
end
|
end
|
||||||
|
|
||||||
# if somebody uses the search field:
|
@users = @users.paginate(:page => params[:page], :per_page => @per_page)
|
||||||
unless params[:query].blank?
|
|
||||||
conditions = ["first_name LIKE ? OR last_name LIKE ? OR nick LIKE ?",
|
|
||||||
"%#{params[:query]}%", "%#{params[:query]}%", "%#{params[:query]}%"]
|
|
||||||
end
|
|
||||||
|
|
||||||
@total = User.count(:conditions => conditions)
|
respond_to do |format|
|
||||||
@users = User.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "nick", :include => :groups)
|
format.html # index.html.haml
|
||||||
|
format.js { render :layout => false } # index.js.erb
|
||||||
respond_to do |format|
|
|
||||||
format.html # index.html.erb
|
|
||||||
format.js { render :partial => "users" }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ class Group < ActiveRecord::Base
|
||||||
validates_length_of :name, :in => 1..25
|
validates_length_of :name, :in => 1..25
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validate :last_admin_on_earth, :on => :update
|
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.
|
# Returns true if the given user if is an member of this group.
|
||||||
def member?(user)
|
def member?(user)
|
||||||
|
@ -17,16 +19,16 @@ class Group < ActiveRecord::Base
|
||||||
def non_members
|
def non_members
|
||||||
User.all(:order => 'nick').reject { |u| users.include?(u) }
|
User.all(:order => 'nick').reject { |u| users.include?(u) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
# Check before destroy a group, if this is the last group with admin role
|
# 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
|
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"
|
raise "Die letzte Gruppe mit Admin-Rechten darf nicht gelöscht werden"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
# validates uniqueness of the Group.name. Checks groups and ordergroups
|
# validates uniqueness of the Group.name. Checks groups and ordergroups
|
||||||
def validate
|
def validate
|
||||||
errors.add(:name, "ist schon vergeben") if (group = Group.find_by_name(name) || group = Ordergroup.find_by_name(name)) && self != group
|
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 :user
|
||||||
belongs_to :group
|
belongs_to :group
|
||||||
|
|
||||||
|
before_destroy :check_last_admin
|
||||||
|
|
||||||
# messages
|
# messages
|
||||||
ERR_NO_ADMIN_MEMBER_DELETE = "Mitgliedschaft kann nicht beendet werden. Du bist die letzte Administratorin"
|
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
|
# 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
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
%td
|
%td
|
||||||
= pagination_links_remote @users, :update => :users
|
= pagination_links_remote @users, :update => :users
|
||||||
%td{:style => "text-align:right"}
|
%td{:style => "text-align:right"}
|
||||||
- if @total > 20
|
- if @users.size > 20
|
||||||
= items_per_page :update => :users
|
= items_per_page :update => :users
|
||||||
%table.list
|
%table.list
|
||||||
%thead
|
%thead
|
||||||
|
@ -17,7 +17,8 @@
|
||||||
%th Bestellgruppe
|
%th Bestellgruppe
|
||||||
%th Arbeitsgruppe(n)
|
%th Arbeitsgruppe(n)
|
||||||
%tbody
|
%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')}
|
%tr{:class => cycle('even','odd', :name => 'users')}
|
||||||
%td= link_to user.nick, user_message_path(user), :title => _('Send user an email')
|
%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'
|
%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
|
%h1 Mitglieder der Foodcoop
|
||||||
%p
|
%p
|
||||||
%i
|
%i
|
||||||
|
@ -13,20 +24,11 @@
|
||||||
.column_content
|
.column_content
|
||||||
- unless params[:sort_by_ordergroups]
|
- unless params[:sort_by_ordergroups]
|
||||||
#user_filter{:style => "float:left; margin-right:2em;"}
|
#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:
|
%label{:for => 'article_name'} Suche nach Name:
|
||||||
= text_field_tag("query", params['query'], :size => 10 )
|
= text_field_tag(:query, params[:query], :size => 10 )
|
||||||
|
|
||||||
= observe_field 'query', :frequency => 2, |
|
Nach Bestellgruppen sortieren:
|
||||||
:before => "Element.show('loader')", |
|
= check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups]
|
||||||
: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();"
|
|
||||||
#users
|
#users
|
||||||
= render :partial => "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]>
|
<!--[if lte IE 7]>
|
||||||
= stylesheet_link_tag 'ie_hacks'
|
= stylesheet_link_tag 'ie_hacks'
|
||||||
<![endif]-->
|
<![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)
|
= yield(:head)
|
||||||
%body
|
%body
|
||||||
#logininfo= render :partial => 'shared/loginInfo'
|
#logininfo= render :partial => 'shared/loginInfo'
|
||||||
|
|
||||||
#header
|
#header
|
||||||
#logo
|
#logo
|
||||||
- link_to root_path do
|
= link_to root_path do
|
||||||
<span>food</span>soft
|
<span>food</span>soft
|
||||||
%span{:style => "color:white; font-size:45%; letter-spacing: -1px;"}= Foodsoft.config[:name]
|
%span{:style => "color:white; font-size:45%; letter-spacing: -1px;"}= Foodsoft.config[:name]
|
||||||
#nav= render :partial => 'layouts/main_tabnav'
|
#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