studium_edit_lvas added

This commit is contained in:
Andreas Stephanides
2014-04-12 18:03:39 +02:00
parent 7fff32bab1
commit f96c3dee9a
9 changed files with 89 additions and 48 deletions

View File

@@ -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) }, @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_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?' }] {: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)}, @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)} @toolbar_elements<<{:text =>I18n.t('studien.allestudien'),:path=>studien_path(@studium)}
end 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 def create
@studium = Studium.new(params[:studium]) @studium = Studium.new(params[:studium])
@@ -73,9 +83,13 @@ class StudienController < ApplicationController
def update def update
@studium = Studium.find(params[:id]) @studium = Studium.find(params[:id])
logger.info "params: #{params[:studium].inspect}"
if @studium.update_attributes(params[:studium]) if @studium.update_attributes(params[:studium])
redirect_to url_for(@studium), notice: 'Studium was successfully updated.' if @studium.lvas.map(&:valid?).all?
redirect_to url_for(@studium), notice: 'Studium was successfully updated.'
else
render action: "edit"
end
else else
render action: "edit" render action: "edit"

View File

@@ -23,6 +23,7 @@ class Neuigkeit < ActiveRecord::Base
has_many :calentries, as: :object has_many :calentries, as: :object
mount_uploader :picture, PictureUploader mount_uploader :picture, PictureUploader
scope :published, -> {where("datum <= ? AND datum IS NOT NULL", Time.now.to_date).order(:datum).reverse_order} scope :published, -> {where("datum <= ? AND datum IS NOT NULL", Time.now.to_date).order(:datum).reverse_order}
scope :recent, -> { published.limit(15)} scope :recent, -> { published.limit(15)}
scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)} 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?} accepts_nested_attributes_for :calentries, :allow_destroy=>true , :reject_if=> lambda{|a| a[:start].blank?}
before_validation :sanitize before_validation :sanitize
has_many :nlinks has_many :nlinks
def datum_nilsave def datum_nilsave
self.datum.nil? ? Time.now + 42.years : self.datum self.datum.nil? ? Time.now + 42.years : self.datum
end end

View File

@@ -27,18 +27,24 @@
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
class Studium < ActiveRecord::Base 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 has_many :modulgruppen, inverse_of: :studium, :class_name => "Modulgruppe", :dependent => :destroy
scope :search, ->(query) {where("name like ? or studien.desc like ?", "%#{query}%", "%#{query}%")} scope :search, ->(query) {where("name like ? or studien.desc like ?", "%#{query}%", "%#{query}%")}
has_many :moduls, :through=>:modulgruppen has_many :moduls, :through=>:modulgruppen
has_many :lvas, :through=>:moduls has_many :lvas, :through=>:moduls
has_many :semester, :dependent => :destroy 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 :typ, :inclusion => {:in => ["Bachelor","Master"] }
validates :name, :uniqueness => true, :presence=>true validates :name, :uniqueness => true, :presence=>true
validates :zahl, :presence=>true, :format=>{:with=>/^[0-9A-Z]{4,10}$/}, :uniqueness => true validates :zahl, :presence=>true, :format=>{:with=>/^[0-9A-Z]{4,10}$/}, :uniqueness => true
mount_uploader :picture, PictureUploader 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 translates :desc,:shortdesc, :qualifikation,:struktur, :jobmoeglichkeiten, :versioning =>true,:fallbacks_for_empty_translations => true
def title_context def title_context
return self.abkuerzung.to_s.strip.empty? ? self.name : self.abkuerzung return self.abkuerzung.to_s.strip.empty? ? self.name : self.abkuerzung
end end

View File

@@ -13,8 +13,13 @@
end %> end %>
</div> </div>
<div class="media-body"> <div class="media-body">
<small class="pull-left"><%= gallery.fotos.size.to_s + " " + I18n.t('fotos.bilder')%> </small> <small class="pull-left">
<small class="pull-right"><%=I18n.l(gallery.try(:datum).try(:to_date)) unless gallery.try(:datum).try(:to_date).nil? %></small></br> <%= gallery.fotos.size.to_s + " " + I18n.t('fotos.bilder')%>
</small>
<small class="pull-right">
<%=I18n.l(gallery.try(:datum).try(:to_date)) unless gallery.try(:datum).try(:to_date).nil? %>
</small>
</br>
<h1><%= gallery.name %></h1> <h1><%= gallery.name %></h1>
<p> <p>
<%= if gallery.desc.split.size > Gallery::WORD_COUNT <%= if gallery.desc.split.size > Gallery::WORD_COUNT

