Permalink
Browse files

period_list_for method and user_regurlarcourse valitations were added…

… to avoid troubles with user_regularcourses_controller. Coffescript changes to resize the dialog for new records
  • Loading branch information...
1 parent 2abed54 commit 770b30f4a818c469da044f60c014bee5e2d40ada Ramón Martínez Olvera committed Feb 23, 2012
@@ -84,7 +84,7 @@ jQuery.extend
$("#dialog").dialog(
title: ""
width: 400
- height: 330
+ height: 500
modal: true
overlay: background: "#fff", opacity: 0.25
).dialog "open"
@@ -244,4 +244,9 @@ def has_current_user?(record)
def link_to_if_url_exists(record)
link_to('online', record.url) if record.has_attribute? :url and !record.url.to_s.strip.empty? and record.url =~ /^http/
end
+
+ def period_list_for(course)
+ registered_periods = course.periods.collect {|record| record.id }
+ Period.all.collect {|record| record unless registered_periods.include? record.id }.compact!
+ end
end
@@ -12,6 +12,7 @@ class Regularcourse < ActiveRecord::Base
has_many :user_regularcourses
has_many :users, :through => :user_regularcourses
+ has_many :periods, :through => :user_regularcourses
accepts_nested_attributes_for :user_regularcourses
user_association_methods_for :user_regularcourses
@@ -4,6 +4,7 @@ class UserRegularcourse < ActiveRecord::Base
validates_numericality_of :period_id, :roleinregularcourse_id, :greater_than => 0, :only_integer => true
validates_numericality_of :hoursxweek, :allow_nil => true, :greater_than => 0 , :only_integer => true
validates_inclusion_of :hoursxweek, :in => 1..40, :allow_nil => true
+ validates_uniqueness_of :regularcourse_id, :scope => [:period_id, :user_id]
belongs_to :regularcourse
belongs_to :period
@@ -13,7 +13,8 @@
= f.hidden_field :regularcourse_id
.row
= f.hidden_field :user_id, :value => current_user.id
- = f.association :period, :collection => Period.all, :input_html => { :prompt => 'true', :required => true, :class => 'chosen-select'}
+
+ = f.association :period, :collection => period_list_for(@regular_course), :input_html => { :prompt => 'true', :required => true, :class => 'chosen-select'}
.row
= f.association :roleinregularcourse, :as => :radio, :collection => Roleinregularcourse.all, :wrapper_class => 'radio-set'
.row

0 comments on commit 770b30f

Please sign in to comment.