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 %>
- <%= gallery.fotos.size.to_s + " " + I18n.t('fotos.bilder')%> - <%=I18n.l(gallery.try(:datum).try(:to_date)) unless gallery.try(:datum).try(:to_date).nil? %>
+ + <%= gallery.fotos.size.to_s + " " + I18n.t('fotos.bilder')%> + + + <%=I18n.l(gallery.try(:datum).try(:to_date)) unless gallery.try(:datum).try(:to_date).nil? %> + +

<%= gallery.name %>

<%= 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 @@ + + +

<%= %>

+ <%= f.semantic_errors :state %> + <%= f.input :id, :as=>:hidden %> + + + <%= f.input :lvanr , :input_html => { "style"=>"width:7em" }%> + <%= f.input :name %> + + <%= f.input :ects, :input_html => { "style"=>"width:4em" },:size=>5 %> + <%= f.input :stunden, :input_html => { "style"=>"width:4em" }%> + <%= f.input :typ, :input_html => { "style"=>"width:4em" }%> + + <% f.input :semester , :input_html=>{:style=>"height:8em"},:collection=>@semester%> + + + <%= f.input :pruefungsinformation,:input_html=>{:rows=>5} %> + + <%= f.input :desc, :input_html=>{:rows=>4}%> + diff --git a/app/views/moduls/edit_lvas.html.erb b/app/views/moduls/edit_lvas.html.erb index 40a6338..9fdea1c 100644 --- a/app/views/moduls/edit_lvas.html.erb +++ b/app/views/moduls/edit_lvas.html.erb @@ -3,33 +3,10 @@ <% i = 0 %> <% @lvas.each do |lva|%> <% i = i +1 %> - <%= semantic_fields_for "lvas[#{i}]", lva do |f|%> - -

<%= lva.name %>

-<%= f.semantic_errors :state %> -<%= f.input :id, :as=>:hidden %> -<%= f.input :lvanr , :input_html => { "style"=>"width:7em" }%> - - -<%= f.input :name %> -<%= f.input :ects, :input_html => { "style"=>"width:4em" },:size=>5 %> -<%= f.input :stunden, :input_html => { "style"=>"width:4em" }%> -<%= f.input :typ, :input_html => { "style"=>"width:4em" }%> - -<%= f.input :semester , :input_html=>{:style=>"height:8em"},:collection=>@semester%> - -<%= f.input :pruefungsinformation,:input_html=>{:rows=>4} %> - -<%= f.input :desc, :input_html=>{:rows=>4}%> - -<%= lva.valid? %> - - + <%= render 'lvas/nested_fields', :f => f,:lva=>lva %> <% end%> - - <% end %> <%= ff.actions do %> diff --git a/app/views/neuigkeiten/_form.html.erb b/app/views/neuigkeiten/_form.html.erb index 0712bab..480709e 100755 --- a/app/views/neuigkeiten/_form.html.erb +++ b/app/views/neuigkeiten/_form.html.erb @@ -9,23 +9,22 @@
-
- <% f.input :datum, :as=> :datepicker %> +
+ <% f.input :datum, :as=> :datepicker %> <%= f.input :rubrik, :as=> :radio, :collection=>Rubrik.all %> +
+
+ <%= f.input :author, :as=> :select %> +
-
- <%= f.input :author, :as=> :select %> -
-
- <%= f.input :picture, :as=> :file %> -
+
+ <%= f.input :picture, :as=> :file %> +
+ - - - - <%= 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 %> diff --git a/app/views/studien/edit_lvas.html.erb b/app/views/studien/edit_lvas.html.erb new file mode 100644 index 0000000..08ac65a --- /dev/null +++ b/app/views/studien/edit_lvas.html.erb @@ -0,0 +1,15 @@ +<%= semantic_form_for @studium do |ff|%> + + + + <%= 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 %> + +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 404b381..0644b99 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -25,9 +25,12 @@ # Studien scope '(:ansicht)' do - resources :studien, :only=>[:new,:edit,:update,:destroy] - resources :studien, :only=>[:show] - end + resources :studien, :only=>[:new,:edit,:update,:destroy,:show] do + member do + get :edit_lvas + end + end + end resources :modulgruppen,:only =>[:create,:index] do end