diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 7fcb94b..4a37fb1 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -36,7 +36,7 @@ class AttachmentsController < ApplicationController end end - # GET /attachments/1/edit + # GET /attachments/1/edit def edit @attachment = Attachment.find(params[:id]) @thema = @attachment.thema @@ -48,16 +48,17 @@ class AttachmentsController < ApplicationController @attachment = Attachment.new(params[:attachment]) @thema = Thema.find(params[:thema_id]) @attachment.thema_id = @thema.id - + @action="create" + logger.info "#{@attachment.inspect}" respond_to do |format| if @attachment.save format.html { redirect_to @thema, notice: 'Attachment was successfully created.' } format.json { render json: @thema, status: :created, location: @thema } - format.js { @attachment = Attachment.new } + format.js { } else format.html { render action: "new" } format.json { render json: @attachment.errors, status: :unprocessable_entity } - format.js { render action: "new"} + format.js { render action: "new.js.erb"} end end end @@ -76,7 +77,7 @@ class AttachmentsController < ApplicationController else format.html { render action: "edit" } format.json { render json: @attachment.errors, status: :unprocessable_entity } - format.js { render action: "new"} + format.js { render action: "new"} end end end diff --git a/app/controllers/beispiele_controller.rb b/app/controllers/beispiele_controller.rb index 1e2438f..ef93f78 100755 --- a/app/controllers/beispiele_controller.rb +++ b/app/controllers/beispiele_controller.rb @@ -43,15 +43,29 @@ class BeispieleController < ApplicationController # POST /beispiele # POST /beispiele.json def create + logger.info "Creating Beispiel..." @lva = Lva.find_by_id(params[:lva_id]) params.delete(:lva_id) @beispiel = Beispiel.new(params[:beispiel]) - @backlink = @beispiel.lva.nil? ? root_url : lva_path(@beispiel.lva) + @beispiel.lva=@lva + logger.info "New Beispiel: #{params.inspect}" + +# @backlink = @beispiel.lva.nil? ? root_url : lva_path(@beispiel.lva) + @beispiel.name=@beispiel.beispieldatei.filename + logger.info "New Beispiel: #{@beispiel.attributes.inspect}" + + @beispiel.datum=Time.now respond_to do |format| - @beispiel.name=@beispiel.beispieldatei.to_s.split('/').last + if @beispiel.save - format.html { redirect_to @backlink, notice: 'Beispiel was successfully created.' } - format.json { render json: @beispiel, status: :created, location: @beispiel } + format.html { + render :json => [@beispiel.to_jq_upload].to_json, + :content_type => 'text/html', + :layout => false + } + format.json { render json: {files: [@beispiel.to_jq_upload]}, status: :created, location: [@lva, @beispiel] } + # format.html { redirect_to @backlink, notice: 'Beispiel was successfully created.' } + # format.json { render json: @beispiel, status: :created, location: @beispiel } else format.html { render action: "new" } format.json { render json: @beispiel.errors, status: :unprocessable_entity } diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 846c82b..4333ec6 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,8 @@ class HomeController < ApplicationController def index @beispiele = Beispiel.last([Beispiel.count, 3].min) + @neuigkeiten = Neuigkeit.recent + end def dev diff --git a/app/controllers/themen_controller.rb b/app/controllers/themen_controller.rb index 8a653f2..4435ec6 100644 --- a/app/controllers/themen_controller.rb +++ b/app/controllers/themen_controller.rb @@ -34,6 +34,7 @@ class ThemenController < ApplicationController respond_to do |format| format.html # new.html.erb format.json { render json: @thema } + format.js { render action: "edit" } end end diff --git a/app/models/beispiel.rb b/app/models/beispiel.rb index 127ce65..6f87953 100755 --- a/app/models/beispiel.rb +++ b/app/models/beispiel.rb @@ -15,11 +15,22 @@ class Beispiel < ActiveRecord::Base has_paper_trail attr_accessible :desc, :name, :lva_id, :beispieldatei, :beispieldatei_cache, :datum belongs_to :lva - mount_uploader :beispieldatei, BeispieldateiUploader + mount_uploader :beispieldatei, AttachmentUploader validates :beispieldatei, :presence => true validates :name, :presence => true validates :lva_id, :presence => true validates :lva, :presence => true validates :datum, :presence => true - + def to_jq_upload + { + "id" => read_attribute(:id), + "title" => read_attribute(:title), + "description" => read_attribute(:desc), + "name" => read_attribute(:title), + "size" => beispieldatei.size, + "url" => beispieldatei.url, + "thumbnail_url" => beispieldatei.thumb.url, + "delete_type" => "DELETE" + } +end end diff --git a/app/views/attachments/_rform.html.erb b/app/views/attachments/_rform.html.erb index 07921ad..066e87d 100644 --- a/app/views/attachments/_rform.html.erb +++ b/app/views/attachments/_rform.html.erb @@ -1,6 +1,8 @@ -<%= semantic_form_for [@thema,@attachment],:remote=>true do |f| %> +<%= semantic_form_for [@thema,@attachment], :remote=>true do |f| %> <%= f.inputs do %> <%= f.input :name %> + +<%= token_tag form_authenticity_token %> <%= f.input :datei, :as => :file %> <% end %> diff --git a/app/views/attachments/create.js.erb b/app/views/attachments/create.js.erb index 57812ac..9c2920e 100644 --- a/app/views/attachments/create.js.erb +++ b/app/views/attachments/create.js.erb @@ -1,2 +1,2 @@ - -$("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )%>") +alert('create_attachment'); +$("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )%>"); diff --git a/app/views/attachments/new.js.erb b/app/views/attachments/new.js.erb index fc8b787..9145620 100644 --- a/app/views/attachments/new.js.erb +++ b/app/views/attachments/new.js.erb @@ -1 +1,4 @@ -$("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )%>") \ No newline at end of file +alert('new.js.erb') +$("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )+ @action.to_s%>"); +$('document').trigger('ready'); +alert('ready') \ No newline at end of file diff --git a/app/views/beispiele/_form_bulk.html.erb b/app/views/beispiele/_form_bulk.html.erb index 955ea51..5ab9ca9 100644 --- a/app/views/beispiele/_form_bulk.html.erb +++ b/app/views/beispiele/_form_bulk.html.erb @@ -1,5 +1,6 @@ +