From 87cad4b91097f4921cc24b2addbfb6af005fa923 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Fri, 4 Apr 2014 14:50:48 +0200 Subject: [PATCH] =?UTF-8?q?fix=20f=C3=BCr=20bulk=20edit=20moduls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/moduls_controller.rb | 7 ++++++- app/models/modul.rb | 16 +++++++++++++--- app/models/studium.rb | 1 + app/views/moduls/_form_bulk.html.erb | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/controllers/moduls_controller.rb b/app/controllers/moduls_controller.rb index 0b71ae9..23aa95e 100755 --- a/app/controllers/moduls_controller.rb +++ b/app/controllers/moduls_controller.rb @@ -63,9 +63,14 @@ class ModulsController < ApplicationController unless params[:modulgruppen_id].nil? @moduls=Modulgruppe.find(params[:modulgruppen_id]).moduls else + unless params[:studium_id].nil? + @moduls=Studium.find(params[:studium_id]).modulgruppen.collect(&:moduls).flatten + else + @moduls=Modul.all +end end - @moduls << Modul.new + end def edit_lvas diff --git a/app/models/modul.rb b/app/models/modul.rb index 4cb136a..b85ef8f 100755 --- a/app/models/modul.rb +++ b/app/models/modul.rb @@ -23,8 +23,9 @@ class Modul < ActiveRecord::Base translates :desc,:depend,:name, :versioning =>true, :fallbacks_for_empty_translations => true def self.update_multiple(hash) m= [] - hash.each_entry do |h| - if h["id"].to_i == 0 + if hash.is_a? Hash + hash.each do |i,h| + if i.to_i == 0 unless h["name"].empty? md=Modul.new(:name=>h["name"],:desc=>h["desc"],:depend=>h["depend"]) md.modulgruppen=Modulgruppe.where(:id => h["modulgruppe_ids"].map(&:to_i)) @@ -37,8 +38,17 @@ class Modul < ActiveRecord::Base md.modulgruppen=Modulgruppe.where(:id => h["modulgruppe_ids"].map(&:to_i)) m << md end - end + else + hash.each do |h| + unless h["name"].empty? + md=Modul.new(:name=>h["name"],:desc=>h["desc"],:depend=>h["depend"]) + md.modulgruppen=Modulgruppe.where(:id => h["modulgruppe_ids"].map(&:to_i)) + md.save + m << md + end + end + end m end end diff --git a/app/models/studium.rb b/app/models/studium.rb index a2813df..4f2f73e 100755 --- a/app/models/studium.rb +++ b/app/models/studium.rb @@ -29,6 +29,7 @@ class Studium < ActiveRecord::Base attr_accessible :desc, :name,:abkuerzung, :typ, :zahl, :semester, :picture, :picture_cache, :qualifikation,:struktur, :jobmoeglichkeiten has_many :modulgruppen, inverse_of: :studium, :class_name => "Modulgruppe", :dependent => :destroy + has_many :semester, :dependent => :destroy validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/} validates :typ, :inclusion => {:in => ["Bachelor","Master"] } diff --git a/app/views/moduls/_form_bulk.html.erb b/app/views/moduls/_form_bulk.html.erb index e3eaebc..8406045 100644 --- a/app/views/moduls/_form_bulk.html.erb +++ b/app/views/moduls/_form_bulk.html.erb @@ -4,7 +4,7 @@ <% @moduls.each do |m| %> <%= semantic_fields_for "moduls[#{m.id}]", m do |f| %> -<%= f.input :id, :label=>false, :hint=>"" ,:as=>:hidden%> +<%= f.input :id, :label=>false, :hint=>"" ,:as=>:hidden %> <%= f.input :name, :label=>false, :hint=>"" %> <%= f.input :modulgruppen, :label=>false, :hint=>"" , :collection=>Modulgruppe.all %>