upload beispiele attachments...

This commit is contained in:
Andreas Stephanides
2014-02-20 10:50:03 +01:00
parent f13a59b64e
commit 8897a217d9
16 changed files with 77 additions and 32 deletions

View File

@@ -48,16 +48,17 @@ class AttachmentsController < ApplicationController
@attachment = Attachment.new(params[:attachment]) @attachment = Attachment.new(params[:attachment])
@thema = Thema.find(params[:thema_id]) @thema = Thema.find(params[:thema_id])
@attachment.thema_id = @thema.id @attachment.thema_id = @thema.id
@action="create"
logger.info "#{@attachment.inspect}"
respond_to do |format| respond_to do |format|
if @attachment.save if @attachment.save
format.html { redirect_to @thema, notice: 'Attachment was successfully created.' } format.html { redirect_to @thema, notice: 'Attachment was successfully created.' }
format.json { render json: @thema, status: :created, location: @thema } format.json { render json: @thema, status: :created, location: @thema }
format.js { @attachment = Attachment.new } format.js { }
else else
format.html { render action: "new" } format.html { render action: "new" }
format.json { render json: @attachment.errors, status: :unprocessable_entity } format.json { render json: @attachment.errors, status: :unprocessable_entity }
format.js { render action: "new"} format.js { render action: "new.js.erb"}
end end
end end
end end

View File

