bulk modul edit
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
class ModulgruppenController < ApplicationController
|
class ModulgruppenController < ApplicationController
|
||||||
# GET /modulgruppen
|
before_filter :find_modulgruppe, :only=>[:show, :delete]
|
||||||
|
before_filter :load_toolbar_show, :only=>[:show] # Toolbar für show erstellen
|
||||||
|
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@modulgruppen = Modulgruppe.all
|
@modulgruppen = Modulgruppe.all
|
||||||
if !params[:studium_id].nil?
|
if !params[:studium_id].nil?
|
||||||
@@ -14,17 +14,12 @@ class ModulgruppenController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
# GET /modulgruppen/1
|
# GET /modulgruppen/1
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@modulgruppe = Modulgruppe.find(params[:id])
|
@modulgruppe = Modulgruppe.find(params[:id])
|
||||||
@studium = Studium.find(@modulgruppe.studium_id)
|
@studium = Studium.find(@modulgruppe.studium_id)
|
||||||
if !params[:studium_id].nil?
|
if !params[:studium_id].nil?
|
||||||
@studium=Studium.find(params[:studium_id])
|
@studium=Studium.find(params[:studium_id])
|
||||||
end
|
end
|
||||||
@toolbar_elements = [ {:text=>'Zurück', :path=>studium_path(@studium, :ansicht=>:modulgruppenansicht)}]
|
|
||||||
@toolbar_elements << {:hicon=>'icon-plus-sign', :text=>I18n.t('modulgruppe.addmodul'), :path=>new_modul_path(@modulgruppe)}
|
|
||||||
@toolbar_elements << {:hicon=>'icon-pencil', :text=>I18n.t('modulgruppe.edit'), :path=>edit_modulgruppe_path(@modulgruppe)}
|
|
||||||
@toolbar_elements << {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => studium_path(@studium, :ansicht=>:modulgruppenansicht), :method=> :delete,:confirm=>'Sure?' }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /modulgruppen/new
|
# GET /modulgruppen/new
|
||||||
@@ -38,7 +33,6 @@ class ModulgruppenController < ApplicationController
|
|||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
format.json { render json: @modulgruppe }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -51,13 +45,15 @@ class ModulgruppenController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# POST /modulgruppen
|
# POST /modulgruppen
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@modulgruppe = Modulgruppe.new(params[:modulgruppe])
|
@modulgruppe = Modulgruppe.new(params[:modulgruppe])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
||||||
if @modulgruppe.save
|
if @modulgruppe.save
|
||||||
format.html { redirect_to @modulgruppe.studium, notice: 'Modulgruppe was successfully created.' }
|
format.html { redirect_to @modulgruppe.studium, notice: 'Modulgruppe was successfully created.' }
|
||||||
|
|
||||||
@@ -93,4 +89,20 @@ class ModulgruppenController < ApplicationController
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_modulgruppe
|
||||||
|
@modulgruppe = Modulgruppe.find(params[:id])
|
||||||
|
|
||||||
|
end
|
||||||
|
def load_toolbar_show
|
||||||
|
@toolbar_elements = [ {:text=>'Zurück', :path=>studium_path(@modulgruppe.studium, :ansicht=>:modulgruppenansicht)}]
|
||||||
|
@toolbar_elements << {:hicon=>'icon-plus-sign', :text=>I18n.t('modulgruppe.addmodule'), :path=>new_bulk_moduls_path(:modulgruppen_id=>@modulgruppe.id)}
|
||||||
|
|
||||||
|
@toolbar_elements << {:hicon=>'icon-plus-sign', :text=>I18n.t('modulgruppe.addmodul'), :path=>new_modul_path(:modulgruppen_id=>@modulgruppe.id)}
|
||||||
|
@toolbar_elements << {:hicon=>'icon-pencil', :text=>I18n.t('modulgruppe.edit'), :path=>edit_modulgruppe_path(@modulgruppe)}
|
||||||
|
@toolbar_elements << {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => modulgruppe_path(@modulgruppe, :ansicht=>:modulgruppenansicht), :method=> :delete,:confirm=>'Sure?' }
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
class ModulsController < ApplicationController
|
class ModulsController < ApplicationController
|
||||||
# GET /moduls
|
# GET /moduls
|
||||||
# GET /moduls.json
|
# GET /moduls.json
|
||||||
before_filter :find_modul, :only=>[:show,:update_lvas,:edit_lvas,:load_tiss,:show_tiss] # @modul laden
|
before_filter :find_modul, :only=>[:show,:update,:update_lvas,:edit_lvas,:load_tiss,:show_tiss] # @modul laden
|
||||||
before_filter :load_toolbar_show, :only=>[:show] # Toolbar für show erstellen
|
before_filter :load_toolbar_show, :only=>[:show] # Toolbar für show erstellen
|
||||||
before_filter :load_toolbar_index, :only=>[:index] # Toolbar für index erstellen
|
before_filter :load_toolbar_index, :only=>[:index] # Toolbar für index erstellen
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@moduls = Modul.all
|
@moduls = Modul.all
|
||||||
if @moduls
|
if @moduls
|
||||||
@@ -31,6 +32,7 @@ class ModulsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# GET /moduls/new
|
# GET /moduls/new
|
||||||
# GET /moduls/new.json
|
# GET /moduls/new.json
|
||||||
def new
|
def new
|
||||||
@@ -43,11 +45,59 @@ class ModulsController < ApplicationController
|
|||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_bulk
|
||||||
|
@moduls= []
|
||||||
|
@modulgruppe=Modulgruppe.find(params[:modulgruppen_id])
|
||||||
|
10.times {@moduls << Modul.new(:modulgruppen=>[@modulgruppe])}
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@modul = Modul.find(params[:id])
|
||||||
|
if !params[:studium_id].nil?
|
||||||
|
@studium=Studium.find(params[:studium_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit_bulk
|
||||||
|
unless params[:modulgruppen_id].nil?
|
||||||
|
@moduls=Modulgruppe.find(params[:modulgruppen_id]).moduls
|
||||||
|
else
|
||||||
|
@moduls=Modul.all
|
||||||
|
end
|
||||||
|
@moduls << Modul.new
|
||||||
|
end
|
||||||
|
|
||||||
def edit_lvas
|
def edit_lvas
|
||||||
@lvas = @modul.lvas
|
@lvas = @modul.lvas
|
||||||
@semester = @modul.modulgruppen.flatten.map(&:studium).map(&:semester).flatten.uniq
|
@semester = @modul.modulgruppen.flatten.map(&:studium).map(&:semester).flatten.uniq
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @modul.update_attributes(params[:modul])
|
||||||
|
for i in @modul.lvas
|
||||||
|
i.add_semesters
|
||||||
|
end
|
||||||
|
format.html { redirect_to url_for(@modul), notice: 'Modul was successfully updated.' }
|
||||||
|
else
|
||||||
|
format.html { render action: "edit" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_bulk
|
||||||
|
@moduls=Modul.update_multiple(params[:moduls])
|
||||||
|
if @moduls.map(&:valid?).all?
|
||||||
|
redirect_to @moduls.first.modulgruppen.first, :notice=>"Erfolgreich Module geändert"
|
||||||
|
else
|
||||||
|
render :edit_bulk
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_lvas
|
def update_lvas
|
||||||
@semester = @modul.modulgruppen.flatten.map(&:studium).map(&:semester).flatten.uniq
|
@semester = @modul.modulgruppen.flatten.map(&:studium).map(&:semester).flatten.uniq
|
||||||
@newlvas=Lva.update_multiple_with_modul(params["lvas"],@modul)
|
@newlvas=Lva.update_multiple_with_modul(params["lvas"],@modul)
|
||||||
@@ -59,14 +109,13 @@ class ModulsController < ApplicationController
|
|||||||
render "edit_lvas"
|
render "edit_lvas"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_tiss
|
def load_tiss
|
||||||
|
|
||||||
@lvas = @modul.lvas
|
@lvas = @modul.lvas
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_tiss
|
def show_tiss
|
||||||
@lvas=[];
|
@lvas=[];
|
||||||
|
|
||||||
@semester = @modul.modulgruppen.flatten.map(&:studium).map(&:semester).flatten.uniq
|
@semester = @modul.modulgruppen.flatten.map(&:studium).map(&:semester).flatten.uniq
|
||||||
params["lvas"].to_a.each do |l|
|
params["lvas"].to_a.each do |l|
|
||||||
unless l.last["lvanr"].empty?
|
unless l.last["lvanr"].empty?
|
||||||
@@ -80,13 +129,8 @@ class ModulsController < ApplicationController
|
|||||||
end
|
end
|
||||||
render 'edit_lvas'
|
render 'edit_lvas'
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /moduls/1/edit
|
# GET /moduls/1/edit
|
||||||
def edit
|
|
||||||
@modul = Modul.find(params[:id])
|
|
||||||
if !params[:studium_id].nil?
|
|
||||||
@studium=Studium.find(params[:studium_id])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# POST /moduls
|
# POST /moduls
|
||||||
# POST /moduls.json
|
# POST /moduls.json
|
||||||
@@ -98,10 +142,8 @@ class ModulsController < ApplicationController
|
|||||||
i.add_semesters
|
i.add_semesters
|
||||||
end
|
end
|
||||||
format.html { redirect_to modulgruppe_path(@modul.modulgruppen.first), notice: 'Modul was successfully created.' }
|
format.html { redirect_to modulgruppe_path(@modul.modulgruppen.first), notice: 'Modul was successfully created.' }
|
||||||
format.json { render json: @modul, status: :created, location: @modul }
|
|
||||||
else
|
else
|
||||||
format.html { render action: "new" }
|
format.html { render action: "new" }
|
||||||
format.json { render json: @modul.errors, status: :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -109,27 +151,9 @@ class ModulsController < ApplicationController
|
|||||||
|
|
||||||
# PUT /moduls/1
|
# PUT /moduls/1
|
||||||
# PUT /moduls/1.json
|
# PUT /moduls/1.json
|
||||||
def update
|
|
||||||
@modul = Modul.find(params[:id])
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @modul.update_attributes(params[:modul])
|
|
||||||
for i in @modul.lvas
|
|
||||||
i.add_semesters
|
|
||||||
end
|
|
||||||
format.html { redirect_to url_for(@modul), notice: 'Modul was successfully updated.' }
|
|
||||||
format.json { head :no_content }
|
|
||||||
else
|
|
||||||
format.html { render action: "edit" }
|
|
||||||
format.json { render json: @modul.errors, status: :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# DELETE /moduls/1
|
# DELETE /moduls/1
|
||||||
# DELETE /moduls/1.json
|
# DELETE /moduls/1.json
|
||||||
def destroy
|
def destroy
|
||||||
|
|
||||||
@modul = Modul.find(params[:id])
|
@modul = Modul.find(params[:id])
|
||||||
modulgruppe=@modul.modulgruppen.first
|
modulgruppe=@modul.modulgruppen.first
|
||||||
for i in @modul.lvas
|
for i in @modul.lvas
|
||||||
@@ -140,9 +164,11 @@ class ModulsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_modul
|
def find_modul
|
||||||
@modul = Modul.find(params[:id])
|
@modul = Modul.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_toolbar_show
|
def load_toolbar_show
|
||||||
@toolbar_elements = [{:hicon=>'icon-plus-sign', :text=>I18n.t("lva.add"), :path=>new_lva_path(:modul_id =>@modul.id)}]
|
@toolbar_elements = [{:hicon=>'icon-plus-sign', :text=>I18n.t("lva.add"), :path=>new_lva_path(:modul_id =>@modul.id)}]
|
||||||
@toolbar_elements << {:hicon=>'icon-pencil', :text=>"Lvas bearbeiten", :path=>edit_lvas_modul_path(@modul)}
|
@toolbar_elements << {:hicon=>'icon-pencil', :text=>"Lvas bearbeiten", :path=>edit_lvas_modul_path(@modul)}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
class Modul < ActiveRecord::Base
|
class Modul < ActiveRecord::Base
|
||||||
attr_accessible :desc,:name, :depend, :studium_id, :modulgruppe_ids
|
attr_accessible :desc,:name, :depend, :studium_id, :modulgruppen
|
||||||
|
|
||||||
has_and_belongs_to_many :lvas , :uniq=>true
|
has_and_belongs_to_many :lvas , :uniq=>true
|
||||||
has_and_belongs_to_many :modulgruppen
|
has_and_belongs_to_many :modulgruppen
|
||||||
@@ -21,5 +21,24 @@ class Modul < ActiveRecord::Base
|
|||||||
validates :modulgruppen, :presence=>true # Ein Modul muss zu einer Modulgruppe gehören
|
validates :modulgruppen, :presence=>true # Ein Modul muss zu einer Modulgruppe gehören
|
||||||
validates :name, :presence=>true # Ein Modul muss einen Namen haben
|
validates :name, :presence=>true # Ein Modul muss einen Namen haben
|
||||||
translates :desc,:depend,:name, :versioning =>true, :fallbacks_for_empty_translations => true
|
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
|
||||||
|
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
|
||||||
|
else
|
||||||
|
md=Modul.find(h["id"].to_i)
|
||||||
|
md.name=h["name"]
|
||||||
|
md.modulgruppen=Modulgruppe.where(:id => h["modulgruppe_ids"].map(&:to_i))
|
||||||
|
m << md
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
m
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
29
app/views/moduls/_form_bulk.html.erb
Normal file
29
app/views/moduls/_form_bulk.html.erb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<%= semantic_form_for "moduls[]", :url=>update_bulk_moduls_path do |ff| %>
|
||||||
|
<table>
|
||||||
|
<tr><th>Modulname</th><th>Modulgruppen</th><th>Beschreibung</th> <th>Voraussetzungen</th></tr>
|
||||||
|
<% @moduls.each do |m| %>
|
||||||
|
<%= semantic_fields_for "moduls[#{m.id}]", m do |f| %>
|
||||||
|
<tr><td>
|
||||||
|
<%= f.input :id, :label=>false, :hint=>"" ,:as=>:hidden%>
|
||||||
|
<%= f.input :name, :label=>false, :hint=>"" %></td>
|
||||||
|
<td>
|
||||||
|
<%= f.input :modulgruppen, :label=>false, :hint=>"" , :collection=>Modulgruppe.all %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= f.input :desc, :label=>false, :hint=>"" ,:input_html=>{:class=>"row-fluid"} %>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<%= f.input :depend, :label=>false, :hint=>"" ,:input_html=>{:class=>"row-fluid"} %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
<%= ff.actions do %>
|
||||||
|
<%= ff.action :submit, :label=>"Save", :as=>:button %>
|
||||||
|
<%= ff.action :cancel, :as => :link %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
1
app/views/moduls/edit_bulk.html.erb
Normal file
1
app/views/moduls/edit_bulk.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<%= render :partial=>"form_bulk" %>
|
||||||
1
app/views/moduls/new_bulk.html.erb
Normal file
1
app/views/moduls/new_bulk.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<%= render :partial=>"form_bulk" %>
|
||||||
@@ -4,10 +4,10 @@
|
|||||||
# Formtastic::FormBuilder.default_text_field_size = 50
|
# Formtastic::FormBuilder.default_text_field_size = 50
|
||||||
|
|
||||||
# Set the default text area height when input is a text. Default is 20.
|
# Set the default text area height when input is a text. Default is 20.
|
||||||
# Formtastic::FormBuilder.default_text_area_height = 5
|
Formtastic::FormBuilder.default_text_area_height = 5
|
||||||
|
|
||||||
# Set the default text area width when input is a text. Default is nil.
|
# Set the default text area width when input is a text. Default is nil.
|
||||||
Formtastic::FormBuilder.default_text_area_width = 100
|
Formtastic::FormBuilder.default_text_area_width = "40"
|
||||||
|
|
||||||
# Should all fields be considered "required" by default?
|
# Should all fields be considered "required" by default?
|
||||||
# Defaults to true.
|
# Defaults to true.
|
||||||
|
|||||||
@@ -29,7 +29,8 @@
|
|||||||
resources :studien, :only=>[:show]
|
resources :studien, :only=>[:show]
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :modulgruppen,:only =>[:create,:index]
|
resources :modulgruppen,:only =>[:create,:index] do
|
||||||
|
end
|
||||||
|
|
||||||
resources :studien,:except=>[:show,:new,:edit,:update,:destroy], :shallow=>true do
|
resources :studien,:except=>[:show,:new,:edit,:update,:destroy], :shallow=>true do
|
||||||
resources :modulgruppen, :path => "(:locale)/modulgruppen"
|
resources :modulgruppen, :path => "(:locale)/modulgruppen"
|
||||||
@@ -65,6 +66,12 @@
|
|||||||
get 'load_tiss'
|
get 'load_tiss'
|
||||||
post 'show_tiss'
|
post 'show_tiss'
|
||||||
end
|
end
|
||||||
|
collection do
|
||||||
|
get 'edit_bulk'
|
||||||
|
get 'new_bulk'
|
||||||
|
post 'update_bulk'
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
resources :beispiele#, :only=>[:show,:index,:create]
|
resources :beispiele#, :only=>[:show,:index,:create]
|
||||||
resources :lvas do
|
resources :lvas do
|
||||||
|
|||||||
Reference in New Issue
Block a user