Merge branch 'rails3' of http://github.com/bennibu/foodsoft into rails3-ajaxArticleDelete
This commit is contained in:
commit
467b53c009
5 changed files with 29 additions and 7 deletions
|
@ -4,7 +4,7 @@ class Group < ActiveRecord::Base
|
||||||
has_many :memberships, :dependent => :destroy
|
has_many :memberships, :dependent => :destroy
|
||||||
has_many :users, :through => :memberships
|
has_many :users, :through => :memberships
|
||||||
|
|
||||||
validates :name, :presence => true, :length => {:in => 1..25}, :uniqueness => true
|
validates :name, :presence => true, :length => {:in => 1..25}
|
||||||
|
|
||||||
attr_reader :user_tokens
|
attr_reader :user_tokens
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Ordergroup < Group
|
||||||
has_many :orders, :through => :group_orders
|
has_many :orders, :through => :group_orders
|
||||||
|
|
||||||
validates_numericality_of :account_balance, :message => 'ist keine gültige Zahl'
|
validates_numericality_of :account_balance, :message => 'ist keine gültige Zahl'
|
||||||
validate :uniqueness_of_members
|
validate :uniqueness_of_name, :uniqueness_of_members
|
||||||
|
|
||||||
after_create :update_stats!
|
after_create :update_stats!
|
||||||
|
|
||||||
|
@ -106,6 +106,16 @@ class Ordergroup < Group
|
||||||
errors.add :user_tokens, "#{user.nick} ist schon in einer anderen Bestellgruppe" if user.groups.where(:type => 'Ordergroup').size > 1
|
errors.add :user_tokens, "#{user.nick} ist schon in einer anderen Bestellgruppe" if user.groups.where(:type => 'Ordergroup').size > 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Make sure, the name is uniq, add usefull message if uniq group is already deleted
|
||||||
|
def uniqueness_of_name
|
||||||
|
id = new_record? ? '' : self.id
|
||||||
|
group = Ordergroup.with_deleted.where('groups.id != ? AND groups.name = ?', id, name).first
|
||||||
|
if group.present?
|
||||||
|
message = group.deleted? ? :taken_with_deleted : :taken
|
||||||
|
errors.add :name, message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,13 @@ class Supplier < ActiveRecord::Base
|
||||||
attr_accessible :name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number,
|
attr_accessible :name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number,
|
||||||
:delivery_days, :order_howto, :note, :shared_supplier_id, :min_order_quantity
|
:delivery_days, :order_howto, :note, :shared_supplier_id, :min_order_quantity
|
||||||
|
|
||||||
validates :name, :presence => true, :length => { :in => 4..30 }, :uniqueness => true
|
validates :name, :presence => true, :length => { :in => 4..30 }
|
||||||
validates :phone, :presence => true, :length => { :in => 8..20 }
|
validates :phone, :presence => true, :length => { :in => 8..20 }
|
||||||
validates :address, :presence => true, :length => { :in => 8..50 }
|
validates :address, :presence => true, :length => { :in => 8..50 }
|
||||||
validates_length_of :order_howto, :note, maximum: 250
|
validates_length_of :order_howto, :note, maximum: 250
|
||||||
# validates_length_of :name, :in => 4..30
|
|
||||||
# validates_uniqueness_of :name
|
|
||||||
|
|
||||||
validates_length_of :phone, :in => 8..20
|
validates_length_of :phone, :in => 8..20
|
||||||
validates_length_of :address, :in => 8..50
|
validates_length_of :address, :in => 8..50
|
||||||
|
validate :uniqueness_of_name
|
||||||
|
|
||||||
# sync all articles with the external database
|
# sync all articles with the external database
|
||||||
# returns an array with articles(and prices), which should be updated (to use in a form)
|
# returns an array with articles(and prices), which should be updated (to use in a form)
|
||||||
|
@ -66,5 +64,17 @@ class Supplier < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
return [updated_articles, outlisted_articles]
|
return [updated_articles, outlisted_articles]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
# Make sure, the name is uniq, add usefull message if uniq group is already deleted
|
||||||
|
def uniqueness_of_name
|
||||||
|
id = new_record? ? '' : self.id
|
||||||
|
supplier = Supplier.with_deleted.where('suppliers.id != ? AND suppliers.name = ?', id, name).first
|
||||||
|
if supplier.present?
|
||||||
|
message = supplier.deleted? ? :taken_with_deleted : :taken
|
||||||
|
errors.add :name, message
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ class Workgroup < Group
|
||||||
# returns all non-finished tasks
|
# returns all non-finished tasks
|
||||||
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC'
|
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC'
|
||||||
|
|
||||||
|
validates_uniqueness_of :name
|
||||||
validates_presence_of :task_name, :weekday, :task_required_users, :next_weekly_tasks_number,
|
validates_presence_of :task_name, :weekday, :task_required_users, :next_weekly_tasks_number,
|
||||||
:if => :weekly_task
|
:if => :weekly_task
|
||||||
validates_numericality_of :next_weekly_tasks_number, :greater_than => 0, :less_than => 21, :only_integer => true,
|
validates_numericality_of :next_weekly_tasks_number, :greater_than => 0, :less_than => 21, :only_integer => true,
|
||||||
|
@ -61,7 +62,7 @@ class Workgroup < Group
|
||||||
# add validation check on update
|
# add validation check on update
|
||||||
# Return an error if this is the last group with admin role and role_admin should set to false
|
# Return an error if this is the last group with admin role and role_admin should set to false
|
||||||
def last_admin_on_earth
|
def last_admin_on_earth
|
||||||
if !role_admin && Workgroup.where(:role_admin => true, :id.ne => id).empty?
|
if !role_admin && !Workgroup.where('role_admin = ? AND id != ?', true, id).exists?
|
||||||
errors.add(:role_admin, "Der letzten Gruppe mit Admin-Rechten darf die Admin-Rolle nicht entzogen werden")
|
errors.add(:role_admin, "Der letzten Gruppe mit Admin-Rechten darf die Admin-Rolle nicht entzogen werden")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -143,6 +143,7 @@ de:
|
||||||
odd: muss ungerade sein
|
odd: muss ungerade sein
|
||||||
record_invalid: ! 'Gültigkeitsprüfung ist fehlgeschlagen: %{errors}'
|
record_invalid: ! 'Gültigkeitsprüfung ist fehlgeschlagen: %{errors}'
|
||||||
taken: ist bereits vergeben
|
taken: ist bereits vergeben
|
||||||
|
taken_with_deleted: ist bereits vergeben (eine gelöschte Gruppe)
|
||||||
too_long: ist zu lang (nicht mehr als %{count} Zeichen)
|
too_long: ist zu lang (nicht mehr als %{count} Zeichen)
|
||||||
too_short: ist zu kurz (nicht weniger als %{count} Zeichen)
|
too_short: ist zu kurz (nicht weniger als %{count} Zeichen)
|
||||||
wrong_length: hat die falsche Länge (muss genau %{count} Zeichen haben)
|
wrong_length: hat die falsche Länge (muss genau %{count} Zeichen haben)
|
||||||
|
|
Loading…
Reference in a new issue