View File

@@ -0,0 +1,21 @@
<tr>
<td>
<h4><%= %></h4>
<%= f.semantic_errors :state %>
<%= f.input :id, :as=>:hidden %>
</td>
<td><%= f.input :lvanr , :input_html => { "style"=>"width:7em" }%></td>
<td><%= f.input :name %></td>
<td>
<%= f.input :ects, :input_html => { "style"=>"width:4em" },:size=>5 %>
<%= f.input :stunden, :input_html => { "style"=>"width:4em" }%></td>
<td><%= f.input :typ, :input_html => { "style"=>"width:4em" }%></td>
<td>
<% f.input :semester , :input_html=>{:style=>"height:8em"},:collection=>@semester%>
</td>
<td><%= f.input :pruefungsinformation,:input_html=>{:rows=>5} %></td>
<td><%= f.input :desc, :input_html=>{:rows=>4}%></td>
</tr>

View File

@@ -3,33 +3,10 @@
<% i = 0 %> <% i = 0 %>
<% @lvas.each do |lva|%> <% @lvas.each do |lva|%>
<% i = i +1 %> <% i = i +1 %>
<tr>
<%= semantic_fields_for "lvas[#{i}]", lva do |f|%> <%= semantic_fields_for "lvas[#{i}]", lva do |f|%>
<td> <%= render 'lvas/nested_fields', :f => f,:lva=>lva %>
<h4><%= lva.name %></h4>
<%= f.semantic_errors :state %>
<%= f.input :id, :as=>:hidden %></td>
<td><%= f.input :lvanr , :input_html => { "style"=>"width:7em" }%></td>
<td><%= f.input :name %></td>
<td><%= f.input :ects, :input_html => { "style"=>"width:4em" },:size=>5 %>
<%= f.input :stunden, :input_html => { "style"=>"width:4em" }%></td>
<td><%= f.input :typ, :input_html => { "style"=>"width:4em" }%></td>
<td>
<%= f.input :semester , :input_html=>{:style=>"height:8em"},:collection=>@semester%></td>
<td><%= f.input :pruefungsinformation,:input_html=>{:rows=>4} %></td>
<td><%= f.input :desc, :input_html=>{:rows=>4}%></td>
<td>
<%= lva.valid? %>
</td>
<% end%> <% end%>
</tr>
<% end %> <% end %>
<%= ff.actions do %> <%= ff.actions do %>

View File

@@ -9,23 +9,22 @@
</div> </div>
</div> </div>
<div class="row-fluid"> <div class="row-fluid">
<div class="span6"> <div class="span6">
<% f.input :datum, :as=> :datepicker %> <% f.input :datum, :as=> :datepicker %>
<%= f.input :rubrik, :as=> :radio, :collection=>Rubrik.all %> <%= f.input :rubrik, :as=> :radio, :collection=>Rubrik.all %>
</div>
<div class="span6">
<%= f.input :author, :as=> :select %>
</div>
</div> </div>
<div class="span6">
<%= f.input :author, :as=> :select %>
</div> </div>
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
<%= f.input :picture, :as=> :file %> <%= f.input :picture, :as=> :file %>
</div> </div> </div>
</div>
<%= f.semantic_fields_for :calentries , @calentries do |calentry| %>
<%= render 'calentries/nested_fields', :f => calentry %>
<%= f.semantic_fields_for :calentries , @calentries do |calentry| %>
<%= render 'calentries/nested_fields', :f => calentry %>
<% end %> <% end %>
<% end %> <% end %>

View File

@@ -0,0 +1,15 @@
<%= semantic_form_for @studium do |ff|%>
<table>
<%= ff.semantic_fields_for :lvas, @lvas do |f|%>
<%= render 'lvas/nested_fields', :f => f %>
<% end %>
<%= ff.actions do %>
<%= ff.action :submit, :as => :button %>
<%= ff.action :cancel, :as => :link %>
<% end %>
</table>
<% end %>

View File

@@ -25,9 +25,12 @@
# Studien # Studien
scope '(:ansicht)' do scope '(:ansicht)' do
resources :studien, :only=>[:new,:edit,:update,:destroy] resources :studien, :only=>[:new,:edit,:update,:destroy,:show] do
resources :studien, :only=>[:show] member do
end get :edit_lvas
end
end
end
resources :modulgruppen,:only =>[:create,:index] do resources :modulgruppen,:only =>[:create,:index] do
end end