diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 4a37fb1..59ea3df 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -46,19 +46,29 @@ class AttachmentsController < ApplicationController # POST /attachments.json def create @attachment = Attachment.new(params[:attachment]) - @thema = Thema.find(params[:thema_id]) - @attachment.thema_id = @thema.id - @action="create" - logger.info "#{@attachment.inspect}" + @thema = Thema.find_by_id(params[:thema_id]) + # logger.info "gg" + @attachment.thema = @thema + @attachment.name=@attachment.datei.filename + @action="create" + + + # logger.info "sdf" 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 { } + if @attachment.save + format.html { + render :json => [@attachment.to_jq_upload].to_json, + :content_type => 'text/html', + :layout => false + } + + # format.html { redirect_to @thema, notice: 'Attachment was successfully created.' } + format.json { render json: {files: [@attachment.to_jq_upload]}, status: :created, location: [@thema, @attachment]} + else format.html { render action: "new" } format.json { render json: @attachment.errors, status: :unprocessable_entity } - format.js { render action: "new.js.erb"} + end end end diff --git a/app/controllers/themen_controller.rb b/app/controllers/themen_controller.rb index 4462131..a4a635f 100644 --- a/app/controllers/themen_controller.rb +++ b/app/controllers/themen_controller.rb @@ -32,7 +32,8 @@ class ThemenController < ApplicationController end def verwalten @thema = Thema.find(params[:id]) - unless (@thema.wikiname.empty? || @thema.wikiname.nil?) + @attachment=Attachment.new + unless (@thema.is_wiki?) redirect_to verwalten_wiki_path(Wiki.find(@thema.id)) end @@ -58,7 +59,10 @@ class ThemenController < ApplicationController # GET /themen/1/edit def edit @thema = Thema.find(params[:id]) - + unless ( @thema.wikiname.nil? || @thema.wikiname.empty? ) + redirect_to edit_wiki_path(Wiki.find(@thema.id)) + return + end respond_to do |format| format.html format.js @@ -93,6 +97,7 @@ class ThemenController < ApplicationController def attachments @thema = Thema.find(params[:id]) @attachments=@thema.attachments + @attachment=Attachment.new respond_to do |format| format.js end diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb index 1033d07..d448a14 100644 --- a/app/controllers/wikis_controller.rb +++ b/app/controllers/wikis_controller.rb @@ -23,7 +23,11 @@ class WikisController < ApplicationController end def edit @wiki = Wiki.find(params[:id]) - + respond_to do |format| + format.html + format.js + end + end def update diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 1efccd6..c61214f 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -12,9 +12,22 @@ class Attachment < ActiveRecord::Base has_paper_trail - attr_accessible :name, :datei + attr_accessible :name, :datei, :datei_cache belongs_to :thema mount_uploader :datei, AttachmentUploader validates :thema, :presence => true validates :name, :presence => true + + def to_jq_upload + { + "id" => read_attribute(:id), + "title" => read_attribute(:title), + "description" => read_attribute(:desc), + "name" => read_attribute(:title), + "size" => datei.size, + "url" => datei.url, + "thumbnail_url" => datei.thumb.url, + "delete_type" => "DELETE" + } + end end diff --git a/app/models/gremium.rb b/app/models/gremium.rb index ea92010..fe5d2d1 100644 --- a/app/models/gremium.rb +++ b/app/models/gremium.rb @@ -14,8 +14,8 @@ class Gremium < ActiveRecord::Base TYPEN={1=>"offiziell", 2=>"offiziell-temporär", 3 => "inoffiziell",4=>"inoffiziell-tempo", 11=> "berufungskommission",12=> "habilitationskommission" } # Kategorien, im Wesentlichen wichtig für Listung oder nicht Listung GESCHLECHT={0=>"saechlich", 1 => "maennlich", 2 => "weiblich"} # Geschlecht des Gremiums zur richtige Deklination - ART2FALL={0=>"des", 1=>"des",2=>"der"} # Artikel 2.Fall abhängig vom Geschlecht - ART4FALL={0=>"das", 1=>"den",2=>"die"} # Artikel 2.Fall abhängig vom Geschlecht + ART2FALL={0=>"des", 1=>"des",2=>"der"} # Artikel 2.Fall abhängig vom Geschlecht + ART4FALL={0=>"das", 1=>"den",2=>"die"} # Artikel 2.Fall abhängig vom Geschlecht FILTER={11=>I18n.t("gremium.filter.berufung.title"),12=>I18n.t("gremium.filter.habil.title")} TEXT={11=>I18n.t("gremium.filter.berufung.text"),12=>I18n.t("gremium.filter.habil.text")} diff --git a/app/models/thema.rb b/app/models/thema.rb index 2a3a9c4..156a3f5 100644 --- a/app/models/thema.rb +++ b/app/models/thema.rb @@ -23,7 +23,7 @@ class Thema < ActiveRecord::Base scope :search, ->(query) {where("text like ? or title like ?", "%#{query}%", "%#{query}%")} translates :title,:text, :versioning =>true, :fallbacks_for_empty_translations => true def is_wiki? - wikiname.empty? || wikiname.nil? + wikiname.nil? || wikiname.empty? end def text_first_words md = /
(?
- <%= frage.title %> <%= notice %>
<%= raw(@thema.text) %>
+
+
+
+ <% end %>
+
+
<% end %>
diff --git a/app/views/themen/_attachment_verwalten.html.erb b/app/views/themen/_attachment_verwalten.html.erb
new file mode 100644
index 0000000..8fb67c3
--- /dev/null
+++ b/app/views/themen/_attachment_verwalten.html.erb
@@ -0,0 +1,3 @@
+
+<%= render :partial=>"attachments/form_bulk" %>
+<%= render partial: "themen/attachment_list", object:@thema.attachments ,locals: {:editor => true}%>
diff --git a/app/views/themen/_form.html.erb b/app/views/themen/_form.html.erb
index 08e8b59..6a77d03 100644
--- a/app/views/themen/_form.html.erb
+++ b/app/views/themen/_form.html.erb
@@ -2,7 +2,7 @@
+ <%= link_to a.datei.url do %>
<%= render a %>
+<% end %>
+<% if editor %>
<%= link_to "Edit", edit_thema_attachment_path(a.thema,a) %>
+<%= link_to "Delete", thema_attachment_path(a.thema,a), method: "DELETE", confirm: "Sure?" %>
+
+<% end %>
<%= small.title %>
-
+
+ <%= small.title %>
+
<%= raw(small.text) %>
-<%= raw("FAQs:") unless small.fragen.empty? %>
+<%= raw("FAQs:") unless small.fragen.empty? %>
<% small.fragen.each do |frage| %>
-<%= raw(frage.text) %>
+ <%= frage.title %>
+ <%= raw(frage.text) %>
<% end %>
+
+<%= render partial: "themen/attachment_list", object: small.attachments, locals:{editor: false} unless small.attachments.empty? %>
+
+
+
<%
@small_elements = []
@small_elements << {:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t('thema.edit'), :path=>small} if can? :edit, small
diff --git a/app/views/themen/attachments.js.erb b/app/views/themen/attachments.js.erb
index 79f8f32..e1dceb5 100644
--- a/app/views/themen/attachments.js.erb
+++ b/app/views/themen/attachments.js.erb
@@ -1 +1 @@
-$("#themaview").html("<%= escape_javascript(raw(""+I18n.t('thema.show')+"
")+render(:partial=>"themen/attachment_list", :object=>@attachments) )%>");
\ No newline at end of file
+$("#themaview").html("<%= escape_javascript(raw(""+I18n.t('thema.show')+"
")+render(:partial=>"themen/attachment_verwalten") )%>");
\ No newline at end of file
diff --git a/app/views/themen/edit.html.erb b/app/views/themen/edit.html.erb
index de6c7a3..10d69ea 100644
--- a/app/views/themen/edit.html.erb
+++ b/app/views/themen/edit.html.erb
@@ -1,5 +1,5 @@
Editing thema
-<%= render 'form' %>
+<%= render 'form' , :locals=>{:remote=>false}, :remote=>false %>
"+I18n.t('thema.edit')+"
")+render(:partial=>"themen/form") )%>");
+$("#themaview").html("<%= escape_javascript(raw(""+I18n.t('thema.edit')+"
")+render(:partial=>"themen/form", :locals=>{:remote=>true}) )%>");
diff --git a/app/views/themen/verwalten.html.erb b/app/views/themen/verwalten.html.erb
index 70177ca..6b1a1bd 100644
--- a/app/views/themen/verwalten.html.erb
+++ b/app/views/themen/verwalten.html.erb
@@ -1,6 +1,9 @@
<%= @thema.title %>
+<%= I18n.t('attachment.title')%>:
+
-<%= I18n.t('attachment.title')%>:
-Editing thema
-<%= render 'form' %>
+<%= render 'form', :remote=>false, :locals=>{:remote=>false} %>
"+I18n.t('wiki.edit')+"
")+render(:partial=>"wikis/form", :locals=>{:remote=>true}) )%>");