diff --git a/app/controllers/studien_controller.rb b/app/controllers/studien_controller.rb index 35f80d3..79de843 100755 --- a/app/controllers/studien_controller.rb +++ b/app/controllers/studien_controller.rb @@ -34,6 +34,7 @@ class StudienController < ApplicationController @toolbar_elements=[{:icon=>:plus, :hicon =>'icon-plus-sign' ,:text=> I18n.t('studien.new') , :path => new_studium_path(@studium) }, {:icon=>:pencil, :hicon=>'icon-pencil',:text =>I18n.t('common.edit'),:path => edit_studium_path(@studium)}, + {:icon=>:pencil, :hicon=>'icon-pencil',:text =>I18n.t('common.edit'),:path => edit_lvas_studium_path(@studium)}, {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => studium_path(@studium), :method=> :delete,:confirm=>'Sure?' }] @toolbar_modulgruppen =[ {:hicon=>'icon-plus-sign', :text=> I18n.t('modulgruppe.new'), :path=>new_studium_modulgruppe_path(@studium)}, @@ -57,6 +58,15 @@ class StudienController < ApplicationController @toolbar_elements<<{:text =>I18n.t('studien.allestudien'),:path=>studien_path(@studium)} end + def edit_lvas + @studium = Studium.find(params[:id]) + @lvas=@studium.lvas + @semester=@studium.semester + @toolbar_elements=[{:text => I18n.t('studien.anzeigen') , :path => url_for(@studium) }] + @toolbar_elements<<{:text =>I18n.t('studien.allestudien'),:path=>studien_path(@studium)} + + end + def create @studium = Studium.new(params[:studium]) @@ -73,9 +83,13 @@ class StudienController < ApplicationController def update @studium = Studium.find(params[:id]) - - if @studium.update_attributes(params[:studium]) - redirect_to url_for(@studium), notice: 'Studium was successfully updated.' + logger.info "params: #{params[:studium].inspect}" + if @studium.update_attributes(params[:studium]) + if @studium.lvas.map(&:valid?).all? + redirect_to url_for(@studium), notice: 'Studium was successfully updated.' + else + render action: "edit" + end else render action: "edit" diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index e5b710b..e894dc9 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -23,6 +23,7 @@ class Neuigkeit < ActiveRecord::Base has_many :calentries, as: :object mount_uploader :picture, PictureUploader + scope :published, -> {where("datum <= ? AND datum IS NOT NULL", Time.now.to_date).order(:datum).reverse_order} scope :recent, -> { published.limit(15)} scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)} @@ -32,7 +33,7 @@ class Neuigkeit < ActiveRecord::Base accepts_nested_attributes_for :calentries, :allow_destroy=>true , :reject_if=> lambda{|a| a[:start].blank?} before_validation :sanitize has_many :nlinks - + def datum_nilsave self.datum.nil? ? Time.now + 42.years : self.datum end diff --git a/app/models/studium.rb b/app/models/studium.rb index 51afdf1..044ae08 100755 --- a/app/models/studium.rb +++ b/app/models/studium.rb @@ -27,18 +27,24 @@ # created_at :datetime not null # updated_at :datetime not null class Studium < ActiveRecord::Base - attr_accessible :desc, :name,:abkuerzung, :typ, :zahl, :semester, :picture, :picture_cache, :qualifikation,:struktur, :jobmoeglichkeiten + attr_accessible :desc, :name,:abkuerzung, :typ, :zahl, :semester, :picture, :picture_cache, :qualifikation,:struktur, :jobmoeglichkeiten, :lvas_attributes has_many :modulgruppen, inverse_of: :studium, :class_name => "Modulgruppe", :dependent => :destroy scope :search, ->(query) {where("name like ? or studien.desc like ?", "%#{query}%", "%#{query}%")} has_many :moduls, :through=>:modulgruppen has_many :lvas, :through=>:moduls has_many :semester, :dependent => :destroy - validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/} + +validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/} validates :typ, :inclusion => {:in => ["Bachelor","Master"] } validates :name, :uniqueness => true, :presence=>true validates :zahl, :presence=>true, :format=>{:with=>/^[0-9A-Z]{4,10}$/}, :uniqueness => true + mount_uploader :picture, PictureUploader + + accepts_nested_attributes_for :lvas #, :allow_destroy=>true # , :reject_if=> lambda{|a| a[:name].blank?} + translates :desc,:shortdesc, :qualifikation,:struktur, :jobmoeglichkeiten, :versioning =>true,:fallbacks_for_empty_translations => true + def title_context return self.abkuerzung.to_s.strip.empty? ? self.name : self.abkuerzung end diff --git a/app/views/galleries/index.html.erb b/app/views/galleries/index.html.erb index 68a8a8f..258fd23 100644 --- a/app/views/galleries/index.html.erb +++ b/app/views/galleries/index.html.erb @@ -13,8 +13,13 @@ end %>
<%= if gallery.desc.split.size > Gallery::WORD_COUNT diff --git a/app/views/lvas/_nested_fields.html.erb b/app/views/lvas/_nested_fields.html.erb new file mode 100644 index 0000000..ed6ff9d --- /dev/null +++ b/app/views/lvas/_nested_fields.html.erb @@ -0,0 +1,21 @@ +