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 = /

(?[^\<\>]*)/.match Sanitize.clean(self.text,:elements=>['p']) diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb index cba26e4..2973828 100644 --- a/app/uploaders/attachment_uploader.rb +++ b/app/uploaders/attachment_uploader.rb @@ -6,6 +6,9 @@ class AttachmentUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick # include CarrierWave::RMagick # include CarrierWave::MiniMagick +def root + Rails.root.join 'public/' +end # Choose what kind of storage to use for this uploader: storage :file @@ -20,6 +23,9 @@ class AttachmentUploader < CarrierWave::Uploader::Base version :thumb do process :resize_to_fill => [64, 64] end + version :thumb_small do + process :resize_to_fill => [32, 32] + end # Provide a default URL as a default if there hasn't been a file uploaded: # def default_url diff --git a/app/views/attachments/_attachment.html.erb b/app/views/attachments/_attachment.html.erb index 1fc66d3..0045f70 100644 --- a/app/views/attachments/_attachment.html.erb +++ b/app/views/attachments/_attachment.html.erb @@ -1,9 +1,9 @@ <% data_ext = attachment.datei.file.extension.downcase %> - <%= attachment.name %>
+ <% if (!["jpg","png","jpeg"].find_index(data_ext).nil?) %> <%= image_tag attachment.datei.thumb.url %> <% else %> <%= image_tag "pdf-logo.jpg" %> <% end %> - + <%= attachment.name %> diff --git a/app/views/attachments/_form_bulk.html.erb b/app/views/attachments/_form_bulk.html.erb new file mode 100644 index 0000000..b8c8616 --- /dev/null +++ b/app/views/attachments/_form_bulk.html.erb @@ -0,0 +1,143 @@ + +

+ <%= semantic_form_for [@thema,@attachment], :remote=>true, :html => { :multipart => true, :id => "fileupload" } do |f| %> + +
+ +
+
+ + + + Add files... + <%= f.file_field :datei, :multiple=>true %> + <% f.input :thema %> + + + + + +
+
+ +
+
+
+
+
+
+ +
+
+ + +
+ <% end %> + +
+ + + + + + + + diff --git a/app/views/fragen/_form.html.erb b/app/views/fragen/_form.html.erb index ce19bc5..a445ffe 100644 --- a/app/views/fragen/_form.html.erb +++ b/app/views/fragen/_form.html.erb @@ -10,3 +10,5 @@ <%= f.action :submit, :as => :input %> <% end %> <% end %> + + <%= tinymce %> diff --git a/app/views/fragen/_rform.html.erb b/app/views/fragen/_rform.html.erb index a3780d1..923744a 100644 --- a/app/views/fragen/_rform.html.erb +++ b/app/views/fragen/_rform.html.erb @@ -10,3 +10,4 @@ <%= f.action :submit, :as => :input %> <% end %> <% end %> + <%= tinymce %> diff --git a/app/views/themen/_attachment_list.html.erb b/app/views/themen/_attachment_list.html.erb index 7b9c0cf..a1c128d 100644 --- a/app/views/themen/_attachment_list.html.erb +++ b/app/views/themen/_attachment_list.html.erb @@ -2,11 +2,17 @@ <% attachment_list.each do |a| %> + <%= 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 %> <% 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 @@
-<%= semantic_form_for @thema, :remote=>true do |f| %> +<%= semantic_form_for @thema, :remote=>remote do |f| %> <%= f.inputs do %>
diff --git a/app/views/themen/_small.html.erb b/app/views/themen/_small.html.erb index dfe8095..7cee6e1 100644 --- a/app/views/themen/_small.html.erb +++ b/app/views/themen/_small.html.erb @@ -1,18 +1,22 @@ - -

<%= small.title %>

-
+ +

<%= small.title %>

+
<%= raw(small.text) %>
-<%= raw("FAQs:") unless small.fragen.empty? %> +<%= raw("FAQs:") unless small.fragen.empty? %>
<% small.fragen.each do |frage| %>

- <%= frage.title %>
-<%= 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 %>

<%= link_to 'Back', @thema %> diff --git a/app/views/themen/edit.js.erb b/app/views/themen/edit.js.erb index 30ca8ab..7256636 100644 --- a/app/views/themen/edit.js.erb +++ b/app/views/themen/edit.js.erb @@ -1 +1 @@ -$("#themaview").html("<%= escape_javascript(raw("

"+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 @@

<%= notice %>

-

<%= @thema.title %>

+
+
+
+

<%= raw(@thema.text) %>

@@ -11,16 +14,22 @@ --> <%= render :partial=>'layouts/pretty_toolbar' %> +

<%= I18n.t('attachment.title')%>:

+
+
+<%= render partial: "attachment_verwalten" %> +<%= render :partial => "themen/select", :object => @thema, :locals=>{:editor => :false} %> + +
+
+ <%= render :partial=>'themen/fragen' %>
-

<%= I18n.t('attachment.title')%>:

-
-
- -<%= link_to new_thema_attachment_path(@thema) ,:remote=>true do %> new Attachment <% end %> -<%= render :partial => "themen/select", :object => @thema, :locals=>{:editor => :false} %> <%= link_to I18n.t('common.back'), themengruppen_path, :class=>:btn %> +
+
+
diff --git a/app/views/wikis/_form.html.erb b/app/views/wikis/_form.html.erb index 18361c3..b17a9e9 100644 --- a/app/views/wikis/_form.html.erb +++ b/app/views/wikis/_form.html.erb @@ -1,6 +1,6 @@ <%= tinymce_assets %>
- <%= semantic_form_for @wiki do |f| %> + <%= semantic_form_for @wiki, :remote=>remote do |f| %> <%= f.inputs do %>
diff --git a/app/views/wikis/edit.html.erb b/app/views/wikis/edit.html.erb index de6c7a3..93d58a1 100644 --- a/app/views/wikis/edit.html.erb +++ b/app/views/wikis/edit.html.erb @@ -1,5 +1,5 @@

Editing thema

-<%= render 'form' %> +<%= render 'form', :remote=>false, :locals=>{:remote=>false} %>

<%= link_to 'Back', @thema %> diff --git a/app/views/wikis/edit.js.erb b/app/views/wikis/edit.js.erb new file mode 100644 index 0000000..0255518 --- /dev/null +++ b/app/views/wikis/edit.js.erb @@ -0,0 +1 @@ +$("#themaview").html("<%= escape_javascript(raw("

"+I18n.t('wiki.edit')+"

")+render(:partial=>"wikis/form", :locals=>{:remote=>true}) )%>");