@@ -43,15 +43,29 @@ class BeispieleController < ApplicationController
# POST /beispiele # POST /beispiele
# POST /beispiele.json # POST /beispiele.json
def create def create
logger.info "Creating Beispiel..."
@lva = Lva.find_by_id(params[:lva_id]) @lva = Lva.find_by_id(params[:lva_id])
params.delete(:lva_id) params.delete(:lva_id)
@beispiel = Beispiel.new(params[:beispiel]) @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| respond_to do |format|
@beispiel.name=@beispiel.beispieldatei.to_s.split('/').last
if @beispiel.save if @beispiel.save
format.html { redirect_to @backlink, notice: 'Beispiel was successfully created.' } format.html {
format.json { render json: @beispiel, status: :created, location: @beispiel } 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 else
format.html { render action: "new" } format.html { render action: "new" }
format.json { render json: @beispiel.errors, status: :unprocessable_entity } format.json { render json: @beispiel.errors, status: :unprocessable_entity }

View File

@@ -1,6 +1,8 @@
class HomeController < ApplicationController class HomeController < ApplicationController
def index def index
@beispiele = Beispiel.last([Beispiel.count, 3].min) @beispiele = Beispiel.last([Beispiel.count, 3].min)
@neuigkeiten = Neuigkeit.recent
end end
def dev def dev

View File

@@ -34,6 +34,7 @@ class ThemenController < ApplicationController
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
format.json { render json: @thema } format.json { render json: @thema }
format.js { render action: "edit" }
end end
end end

View File

@@ -15,11 +15,22 @@ class Beispiel < ActiveRecord::Base
has_paper_trail has_paper_trail
attr_accessible :desc, :name, :lva_id, :beispieldatei, :beispieldatei_cache, :datum attr_accessible :desc, :name, :lva_id, :beispieldatei, :beispieldatei_cache, :datum
belongs_to :lva belongs_to :lva
mount_uploader :beispieldatei, BeispieldateiUploader mount_uploader :beispieldatei, AttachmentUploader
validates :beispieldatei, :presence => true validates :beispieldatei, :presence => true
validates :name, :presence => true validates :name, :presence => true
validates :lva_id, :presence => true validates :lva_id, :presence => true
validates :lva, :presence => true validates :lva, :presence => true
validates :datum, :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 end

View File

@@ -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.inputs do %>
<%= f.input :name %> <%= f.input :name %>
<%= token_tag form_authenticity_token %>
<%= f.input :datei, :as => :file %> <%= f.input :datei, :as => :file %>
<% end %> <% end %>

View File

@@ -1,2 +1,2 @@
alert('create_attachment');
$("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )%>") $("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )%>");

View File

@@ -1 +1,4 @@
$("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )%>") alert('new.js.erb')
$("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )+ @action.to_s%>");
$('document').trigger('ready');
alert('ready')

View File

@@ -1,5 +1,6 @@
<div class="container"> <div class="container">
<%= semantic_form_for [@lva, @beispiel], :remote=>true, :html => { :multipart => true, :id => "fileupload" } do |f| %> <%= semantic_form_for [@lva,@beispiel], :remote=>true, :html => { :multipart => true, :id => "fileupload" } do |f| %>
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --> <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="row "> <div class="row ">
@@ -10,7 +11,7 @@
<i class="icon-plus icon-white"></i> <i class="icon-plus icon-white"></i>
<span>Add files...</span> <span>Add files...</span>
<%= f.file_field :beispieldatei, :multiple=>true %> <%= f.file_field :beispieldatei, :multiple=>true %>
<%= f.input :lva %> <% f.input :lva %>
</span> </span>
<button type="submit" class="btn btn-primary start"> <button type="submit" class="btn btn-primary start">
<i class="icon-upload icon-white"></i> <i class="icon-upload icon-white"></i>

View File

@@ -2,7 +2,7 @@
<div class="row-fluid"> <div class="row-fluid">
<div class="span8"> <div class="span8">
<h4>Neueste Beispiele</h4> <h4>Neueste Beispiele in unserer Sammlung</h4>
</div> </div>
<div class="span4"> <div class="span4">
<%= link_to I18n.t("beispiel.add"), new_beispiel_path, :class=>"btn"%> <%= link_to I18n.t("beispiel.add"), new_beispiel_path, :class=>"btn"%>

View File

@@ -1,5 +1,14 @@
<div class="content-wrap content-column"> <div class="content-wrap content-column">
<h1><%= I18n.t('home.willkommen') %></h1> <h1><%= I18n.t('home.willkommen') %></h1>
<p><%= I18n.t('home.hallobeiderfet') %></p>
<ul class="unstyled linkbox-list" style="max-width:70em">
<% @neuigkeiten.each do |n| %>
<li><%= render n if can?(:show, n) %> </li>
<% end %>
</ul>
<p>
<%= link_to "FET Login", user_omniauth_authorize_path(:ldap) %>
</p>
<div class="alert"> <div class="alert">
<h2>Beta Test</h2> <h2>Beta Test</h2>
<p>Die Webseite befindet sich derzeit in einem Entsicklungsstadium, <p>Die Webseite befindet sich derzeit in einem Entsicklungsstadium,
@@ -19,7 +28,6 @@
</p> </p>
</div> </div>
<p><%= I18n.t('home.hallobeiderfet') %></p>
<%= link_to "Entwicklungsstatus" , home_dev_path %> <%= link_to "Entwicklungsstatus" , home_dev_path %>
<%= render 'beispiele' %> <%= render 'beispiele' %>

View File

@@ -14,14 +14,14 @@
</h1> </h1>
<%= raw(neuigkeit.text_first_words) unless neuigkeit.text.nil?%> <%= raw(neuigkeit.text_first_words) unless neuigkeit.text.nil?%>
</div> </div>
<% if neuigkeit.has_calentries? %> <% if neuigkeit.has_calentries? %>
<div class="pull-right" href="#"> <div class="pull-right" href="#">
<%= image_tag("/iconnavy/time.png") %> <%= image_tag("/iconnavy/time.png") %>
<% unless neuigkeit.calentries.upcoming.empty? %> <% unless neuigkeit.calentries.upcoming.empty? %>
<%= neuigkeit.calentries.upcoming.first.text %> <%= neuigkeit.calentries.upcoming.first.text %>
<% else unless neuigkeit.calentries.recent.empty? %> <% else unless neuigkeit.calentries.recent.empty? %>
<%= neuigkeit.calentries.recent.first.text %> <%= neuigkeit.calentries.recent.first.text %>
<% end %><% end %> <% end %><% end %>
</div> </div>
<% end %> <% end %>

View File

@@ -1 +1 @@
$("#themaview").html("<%= escape_javascript(raw("<h2>Bearbeiten</h2>")+render(:partial=>"themen/form") )%>"); $("#themaview").html("<%= escape_javascript(raw("<h2>"+I18n.t('thema.edit')+"</h2>")+render(:partial=>"themen/form") )%>");

View File

@@ -11,6 +11,7 @@
<li id="themen_<%= thema.id %>" class="sort" ><div class="contentbox handle" ><h2><%= thema.title %></h2> </div> <%= link_to edit_thema_path(thema),:remote=>true do %> Edit <% end %> <%= link_to thema_fragen_path(thema),:remote=>true do %> Fragen <% end %></li> <li id="themen_<%= thema.id %>" class="sort" ><div class="contentbox handle" ><h2><%= thema.title %></h2> </div> <%= link_to edit_thema_path(thema),:remote=>true do %> Edit <% end %> <%= link_to thema_fragen_path(thema),:remote=>true do %> Fragen <% end %></li>
<% end %> <% end %>
</ul> </ul>
<%= link_to new_themengruppe_thema_path(@themengruppe),:remote=>true do %> New Thema <% end %>
</div> </div>
<div class="span8"> <div class="span8">
<div id="themaview"></div> <div id="themaview"></div>

View File

@@ -21,6 +21,7 @@ de:
info: "Information" info: "Information"
mitarbeiter: "Mitarbeiter" mitarbeiter: "Mitarbeiter"
fotos: "Fotos" fotos: "Fotos"
search: "Suche"
formtastic: formtastic:
titles: titles:
modul: modul:

View File

@@ -62,9 +62,9 @@ end
get 'load_tiss' get 'load_tiss'
post 'show_tiss' post 'show_tiss'
end end
resources :beispiele#, :only=>[:show,:index,:create]
resources :lvas do resources :lvas do
resources :beispiele, :only=>[:show,:index] resources :beispiele#, :only=>[:show,:index,:create]
end end
resources :fragen resources :fragen
@@ -102,7 +102,7 @@ end
get 'home/linksnotimplemented', :controller=>:home, :action=>:linksnotimplemented, :as=>'home_linksnotimplemented' get 'home/linksnotimplemented', :controller=>:home, :action=>:linksnotimplemented, :as=>'home_linksnotimplemented'
resources :beispiele
resources :themen do resources :themen do
get :fragen get :fragen
resources :attachments resources :attachments